以下是c与之相关的示例代码stat.h.bits/stat.h提到的"Never include <bits/stat.h> directly; use <sys/stat.h> instead.".但是struct stat定义于bits/stat.h,并int __xstat (...)在中定义sys/stat.h.代码不会使用任何一个头文件甚至两者编译.如何在#include ...不改变任何一个功能的情况下更改它而进行复制?
#include <stdio.h>
#include <bits/stat.h>
#include <sys/stat.h>
int stat_1(char *filename, struct stat *stat_buf)
{
return __xstat(1, filename, stat_buf); // extern int __xstat (...) defined in sys/stat.h
}
char * test(const char *filename) {
char *result;
stat stat_buf; // struct stat defined in bits/stat.h
printf("DO something here");
if ( stat_1(filename, &sbuf) == -1 ) {
printf("DO something here");
}
return result;
}
int main() {
const char *fileName = "file.txt";
test(fileName);
return 0;
}
Run Code Online (Sandbox Code Playgroud)