portable_io.h
Go to the documentation of this file.00001 #ifndef PORTABLE_IO_HEADER
00002 #define PORTABLE_IO_HEADER
00003
00012
00013 #include <stdlib.h>
00014 #include <stdio.h>
00015
00016 #ifdef _MSC_VER
00017 # include <io.h>
00018 # include <direct.h>
00019 # define snprintf _snprintf
00020 #define popen _popen
00021 #define pclose _pclose
00022 #else
00023 # include <unistd.h>
00024 # define O_BINARY 0
00025 #endif
00026
00027 #include <fcntl.h>
00028
00029 namespace cxxtls
00030 {
00031
00032 template<class Iterator>
00033 inline
00034 Iterator
00035 copy_end_of_line(Iterator output)
00041 {
00042 #ifdef _MSC_VER
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 static bool initialized = false;
00061 static bool underBash = false;
00062
00063 if(!initialized)
00064 {
00065 initialized = true;
00066
00067 char* p = getenv("SHLVL");
00068
00069 if(p)
00070 {
00071
00072
00073
00074 underBash = true;
00075 }
00076
00077
00078
00079
00080
00081
00082 }
00083
00084
00085 if(!underBash)
00086 *(output)++ = '\r';
00087
00088 #endif
00089
00090 *(output)++ = '\n';
00091
00092 return output;
00093 }
00094
00095 #ifdef _MSC_VER
00096
00097 extern struct EOL_Sequence_t { char s[2]; } EOL_Sequence;
00098
00099 #else
00100
00101 extern struct EOL_Sequence_t { char s[1]; } EOL_Sequence;
00102
00103 #endif
00104
00105 }
00106 #endif