From baaddeabcc7daec22f0859f6a664ea0b7f00371d Mon Sep 17 00:00:00 2001 From: Daniel Reinhold Date: Tue, 8 Oct 2002 17:08:23 +0000 Subject: [PATCH] initial checkin git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1457 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/error.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/apps/bin/error.c diff --git a/src/apps/bin/error.c b/src/apps/bin/error.c new file mode 100644 index 0000000000..a1d9484ec3 --- /dev/null +++ b/src/apps/bin/error.c @@ -0,0 +1,67 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2001-2002, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// File: error.c +// Author: Daniel Reinhold (danielre@users.sf.net) +// Description: displays error message text for OS error codes +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include +#include +#include +#include +#include + + +void print_error(char *); + + +int +main(int argc, char *argv[]) +{ + if (argc != 2) + printf("usage: error number\n" + "Displays the message text for OS error codes. " + "The error number can be in decimal, hex or octal.\n"); + else + print_error(argv[1]); + + return 0; +} + + +void +print_error(char *str) +{ + uint32 err; + int base = 10; + char *end; + + if (str[0] == '0') { + if (tolower(str[1]) == 'x') + base = 16; + else + base = 8; + } + + errno = 0; + err = strtoul(str, &end, base); + + if (errno) { + fprintf(stderr, "%s: %s\n", str, strerror(errno)); + exit(1); + } + + if (*end) { + fprintf(stderr, "%s: invalid number\n", str); + exit(1); + } + + printf("0x%x: %s\n", err, strerror(err)); +}