1249259Sdim/*- 2249259Sdim * SPDX-License-Identifier: BSD-2-Clause 3249259Sdim * 4249259Sdim * Copyright (c) 2009 Hudson River Trading LLC 5249259Sdim * Written by: George V. Neville-Neil <gnn@FreeBSD.org> 6249259Sdim * All rights reserved. 7249259Sdim * 8249259Sdim * Redistribution and use in source and binary forms, with or without 9249259Sdim * modification, are permitted provided that the following conditions 10249259Sdim * are met: 11249259Sdim * 1. Redistributions of source code must retain the above copyright 12249259Sdim * notice, this list of conditions and the following disclaimer. 13249259Sdim * 2. Redistributions in binary form must reproduce the above copyright 14249259Sdim * notice, this list of conditions and the following disclaimer in the 15249259Sdim * documentation and/or other materials provided with the distribution. 16249259Sdim * 17249259Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18249259Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19249259Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20249259Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21249259Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22249259Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23249259Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24249259Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25249259Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26249259Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27249259Sdim * SUCH DAMAGE. 28249259Sdim */ 29249259Sdim 30249259Sdim#include <sys/cdefs.h> 31249259Sdim#include <stdio.h> 32249259Sdim#include <stdlib.h> 33249259Sdim#include <string.h> 34249259Sdim#include <err.h> 35263508Sdim#include <locale.h> 36249259Sdim#include <sys/errno.h> 37249259Sdim 38249259Sdimstatic void usage(void) __dead2; 39249259Sdim 40249259Sdimint 41249259Sdimmain(int argc, char **argv) 42249259Sdim{ 43249259Sdim char *cp; 44249259Sdim char *errstr; 45249259Sdim long errnum; 46249259Sdim 47249259Sdim (void) setlocale(LC_MESSAGES, ""); 48249259Sdim if (argc != 2) 49249259Sdim usage(); 50249259Sdim 51249259Sdim errno = 0; 52249259Sdim 53249259Sdim errnum = strtol(argv[1], &cp, 0); 54249259Sdim 55249259Sdim if (errno != 0) 56249259Sdim err(1, NULL); 57249259Sdim 58249259Sdim if ((errstr = strerror(errnum)) == NULL) 59249259Sdim err(1, NULL); 60249259Sdim 61249259Sdim printf("%s\n", errstr); 62249259Sdim 63249259Sdim exit(0); 64249259Sdim} 65249259Sdim 66249259Sdimstatic void 67249259Sdimusage(void) 68249259Sdim{ 69249259Sdim fprintf(stderr, "usage: perror number\n"); 70249259Sdim exit(1); 71249259Sdim} 72249259Sdim 73249259Sdim