*
* Usage: errcode -h give all info's
*
- * $Id: ErrCode.c,v 1.2 2001/09/09 22:45:34 piccardi Exp $
- *
****************************************************************/
/*
* Include needed headers
#include <stdlib.h> /* C standard library */
#include <unistd.h> /* unix standard library */
#include <stdio.h> /* standard I/O library */
-#include <string.h> /* string functions */
+#include <string.h> /* C strings library */
+#include <limits.h> /* system limits values */
/* Help printing routine */
void usage(void);
if (optind == argc) {
usage();
}
- err = atoi(argv[optind]);
+ /* convert string to number */
+ err = strtol(argv[optind], NULL, 10);
+ /* testing error condition on conversion */
+ if (err==LONG_MIN) {
+ perror("Underflow on error code");
+ return 1;
+ } else if (err==LONG_MIN) {
+ perror("Overflow on error code");
+ return 1;
+ }
+ /* conversion is fine */
if (message) {
printf("Error message for %d is %s\n", err, strerror(err));
}
void usage(void) {
printf("Print error code message or macro label \n");
printf("Usage:\n");
- printf(" daytime [-h] [-l] [-m] error code \n");
+ printf(" errcode [-h] [-l] [-m] error code \n");
printf(" -m print error messages\n");
printf(" -l print error code label\n");
printf(" -h print this help\n");