keep this function safe for others. return impossible value on error.
authorPeter B. Kessler <peter@ucbvax.Berkeley.EDU>
Tue, 31 Jan 1984 08:37:56 +0000 (00:37 -0800)
committerPeter B. Kessler <peter@ucbvax.Berkeley.EDU>
Tue, 31 Jan 1984 08:37:56 +0000 (00:37 -0800)
SCCS-vsn: usr.bin/gprof/hertz.c 1.3

usr/src/usr.bin/gprof/hertz.c

index c87fe70..17d8edf 100644 (file)
@@ -1,16 +1,16 @@
 #ifndef lint
 #ifndef lint
-    static     char *sccsid = "@(#)hertz.c     1.2 (Berkeley) %G%";
+    static     char *sccsid = "@(#)hertz.c     1.3 (Berkeley) %G%";
 #endif lint
 
     /*
      * discover the tick frequency of the machine
 #endif lint
 
     /*
      * discover the tick frequency of the machine
-     * if something goes wrong, we return HZ_DEFAULT.
+     * if something goes wrong, we return 0, an impossible hertz.
      */
 #include <nlist.h>
 #include <stdio.h>
 
 #define        HZ_SYMBOL       "_hz"
      */
 #include <nlist.h>
 #include <stdio.h>
 
 #define        HZ_SYMBOL       "_hz"
-#define        HZ_DEFAULT      1
+#define        HZ_WRONG        0
 
 struct nlist   nl[] =  {{HZ_SYMBOL},   /* clock ticks per second */
                         {0}};
 
 struct nlist   nl[] =  {{HZ_SYMBOL},   /* clock ticks per second */
                         {0}};
@@ -28,34 +28,31 @@ hertz()
     nlist(VMUNIX, nl);
     if (nl[0].n_type == 0) {
        fprintf(stderr, "no %s namelist entry for %s\n", VMUNIX, HZ_SYMBOL);
     nlist(VMUNIX, nl);
     if (nl[0].n_type == 0) {
        fprintf(stderr, "no %s namelist entry for %s\n", VMUNIX, HZ_SYMBOL);
-wrong:
-       fprintf(stderr, "times are in units of %d tick%s, not seconds\n",
-                       HZ_DEFAULT, HZ_DEFAULT==1?"":"s");
-       return HZ_DEFAULT;
+       return HZ_WRONG;
     }
 #   define     KMEM    "/dev/kmem"     /* location of the system data space */
     kmem = open(KMEM, 0);
     if (kmem == -1) {
        perror("hertz()");
        fprintf(stderr, "open(\"%s\", 0)", KMEM);
     }
 #   define     KMEM    "/dev/kmem"     /* location of the system data space */
     kmem = open(KMEM, 0);
     if (kmem == -1) {
        perror("hertz()");
        fprintf(stderr, "open(\"%s\", 0)", KMEM);
-       goto wrong;
+       return HZ_WRONG;
     }
     seeked = lseek(kmem, nl[0].n_value, 0);
     if (seeked == -1) {
        fprintf(stderr, "can't lseek(kmem, 0x%x, 0)\n", nl[0].n_value);
     }
     seeked = lseek(kmem, nl[0].n_value, 0);
     if (seeked == -1) {
        fprintf(stderr, "can't lseek(kmem, 0x%x, 0)\n", nl[0].n_value);
-       goto wrong;
+       return HZ_WRONG;
     }
     red = read(kmem, &hz, sizeof hz);
     if (red != sizeof hz) {
        fprintf(stderr, "read(kmem, 0x%x, %d) returned %d\n",
                &hz, sizeof hz, red);
     }
     red = read(kmem, &hz, sizeof hz);
     if (red != sizeof hz) {
        fprintf(stderr, "read(kmem, 0x%x, %d) returned %d\n",
                &hz, sizeof hz, red);
-       goto wrong;
+       return HZ_WRONG;
     }
     closed = close(kmem);
     if (closed != 0) {
        perror("hertz()");
        fprintf(stderr, "close(\"%s\")", KMEM);
     }
     closed = close(kmem);
     if (closed != 0) {
        perror("hertz()");
        fprintf(stderr, "close(\"%s\")", KMEM);
-       goto wrong;
+       return HZ_WRONG;
     }
     return hz;
 }
     }
     return hz;
 }