File Metadata

File metadata is data about the file, but it is not the file’s data itself. This includes information like the file’s size, type, the last access times, and so on.

stat()

Three functions can be used to access metadata that lives in the inode:

int stat (const char *path, struct stat *sb);

int lstat (const char *path, struct stat *sb);

int fstat (int fd, struct stat *sb);

stat() gets the status, the information about the file at a path, following any intervening symbolic links. lstat() gets information about the symbolic link itself. fstat() gives you metadata about an already open file. As with most Unix file functions, a return value of zero indicates success, a value of -1 indicates an error, and errno is set appropriately.

You ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.