Files
haiku-beta6/src/apps/bin/error.c
T

68 lines
1.2 KiB
C
Raw Normal View History

2002-10-08 17:08:23 +00:00
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
2002-10-10 19:05:58 +00:00
// Copyright (c) 2001-2003, OpenBeOS
2002-10-08 17:08:23 +00:00
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: error.c
// Author: Daniel Reinhold ([email protected])
2002-10-10 19:05:58 +00:00
// Description: prints error message text for OS error codes
2002-10-08 17:08:23 +00:00
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include <OS.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
void print_error(char *);
int
main(int argc, char *argv[])
{
if (argc != 2)
2002-10-10 19:05:58 +00:00
printf("Usage: error number\n"
"Prints the message text for OS error codes. "
2002-10-08 17:08:23 +00:00
"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));
}