How to use the command 'errno' (with examples)
The errno
command is used to look up errno names and descriptions. It provides information about error codes and their corresponding descriptions. This can be useful when troubleshooting and debugging programs, as it helps to understand the meaning of error codes.
Use case 1: Lookup errno description by name or code
Code:
errno name|code
Motivation: The motivation for using this example is to quickly find the description of a specific errno name or code. This can be helpful when encountering an error in a program and needing to understand what the error code means.
Explanation: The name|code
argument can be either an errno name or an errno code. It is used to specify the specific errno for which you want to retrieve the description.
Example output:
$ errno EACCES
EACCES 13 Permission denied
In this example, the errno
command is used to look up the description for the errno code EACCES
. The output displays the name, code, and description of the errno.
Use case 2: List all errno names, codes, and descriptions
Code:
errno --list
Motivation: The motivation for using this example is to obtain a comprehensive list of all errno names, codes, and descriptions. This can be useful for reference or when dealing with error handling in programs.
Explanation: The --list
argument is used to instruct the errno
command to display a list of all errno names, codes, and descriptions.
Example output:
$ errno --list
EPERM 1 Operation not permitted
ENOENT 2 No such file or directory
...
In this example, the errno
command with the --list
argument is used to retrieve a list of all errno names, codes, and descriptions. The output displays each errno entry with its corresponding name, code, and description.
Use case 3: Search for code whose description contains all of the given text
Code:
errno --search text
Motivation: This example is useful when you want to search for specific error codes based on a particular description. It helps to quickly locate relevant error codes that match the given text.
Explanation: The --search
argument is used with the errno
command to perform a search for error codes whose description contains all of the given text.
Example output:
$ errno --search "permission denied"
EACCES 13 Permission denied
EPERM 1 Operation not permitted
In this example, the errno
command is used with the --search
argument to search for error codes with descriptions that contain the text “permission denied”. The output displays the matching error codes along with their names, codes, and descriptions.
Use case 4: Search for code whose description contains all of the given text (all locales)
Code:
errno --search-all-locales text
Motivation: This example is similar to the previous use case, but it searches for error codes based on the description text in all locales. This can be useful when dealing with programs or systems that use different locales.
Explanation: The --search-all-locales
argument is used to perform a search for error codes whose description contains all of the given text, considering all available locales.
Example output:
$ errno --search-all-locales "permission denied"
EACCES 13 Permission denied
EPERM 1 Operation not permitted
In this example, the errno
command with the --search-all-locales
argument is used to search for error codes with descriptions that contain the text “permission denied” in all locales. The output displays the matching error codes along with their names, codes, and descriptions.
Conclusion:
The errno
command is a helpful tool for looking up errno names and descriptions. It provides an easy way to retrieve information about error codes, which can aid in troubleshooting and understanding program errors. Whether you need to look up a specific errno or obtain a comprehensive list, the errno
command has you covered.