bore

basic core utilities (PD)
git clone git://bvnf.space/bore.git
Log | Files | Refs | README

nice.c (602B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int
main(int argc, char **argv) {
    int n = 10;
    if (argc > 3 && strcmp("-n", argv[1]) == 0) {
        n = atoi(argv[2]);
        argv += 2;
        argc -= 2;
    }

    if (argc == 1) {
        fprintf(stderr, "usage: nice [-n increment] utility [args]\n");
        return 1;
    }

    errno = 0;
    if (nice(n) == -1 && errno) {
        perror("nice");
    }

    errno = 0;
    execvp(argv[1], argv + 1);

    if (errno) {
        perror(argv[1]);
        return 127;
    }
    return 126;
}