如何编译c代码?

cao*_*aot 0 c linux

以下是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)

pm1*_*100 5

你应该调用stat看到 https://linux.die.net/man/2/stat.不是__xstat.

与开头的名称进行交互__几乎总是表明你做错了什么.他们是在幕后实施的东西