I'm getting back into c after a long hiatus. Here's a little program I've written to output a files size. It compiles, and it works correctly, and it's pretty much copied and pasted from the man page. But it gives me 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 hints as to how I can make it go away (without disabling 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);
}
You need to pass a file descriptor, not a FILE *
.
int fstat(int fildes, struct stat *buf);
Try using fileno(3)
to get the file descriptor from a FILE *
.
int fd;
fp = fopen("image.png", "rb");
fd = fileno(fp);
fstat(fd, &sb);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With