› Foros › PC › Software libre
Cafetino escribió:Para saber el tamaño de un fichero se puede usar la llamada al sistema lseek. E aqui un ejemplo:
TamFitxero=lseek(f,0,L_XTND);
La varialble f es el file descriptor del fichero del qual quieres saber el tamaño.
La funcion en realidad, lo que hace es jugar con el apuntador que apunta a la posicion actual dentro del fichero en cuestion. Esta funcion con la constante L_XTND lo que hace es mover ese apuntador hasta la posicion final mas 0, y luego esta te devuelve la posicion, de esta manera conoces su tamaño.
Si quieres mover el puntero al inicio del fichero haz:
lseek(f,0,L_SET);
No se si me habré del explicado del todo bien. Tu diras
Espero que te sirva
Salu2
[OT] PD: Por cierto yo también hice esta practica el año pasado. No se como os la han hecho hacer vosotros, pero nosotros nos la hicieron hacer con una estructura por tres capas, y el protocolo funcionando sobre udp, menudo caos, esa practica ha sido una de la practicas de programacion en la que he necesitado mas horas.
struct stat {
dev_t st_dev; /* device inode resides on */
ino_t st_ino; /* inode's number */
mode_t st_mode; /* inode protection mode */
nlink_t st_nlink; /* number or hard links to the file */
uid_t st_uid; /* user-id of owner */
gid_t st_gid; /* group-id of owner */
dev_t st_rdev; /* device type, for special file inode */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
off_t st_size; /* file size, in bytes */
quad_t st_blocks; /* blocks allocated for file */
u_long st_blksize;/* optimal file sys I/O ops blocksize */
u_long st_flags; /* user defined flags for file */
u_long st_gen; /* file generation number */
};
man stat
Ferdy escribió:¿?struct stat {
dev_t st_dev; /* device inode resides on */
ino_t st_ino; /* inode's number */
mode_t st_mode; /* inode protection mode */
nlink_t st_nlink; /* number or hard links to the file */
uid_t st_uid; /* user-id of owner */
gid_t st_gid; /* group-id of owner */
dev_t st_rdev; /* device type, for special file inode */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
off_t st_size; /* file size, in bytes */
quad_t st_blocks; /* blocks allocated for file */
u_long st_blksize;/* optimal file sys I/O ops blocksize */
u_long st_flags; /* user defined flags for file */
u_long st_gen; /* file generation number */
};man stat
Ferdy escribió:¿?struct stat {
dev_t st_dev; /* device inode resides on */
ino_t st_ino; /* inode's number */
mode_t st_mode; /* inode protection mode */
nlink_t st_nlink; /* number or hard links to the file */
uid_t st_uid; /* user-id of owner */
gid_t st_gid; /* group-id of owner */
dev_t st_rdev; /* device type, for special file inode */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
off_t st_size; /* file size, in bytes */
quad_t st_blocks; /* blocks allocated for file */
u_long st_blksize;/* optimal file sys I/O ops blocksize */
u_long st_flags; /* user defined flags for file */
u_long st_gen; /* file generation number */
};man stat
Salu2.Ferdy