Boost.Nowide
boost/nowide/cstdio.hpp
00001 //
00002 //  Copyright (c) 2012 Artyom Beilis (Tonkikh)
00003 //
00004 //  Distributed under the Boost Software License, Version 1.0. (See
00005 //  accompanying file LICENSE_1_0.txt or copy at
00006 //  http://www.boost.org/LICENSE_1_0.txt)
00007 //
00008 #ifndef BOOST_NOWIDE_CSTDIO_H_INCLUDED
00009 #define BOOST_NOWIDE_CSTDIO_H_INCLUDED
00010 
00011 #include <cstdio>
00012 #include <stdio.h>
00013 #include <boost/config.hpp>
00014 #include <boost/nowide/convert.hpp>
00015 #include <boost/nowide/stackstring.hpp>
00016 #include <errno.h>
00017 
00018 #ifdef BOOST_MSVC
00019 #  pragma warning(push)
00020 #  pragma warning(disable : 4996)
00021 #endif
00022 
00023 
00024 namespace boost {
00025 namespace nowide {
00026 #if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
00027     using std::fopen;
00028     using std::freopen;
00029     using std::remove;
00030     using std::rename;
00031 #else
00032 
00038 inline FILE *freopen(char const *file_name,char const *mode,FILE *stream)
00039 {
00040     wstackstring wname;
00041     wshort_stackstring wmode;
00042     if(!wname.convert(file_name) || !wmode.convert(mode)) {
00043         errno = EINVAL;
00044         return 0;
00045     }
00046     return _wfreopen(wname.c_str(),wmode.c_str(),stream);
00047 }
00053 inline FILE *fopen(char const *file_name,char const *mode)
00054 {
00055     wstackstring wname;
00056     wshort_stackstring wmode;
00057     if(!wname.convert(file_name) || !wmode.convert(mode)) {
00058         errno = EINVAL;
00059         return 0;
00060     }
00061     return _wfopen(wname.c_str(),wmode.c_str());
00062 }
00068 inline int rename(char const *old_name,char const *new_name)
00069 {
00070     wstackstring wold,wnew;
00071     if(!wold.convert(old_name) || !wnew.convert(new_name)) {
00072         errno = EINVAL;
00073         return -1;
00074     }
00075     return _wrename(wold.c_str(),wnew.c_str());
00076 }
00082 inline int remove(char const *name)
00083 {
00084     wstackstring wname;
00085     if(!wname.convert(name)) {
00086         errno = EINVAL;
00087         return -1;
00088     }
00089     return _wremove(wname.c_str());
00090 }
00091 #endif
00092 } // nowide
00093 } // namespace boost
00094 
00095 #ifdef BOOST_MSVC
00096 #pragma warning(pop)
00097 #endif
00098 
00099 #endif
00100 
00101 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4