Max*_*x0u 2 c unix system-calls stat
我想知道文件是目录还是带有 stat 的常规文件:
#define _DEFAULT_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int is_regular_file(const char *path)
{
struct stat path_stat;
stat(path, &path_stat);
return S_ISREG(path_stat.st_mode);
}
Run Code Online (Sandbox Code Playgroud)
我在 Mac 和 Linux 上尝试,当我打印 S_ISREG(path_stat.st_mode) 总是等于 1 并且 path_stat.st_mode 总是等于 16877。
| 归档时间: |
|
| 查看次数: |
3475 次 |
| 最近记录: |