Decoded: unlink (coreutils)

[Back to Project Main Page]

Note: This page explores the design of command-line utilities. It is not a user guide.
[GNU Manual] [POSIX requirement] [Linux man] [FreeBSD man]

Logical flow of unlink command (coreutils)

Summary

unlink - remove files via the unlink syscall

[Source] [Code Walkthrough]

Lines of code: 96
Principal syscall: unlink()
Support syscalls: None
Options: 0 (help and version built in to usage())

Existed as a syscall since Version 1 UNIX (1971). Wrapper utility unique to coreutils
Added to Coreutils in April 2002 [First version]
Number of revisions: 51 [Code Evolution]

Helpers:
  • None
External non-standard helpers:
  • die() - Exit with mandatory non-zero error and message to stderr
  • error() - Outputs error message to standard error with possible process termination

Setup

unlink initializes no parsing options, globals, or additional variables in main() not already mentioned.


Parsing

Parsing for unlink involves checking that a single argument references a file.

Parsing failures

These failure case is explicitly checked:

  • No file provided
  • More than one file provided

Failure results in a short error message followed by the usage instructions.

Execution

Successful execution happens with one line of code: unlink (argv[optind]).

Failure case:

  • unlink() returned an error for any reason. The reason for failure is not checked.

All failures at this stage output an error message to STDERR and return without displaying usage help


[Back to Project Main Page]