C warning warning passing argument 1 of 'fstat makes integer from pointer without casting

I am returning to c after a long break. Here is a small program that I wrote for file size output. It compiles and it works correctly, and it is largely copied and pasted from the man page. But this causes an annoying warning from 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 *'` 

Any clues as to how I can get him to leave (without turning off the warnings;))

 #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
source share
1 answer

You need to pass the file descriptor , not FILE * .

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

Try using fileno(3) to get a file descriptor with FILE * .

 int fd; fp = fopen("image.png", "rb"); fd = fileno(fp); fstat(fd, &sb); 
+11
source

Source: https://habr.com/ru/post/1401464/


All Articles