Ver Mensaje Individual
  #4 (permalink)  
Antiguo 07/11/2014, 05:44
eferion
 
Fecha de Ingreso: octubre-2014
Ubicación: Madrid
Mensajes: 1.212
Antigüedad: 9 años, 6 meses
Puntos: 204
Respuesta: Problemas con fseek y ftell

El prototipo de la función es

Código C++:
Ver original
  1. int _fstat( int handle, struct _stat *buffer );

es decir, tienes que pasarle el descriptor del archivo que has abierto y una referencia a una estructura de tipo "struct _stat", "struct stat" si es en linux. La función finalmente te devolverá un entero que indica si se ha producido algún error y, en caso contrario, rellena la citada estructura.

La estructura stat contiene la siguiente información:

Código C++:
Ver original
  1. dev_t     st_dev     Device ID of device containing file.
  2. ino_t     st_ino     File serial number.
  3. mode_t    st_mode    Mode of file (see below).
  4. nlink_t   st_nlink   Number of hard links to the file.
  5. uid_t     st_uid     User ID of file.
  6. gid_t     st_gid     Group ID of file.
  7. off_t     st_size    For regular files, the file size in bytes.
  8.                      For symbolic links, the length in bytes of the
  9.                      pathname contained in the symbolic link.
  10.                      For other file types, the use of this field is
  11.                      unspecified.
  12. time_t    st_atime   Time of last access.
  13. time_t    st_mtime   Time of last data modification.
  14. time_t    st_ctime   Time of last status change.

Es decir, el campo st_size te va a indicar el tamaño en bytes del fichero.

Son tres líneas de código, hacer la llamada, comprobar que no se ha producido ningún error y consultar el campo st_size para saber el tamaño en bytes del fichero.