🛰️航天仿真算法库 SpaceAST 0.3.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 int isatty(int fd)
75 {
76 return ::_isatty(fd);
77 }
78
83 A_ALWAYS_INLINE
84 int fstat(int fd, stat* buf)
85 {
86 return ::_fstat(fd, buf);
87 }
88
92 AST_UTIL_API
93 int chdir(const char* path);
94
99 AST_UTIL_API
100 char* getcwd(char* buf, size_t size);
101
102 using ::fdopen;
103 using ::read;
104 using ::write;
105 using ::close;
106 using ::abort;
107#else
108 using ::stat;
109 using ::fileno;
110 using ::rmdir;
111 using ::isatty;
112 using ::fstat;
113 using ::chdir;
114 using ::getcwd;
115 using ::fdopen;
116 using ::read;
117 using ::write;
118 using ::close;
119 using ::abort;
120
121#endif
122
123#if defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
127 A_ALWAYS_INLINE
128 const char* getenv(const char* name){
129 const char* const env = std::getenv(name);
130 return (env != nullptr && env[0] != '\0') ? env : nullptr;
131 }
132#else
133 using std::getenv;
134#endif
135
136
137}
138AST_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:84
A_ALWAYS_INLINE int isatty(int fd)
判断文件描述符是否为终端
定义 Posix.hpp:74