Xinqi Bao's Git

Add FreeBSD support for netspeeds, entropy and ip components
[slstatus.git] / slstatus.c
index 9bd9e81..96fa5b6 100644 (file)
@@ -36,13 +36,13 @@ difftimespec(struct timespec *res, struct timespec *a, struct timespec *b)
 {
        res->tv_sec = a->tv_sec - b->tv_sec - (a->tv_nsec < b->tv_nsec);
        res->tv_nsec = a->tv_nsec - b->tv_nsec +
 {
        res->tv_sec = a->tv_sec - b->tv_sec - (a->tv_nsec < b->tv_nsec);
        res->tv_nsec = a->tv_nsec - b->tv_nsec +
-                      (a->tv_nsec < b->tv_nsec) * 1000000000;
+                      (a->tv_nsec < b->tv_nsec) * 1E9;
 }
 
 static void
 usage(void)
 {
 }
 
 static void
 usage(void)
 {
-       die("usage: %s [-so]", argv0);
+       die("usage: %s [-s]", argv0);
 }
 
 int
 }
 
 int
@@ -51,18 +51,15 @@ main(int argc, char *argv[])
        struct sigaction act;
        struct timespec start, current, diff, intspec, wait;
        size_t i, len;
        struct sigaction act;
        struct timespec start, current, diff, intspec, wait;
        size_t i, len;
-       int sflag, oflag, ret;
+       int sflag, ret;
        char status[MAXLEN];
        const char *res;
 
        char status[MAXLEN];
        const char *res;
 
-       sflag = oflag = 0;
+       sflag = 0;
        ARGBEGIN {
                case 's':
                        sflag = 1;
                        break;
        ARGBEGIN {
                case 's':
                        sflag = 1;
                        break;
-               case 'o':
-                       oflag = 1;
-                       break;
                default:
                        usage();
        } ARGEND
                default:
                        usage();
        } ARGEND
@@ -76,10 +73,6 @@ main(int argc, char *argv[])
        sigaction(SIGINT,  &act, NULL);
        sigaction(SIGTERM, &act, NULL);
 
        sigaction(SIGINT,  &act, NULL);
        sigaction(SIGTERM, &act, NULL);
 
-       if (sflag) {
-               setbuf(stdout, NULL);
-       }
-
        if (!sflag && !(dpy = XOpenDisplay(NULL))) {
                die("XOpenDisplay: Failed to open display");
        }
        if (!sflag && !(dpy = XOpenDisplay(NULL))) {
                die("XOpenDisplay: Failed to open display");
        }
@@ -102,20 +95,18 @@ main(int argc, char *argv[])
                }
 
                if (sflag) {
                }
 
                if (sflag) {
-                       if (printf("%s\n", status) < 0) {
-                               die("printf:");
-                       }
+                       puts(status);
+                       fflush(stdout);
+                       if (ferror(stdout))
+                               die("puts:");
                } else {
                } else {
-                       if (XStoreName(dpy, DefaultRootWindow(dpy), status) < 0) {
+                       if (XStoreName(dpy, DefaultRootWindow(dpy), status)
+                            < 0) {
                                die("XStoreName: Allocation failed");
                        }
                        XFlush(dpy);
                }
 
                                die("XStoreName: Allocation failed");
                        }
                        XFlush(dpy);
                }
 
-               if (oflag) {
-                       done = 1;
-               }
-
                if (!done) {
                        if (clock_gettime(CLOCK_MONOTONIC, &current) < 0) {
                                die("clock_gettime:");
                if (!done) {
                        if (clock_gettime(CLOCK_MONOTONIC, &current) < 0) {
                                die("clock_gettime:");
@@ -123,7 +114,7 @@ main(int argc, char *argv[])
                        difftimespec(&diff, &current, &start);
 
                        intspec.tv_sec = interval / 1000;
                        difftimespec(&diff, &current, &start);
 
                        intspec.tv_sec = interval / 1000;
-                       intspec.tv_nsec = (interval % 1000) * 1000000;
+                       intspec.tv_nsec = (interval % 1000) * 1E6;
                        difftimespec(&wait, &intspec, &diff);
 
                        if (wait.tv_sec >= 0) {
                        difftimespec(&wait, &intspec, &diff);
 
                        if (wait.tv_sec >= 0) {