errno.c (692B)
- // Collection of Unix tools, comparable to coreutils
 - // SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
 - // SPDX-License-Identifier: MPL-2.0
 - #include <errno.h> // errno
 - #include <stdio.h> // puts, perror
 - #include <stdlib.h> // strtol
 - #include <string.h> // strerror
 - int
 - main(int argc, char *argv[])
 - {
 - if(argc != 2)
 - {
 - puts("usage: errno <number>");
 - return 1;
 - }
 - errno = 0;
 - int err = (int)(strtol(argv[1], NULL, 10));
 - if(errno != 0)
 - {
 - perror("errno: strtol");
 - return 1;
 - }
 - errno = 0;
 - char *msg = strerror(err);
 - if(errno != 0)
 - {
 - perror("errno: strerror");
 - return 1;
 - }
 - if(puts(msg) < 0)
 - {
 - return 1;
 - }
 - return 0;
 - }