Error messages cleanup

This commit is contained in:
Pierre Pronchery 2004-08-19 16:55:05 +00:00
parent b723461479
commit ab0f87ffc4

View File

@ -12,6 +12,7 @@ extern int optind;
/* time */ /* time */
static int _time_error(char * error, int ret);
static int _time(int argc, char * argv[]) static int _time(int argc, char * argv[])
{ {
pid_t pid; pid_t pid;
@ -20,43 +21,25 @@ static int _time(int argc, char * argv[])
clock_t cbefore, cafter; clock_t cbefore, cafter;
if((cbefore = times(NULL)) == -1) if((cbefore = times(NULL)) == -1)
{ return _time_error("times", 2);
fprintf(stderr, "%s", "time: ");
perror("times");
return 2;
}
if((pid = fork()) == -1) if((pid = fork()) == -1)
{ return _time_error("fork", 2);
fprintf(stderr, "%s", "time: ");
perror("fork");
return 2;
}
if(pid == 0) if(pid == 0)
{ {
execvp(argv[0], argv); execvp(argv[0], argv);
fprintf(stderr, "%s", "time: ");
perror(argv[0]);
if(errno == ENOENT) if(errno == ENOENT)
return 127; return _time_error(argv[0], 127);
return 126; return _time_error(argv[0], 126);
} }
for(;;) for(;;)
{ {
if(waitpid(pid, &status, 0) == -1) if(waitpid(pid, &status, 0) == -1)
{ return _time_error("waitpid", 2);
fprintf(stderr, "%s", "time: ");
perror("waitpid");
return 2;
}
if(WIFEXITED(status)) if(WIFEXITED(status))
break; break;
} }
if((cafter = times(&tmsbuf)) == -1) if((cafter = times(&tmsbuf)) == -1)
{ return _time_error("times", 2);
fprintf(stderr, "%s", "time: ");
perror("times");
return 2;
}
/* FIXME */ /* FIXME */
fprintf(stderr, "real %ld\nuser %ld\nsys %ld\n", fprintf(stderr, "real %ld\nuser %ld\nsys %ld\n",
cafter - cbefore, cafter - cbefore,
@ -65,6 +48,13 @@ static int _time(int argc, char * argv[])
return 0; return 0;
} }
static int _time_error(char * message, int ret)
{
fprintf(stderr, "%s", "time: ");
perror(message);
return ret;
}
/* usage */ /* usage */
static int _usage(void) static int _usage(void)