🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
Posix.hpp
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstUtil/IO.hpp" // for functions such as printf, fopen
25#include "AstUtil/StringPosix.hpp" // for functions such as strcasecmp, strncasecmp
26
27#include <cstdlib> // for std::getenv
28#include <cstdio> // for FILE
29#include <cstring>
30
31#ifdef _WIN32
32#include <sys/types.h>
33#include <fcntl.h>
34#include <io.h> // for _isatty, _fileno
35#include <sys/stat.h> // for fstat
36#include <direct.h> // for _rmdir
37#else
38#include <unistd.h> // for isatty, fileno, rmdir
39#include <sys/stat.h> // for fstat
40#endif
41
42AST_NAMESPACE_BEGIN
43
44
49namespace posix
50{
51#if defined(_WIN32) || defined(AST_PARSED_BY_DOXYGEN)
52 // typedef struct _stat stat;
53 using stat = struct ::_stat;
54
58 A_ALWAYS_INLINE
59 int fileno(FILE* file)
60 {
61 return ::_fileno(file);
62 }
63
67 AST_UTIL_API
68 int rmdir(const char* path);
69
73 A_ALWAYS_INLINE
74 bool isdir(const stat& st)
75 {
76 return (_S_IFDIR & st.st_mode) != 0;
77 }
78
82 A_ALWAYS_INLINE
83 int isatty(int fd)
84 {
85 return ::_isatty(fd);
86 }
87
92 A_ALWAYS_INLINE
93 int fstat(int fd, stat* buf)
94 {
95 return ::_fstat(fd, buf);
96 }
97
101 AST_UTIL_API
102 int chdir(const char* path);
103
108 AST_UTIL_API
109 char* getcwd(char* buf, size_t size);
110
111 using ::fdopen;
112 using ::read;
113 using ::write;
114 using ::close;
115 using ::abort;
116#else
117 using ::stat;
118 using ::fileno;
119 using ::rmdir;
120
121 A_ALWAYS_INLINE
122 bool isdir(const struct stat& st)
123 {
124 return S_ISDIR(st.st_mode);
125 }
126 using ::isatty;
127 using ::fstat;
128 using ::chdir;
129 using ::getcwd;
130 using ::fdopen;
131 using ::read;
132 using ::write;
133 using ::close;
134 using ::abort;
135
136#endif
137
138#if defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
142 A_ALWAYS_INLINE
143 const char* getenv(const char* name){
144 const char* const env = std::getenv(name);
145 return (env != nullptr && env[0] != '\0') ? env : nullptr;
146 }
147#else
148 using std::getenv;
149#endif
150
151
152}
153AST_NAMESPACE_END
AST_UTIL_API int rmdir(const char *path)
删除目录
A_ALWAYS_INLINE int fileno(FILE *file)
获取文件流的文件描述符
定义 Posix.hpp:59
AST_UTIL_API int chdir(const char *path)
改变当前工作目录
AST_UTIL_API char * getcwd(char *buf, size_t size)
获取当前工作目录
A_ALWAYS_INLINE int fstat(int fd, stat *buf)
获取文件状态
定义 Posix.hpp:93
A_ALWAYS_INLINE bool isdir(const stat &st)
检查文件状态是否为目录
定义 Posix.hpp:74
A_ALWAYS_INLINE int isatty(int fd)
判断文件描述符是否为终端
定义 Posix.hpp:83