En mi programa, coloco los archivos que quieren y envío los datos. Los campos de una estadística struct
son todos los tipos especiales:¿Cómo usar printf para mostrar off_t, nlink_t, size_t y otros tipos especiales?
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
};
El código relevante para mi pregunta sigue:
len = snprintf(statbuf, STAT_BUFFER_SIZE,
"%crwxrwxrwx %lu %u %u %lld %s %s\r\n",
S_ISDIR(filestats.st_mode) ? 'd' : '-',
(unsigned long) filestats.st_nlink,
filestats.st_uid,
filestats.st_gid,
(unsigned long long) filestats.st_size,
date,
filename);
¿Cómo se imprime este tipo de una manera portátil y eficiente? Al principio lo hice sin moldes adivinando los especificadores de formato correctos. Además de ser un hábito de programación molesto, esto también significaba que mi código no funcionaría en un sistema de 32 bits. Ahora con los moldes parece funcionar, pero ¿en cuántas plataformas?
específico para clock_t: http://stackoverflow.com/questions/1083142/what-s-the-correct-way-to-use-printf-to-print-a-clock-t –
Para '__uint128': http://stackoverflow.com/questions/11656241/how-to-print-uint128-t-number-using-gcc –