O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Removing Files

Removing files is pretty easy. Use the unlink() system call:

int unlink (const char *path);

unlink() returns zero on successful completion or -1 if there was an error, with errno set to the error that actually happened. There can be multiple references to a file via hardlinks. unlink() removes a reference from a particular dictionary, but the file’s contents are only removed when all references to it have been eliminated.

There is one subtlety when unlinking files that are currently open. The directory entry for the file is removed immediately. If you do an ls on the directory, you won’t see the file. But the file’s contents still exist on the disk, still consume space, and are still available to programs that have the file open. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required