🛰️航天仿真算法库 SpaceAST 0.4.0
载入中...
搜索中...
未找到
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 <process.h> // for _getpid
36#include <sys/stat.h> // for fstat
37#include <direct.h> // for _rmdir
38#else
39#include <unistd.h> // for isatty, fileno, rmdir
40#include <sys/stat.h> // for fstat
41#endif
42
43AST_NAMESPACE_BEGIN
44
45
50namespace posix
51{
52#if defined(_WIN32) || defined(AST_PARSED_BY_DOXYGEN)
53 // typedef struct _stat stat;
54 using stat = struct ::_stat;
55
59 A_ALWAYS_INLINE
60 int fileno(FILE* file)
61 {
62 return ::_fileno(file);
63 }
64
68 AST_UTIL_API
69 int rmdir(const char* path);
70
74 A_ALWAYS_INLINE
75 int isatty(int fd)
76 {
77 return ::_isatty(fd);
78 }
79
82 A_ALWAYS_INLINE
83 int getpid()
84 {
85 return ::_getpid();
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 using ::isatty;
121 using ::getpid;
122 using ::fstat;
123 using ::chdir;
124 using ::getcwd;
125 using ::fdopen;
126 using ::read;
127 using ::write;
128 using ::close;
129 using ::abort;
130
131#endif
132
133#if defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
137 A_ALWAYS_INLINE
138 const char* getenv(const char* name){
139 const char* const env = std::getenv(name);
140 return (env != nullptr && env[0] != '\0') ? env : nullptr;
141 }
142#else
143 using std::getenv;
144#endif
145
146
147}
148AST_NAMESPACE_END
AST_UTIL_API int rmdir(const char *path)
删除目录
A_ALWAYS_INLINE int fileno(FILE *file)
获取文件流的文件描述符
定义 Posix.hpp:60
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 int getpid()
获取当前进程 ID
定义 Posix.hpp:83
A_ALWAYS_INLINE int isatty(int fd)
判断文件描述符是否为终端
定义 Posix.hpp:75