CppCMS
cstdio.h
1 #ifndef CPPCMS_NOWIDE_CSTDIO_H
2 #define CPPCMS_NOWIDE_CSTDIO_H
3 
4 #include <cstdio>
5 #include <stdio.h>
6 #include <booster/config.h>
7 #include <booster/nowide/convert.h>
8 
9 #include <booster/config.h>
10 #ifdef BOOSTER_MSVC
11 # pragma warning(push)
12 # pragma warning(disable : 4996)
13 #endif
14 
15 
16 namespace booster {
17  namespace nowide {
18  #ifndef BOOSTER_WIN_NATIVE
19  using std::fopen;
20  using std::freopen;
21  using std::remove;
22  using std::rename;
23  #endif
24 
25  #if defined(BOOSTER_WIN_NATIVE) || defined(BOOSTER_DOXYGEN_DOCS)
26 
30  inline FILE *fopen(char const *file_name,char const *mode)
31  {
32  try {
33  return _wfopen(convert(file_name).c_str(),convert(mode).c_str());
34  }
35  catch(bad_utf const &) {
36  return 0;
37  }
38  }
42  inline FILE *freopen(char const *file_name,char const *mode,FILE *stream)
43  {
44  try {
45  return _wfreopen(convert(file_name).c_str(),convert(mode).c_str(),stream);
46  }
47  catch(bad_utf const &) {
48  return 0;
49  }
50  }
54  inline int rename(char const *old_name,char const *new_name)
55  {
56  try {
57  return _wrename(convert(old_name).c_str(),convert(new_name).c_str());
58  }
59  catch(bad_utf const &) {
60  return -1;
61  }
62  }
66  inline int remove(char const *name)
67  {
68  try {
69  return _wremove(convert(name).c_str());
70  }
71  catch(bad_utf const &) {
72  return -1;
73  }
74  }
75  #endif
76  } // nowide
77 } // booster
78 
79 #ifdef BOOSTER_MSVC
80 #pragma warning(pop)
81 #endif
82 
83 #endif
FILE * fopen(char const *file_name, char const *mode)
Definition: cstdio.h:30
BOOSTER_API std::string convert(wchar_t const *s)
FILE * freopen(char const *file_name, char const *mode, FILE *stream)
Definition: cstdio.h:42
int rename(char const *old_name, char const *new_name)
Definition: cstdio.h:54
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
This exception is thrown if invalid UTF-8 or UTF-16 is given as input.
Definition: convert.h:14