programa c, mensaje de advertencia al pasar el argumento 1 de 'fstat' se convierte en un número entero a partir del puntero sin conversión

StackOverflow https://stackoverflow.com//questions/9709730

Pregunta

Estoy volviendo a c después de una larga pausa.Aquí hay un pequeño programa que escribí para generar un tamaño de archivo.Se compila, funciona correctamente y prácticamente se copia y pega desde la página de manual.Pero me da una molesta advertencia de 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 *’`

Cualquier pista sobre cómo puedo hacer que desaparezca (sin desactivar las advertencias;))

#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);

}
¿Fue útil?

Solución

Necesitas pasar un descriptor de archivo, No un FILE *.

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

Intenta usar fileno(3) para obtener el descriptor de archivo de un FILE *.

int fd;

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

fstat(fd, &sb);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top