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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.