Next: unlinkat, Previous: ttyname_r, Up: Functions in <unistd.h>   [Contents][Index]


10.69.93 unlink ¶

POSIX specification:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/unlink.html

LSB specification:
https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib-unlink-3.html

Gnulib module: unlink

Portability problems fixed by Gnulib:

  • This function is declared in a different header file (namely, <stdio.h>) on some platforms: MSVC 14.
  • Some systems mistakenly succeed on unlink("link-to-file/"): GNU/Hurd, FreeBSD 7.2, AIX 7.1, Solaris 9.
  • On Mac OS X 10.10, in a writable HFS mount, unlink("..") succeeds without doing anything.

Portability problems not fixed by Gnulib:

  • Some systems allow a superuser to unlink directories, even though this can cause file system corruption. The error given if a process is not permitted to unlink directories varies across implementations; it is not always the POSIX value of EPERM. Meanwhile, if a process has the ability to unlink directories, POSIX requires that unlink("symlink-to-dir/") remove dir and leave symlink-to-dir dangling; this behavior is counter-intuitive. The gnulib module unlinkdir can help determine whether code must be cautious of unlinking directories.
  • Removing an open file is non-portable: On Unix this allows the programs that have the file already open to continue working with it; the file’s storage is only freed when the no process has the file open any more. On Windows, the attempt to remove an open file fails.