1 #define _POSIX_C_SOURCE 200809L
10 /* Public domain by Nathan Wagner */
12 /* reads a long from a string. returns -1 if completely
13 * read, number of characters read otherwise,
14 * or zero if it can't read a string
15 * clears errno, which may be reset again by strtol()
17 static int readint(char *s, long *i) {
21 val = strtol(s, &end, 10);
23 /* Check for various possible errors */
25 if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
26 || (errno != 0 && val == 0)) {
32 fprintf(stderr, "No digits were found\n");
36 /* If we got here, strtol() successfully parsed a number */
41 /* Not necessarily an error... */
42 /* printf("Further characters after number: %s\n", endptr); */
49 static void usage(void) {
50 fprintf(stderr, "usage: nice [-n increment] utility [argument...]\n");
54 int main(int ac, char *av[]) {
58 if (arg < ac && !strcmp(av[arg], "-n")) {
62 } else if (++arg < ac) {
65 if (s && (readint(s, &nval) == -1)) {
74 execvp(av[arg], &av[arg]);
77 fprintf(stderr, "nice: ");
81 fprintf(stderr, "nice: ");