5

長い休止の後、私はcに戻っています。これが私がファイルサイズを出力するために書いた小さなプログラムです。コンパイルされ、正しく動作し、manページからほとんどコピーアンドペーストされます。しかし、それは私にgccからの迷惑な警告を与えます。

gcc -ggdb  read_file_to_char_array.c -o read_file_to_char_array `mysql_config --cflags --libs && pkg-config --cflags --libs gtk+-2.0 && pkg-config --cflags --libs sdl`  
read_file_to_char_array.c: In function ‘main’:
read_file_to_char_array.c:22:19: warning:   [enabled by default]
/usr/include/i386-linux-gnu/sys/stat.h:216:12: note: expected ‘int’ but argument is of type ‘struct FILE *’`

(警告を無効にせずに)どうすればそれをなくすことができるかについてのヒント;))

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv) {
    unsigned long *lengths;
    FILE *fp;
    struct stat sb;

    fp = fopen("image.png", "rb");
    fstat(fp,&sb);

    printf(" Size - %lld : ", (long long)sb.st_size);

    fclose(fp);

}
4

1 に答える 1

14

ではなく、ファイル記述子を渡す必要がありますFILE *

int fstat(int fildes, struct stat *buf);

fileno(3)を使用して、からファイル記述子を取得してみてくださいFILE *

int fd;

fp = fopen("image.png", "rb");
fd = fileno(fp);

fstat(fd, &sb);
于 2012-03-14T20:28:31.463 に答える