[GNU Manual] [POSIX requirement] [Linux man] [FreeBSD man]
Summary
link - make a hard link to a file
Lines of code: 101
Principal syscall: link()
Support syscalls: None
Options: 2 (help and version)
Added to Coreutils in April 2002 [First version]
Number of revisions: 50 [Code Evolution]
- None
die()
- Exit with mandatory non-zero error and message to stderrerror()
- Outputs error message to standard error with possible process terminationquoteaf_n()
- Outputs a printable argument
Setup
link only uses the default parsing options, which require no initialization
main() initializes no additional variables
Parsing
Parsing for link involves two checks:
- Check for any long options
- Check for anything else
Parsing failures
These failure cases are explicitly checked:
- If any non-long option is passed
- If there are any missing operands (target files, etc)
- If there are any extra operands
All failures result in a short error message followed by the usage instructions.
Execution
This wrapper utility passes user arguments directly to the link()
syscall.
Utility usage...
link filename linkname
...matches link()
syscall prototype
int link(const char *path1, const char *path2);
The success or failure of the syscall determines the return value of the utility
Extra comments
Here is how the link()
syscall is handled in a modern linux kernel (v5.0):
(Declaration), (Execution)