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 <stdio.h>
13 #include <boost/config.hpp>
14 #include <boost/nowide/convert.hpp>
15 #include <boost/nowide/stackstring.hpp>
16 #include <errno.h>
17 
18 #ifdef BOOST_MSVC
19 # pragma warning(push)
20 # pragma warning(disable : 4996)
21 #endif
22 
23 
24 namespace boost {
25 namespace nowide {
26 #if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
27  using std::fopen;
28  using std::freopen;
29  using std::remove;
30  using std::rename;
31 #else
32 
38 inline FILE *freopen(char const *file_name,char const *mode,FILE *stream)
39 {
40  wstackstring wname;
41  wshort_stackstring wmode;
42  if(!wname.convert(file_name) || !wmode.convert(mode)) {
43  errno = EINVAL;
44  return 0;
45  }
46  return _wfreopen(wname.c_str(),wmode.c_str(),stream);
47 }
53 inline FILE *fopen(char const *file_name,char const *mode)
54 {
55  wstackstring wname;
56  wshort_stackstring wmode;
57  if(!wname.convert(file_name) || !wmode.convert(mode)) {
58  errno = EINVAL;
59  return 0;
60  }
61  return _wfopen(wname.c_str(),wmode.c_str());
62 }
68 inline int rename(char const *old_name,char const *new_name)
69 {
70  wstackstring wold,wnew;
71  if(!wold.convert(old_name) || !wnew.convert(new_name)) {
72  errno = EINVAL;
73  return -1;
74  }
75  return _wrename(wold.c_str(),wnew.c_str());
76 }
82 inline int remove(char const *name)
83 {
84  wstackstring wname;
85  if(!wname.convert(name)) {
86  errno = EINVAL;
87  return -1;
88  }
89  return _wremove(wname.c_str());
90 }
91 #endif
92 } // nowide
93 } // namespace boost
94 
95 #ifdef BOOST_MSVC
96 #pragma warning(pop)
97 #endif
98 
99 #endif
100 // 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:68
Definition: args.hpp:18
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:38
FILE * fopen(char const *file_name, char const *mode)
Same as fopen but file_name and mode are UTF-8 strings.
Definition: cstdio.hpp:53
A class that allows to create a temporary wide or narrow UTF strings from wide or narrow UTF source...
Definition: stackstring.hpp:25