Boost.Nowide
cstdio.hpp
1 //
2 // Copyright (c) 2012 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOST_NOWIDE_CSTDIO_H_INCLUDED
9 #define BOOST_NOWIDE_CSTDIO_H_INCLUDED
10 
11 #include <cstdio>
12 #include <boost/config.hpp>
13 #include <boost/nowide/convert.hpp>
14 #include <boost/nowide/stackstring.hpp>
15 #include <cerrno>
16 
17 #ifdef BOOST_MSVC
18 # pragma warning(push)
19 # pragma warning(disable : 4996)
20 #endif
21 
22 
23 namespace boost {
24 namespace nowide {
25 #if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
26  using std::fopen;
27  using std::freopen;
28  using std::remove;
29  using std::rename;
30 #else
31 
37 inline FILE *freopen(char const *file_name,char const *mode,FILE *stream)
38 {
39  wstackstring wname;
40  wshort_stackstring wmode;
41  if(!wname.convert(file_name) || !wmode.convert(mode)) {
42  errno = EINVAL;
43  return 0;
44  }
45  return _wfreopen(wname.c_str(),wmode.c_str(),stream);
46 }
52 inline FILE *fopen(char const *file_name,char const *mode)
53 {
54  wstackstring wname;
55  wshort_stackstring wmode;
56  if(!wname.convert(file_name) || !wmode.convert(mode)) {
57  errno = EINVAL;
58  return 0;
59  }
60  return _wfopen(wname.c_str(),wmode.c_str());
61 }
67 inline int rename(char const *old_name,char const *new_name)
68 {
69  wstackstring wold,wnew;
70  if(!wold.convert(old_name) || !wnew.convert(new_name)) {
71  errno = EINVAL;
72  return -1;
73  }
74  return _wrename(wold.c_str(),wnew.c_str());
75 }
81 inline int remove(char const *name)
82 {
83  wstackstring wname;
84  if(!wname.convert(name)) {
85  errno = EINVAL;
86  return -1;
87  }
88  return _wremove(wname.c_str());
89 }
90 #endif
91 } // nowide
92 } // namespace boost
93 
94 #ifdef BOOST_MSVC
95 #pragma warning(pop)
96 #endif
97 
98 #endif
99 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
int rename(char const *old_name, char const *new_name)
Same as rename but old_name and new_name are UTF-8 strings.
Definition: cstdio.hpp:67
FILE * freopen(char const *file_name, char const *mode, FILE *stream)
Same as freopen but file_name and mode are UTF-8 strings.
Definition: cstdio.hpp:37
FILE * fopen(char const *file_name, char const *mode)
Same as fopen but file_name and mode are UTF-8 strings.
Definition: cstdio.hpp:52
A class that allows to create a temporary wide or narrow UTF strings from wide or narrow UTF source...
Definition: stackstring.hpp:25