CppCMS
booster/nowide/cstdio.h
00001 #ifndef CPPCMS_NOWIDE_CSTDIO_H
00002 #define CPPCMS_NOWIDE_CSTDIO_H
00003 
00004 #include <cstdio>
00005 #include <stdio.h>
00006 #include <booster/config.h>
00007 #include <booster/nowide/convert.h>
00008 
00009 #include <booster/config.h>
00010 #ifdef BOOSTER_MSVC
00011 #  pragma warning(push)
00012 #  pragma warning(disable : 4996)
00013 #endif
00014 
00015 
00016 namespace booster {
00017         namespace nowide {
00018         #ifndef BOOSTER_WIN_NATIVE
00019                 using std::fopen;
00020                 using std::freopen;
00021                 using std::remove;
00022                 using std::rename;
00023         #endif
00024 
00025         #if defined(BOOSTER_WIN_NATIVE) || defined(BOOSTER_DOXYGEN_DOCS)
00026 
00030                 inline FILE *fopen(char const *file_name,char const *mode)
00031                 {
00032                         try {
00033                                 return _wfopen(convert(file_name).c_str(),convert(mode).c_str());
00034                         }
00035                         catch(bad_utf const &) {
00036                                 return 0;
00037                         }
00038                 }
00042                 inline FILE *freopen(char const *file_name,char const *mode,FILE *stream)
00043                 {
00044                         try {
00045                                 return _wfreopen(convert(file_name).c_str(),convert(mode).c_str(),stream);
00046                         }
00047                         catch(bad_utf const &) {
00048                                 return 0;
00049                         }
00050                 }
00054                 inline int rename(char const *old_name,char const *new_name)
00055                 {
00056                         try {
00057                                 return _wrename(convert(old_name).c_str(),convert(new_name).c_str());
00058                         }
00059                         catch(bad_utf const &) {
00060                                 return -1;
00061                         }
00062                 }
00066                 inline int remove(char const *name)
00067                 {
00068                         try {
00069                                 return _wremove(convert(name).c_str());
00070                         }
00071                         catch(bad_utf const &) {
00072                                 return -1;
00073                         }
00074                 }
00075         #endif
00076         } // nowide
00077 } // booster
00078 
00079 #ifdef BOOSTER_MSVC
00080 #pragma warning(pop)
00081 #endif
00082 
00083 #endif