Annotation of 3BSD/cmd/who.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * who
                      3:  */
                      4: 
                      5: #include <stdio.h>
                      6: #include <utmp.h>
                      7: #include <pwd.h>
                      8: struct utmp utmp;
                      9: struct passwd *pw;
                     10: struct passwd *getpwuid();
                     11: 
                     12: char *ttyname(), *rindex(), *ctime(), *strcpy();
                     13: main(argc, argv)
                     14: char **argv;
                     15: {
                     16:        register char *tp, *s;
                     17:        register FILE *fi;
                     18: 
                     19:        s = "/etc/utmp";
                     20:        if(argc == 2)
                     21:                s = argv[1];
                     22:        if (argc==3) {
                     23:                tp = ttyname(0);
                     24:                if (tp)
                     25:                        tp = rindex(tp, '/') + 1;
                     26:                else {  /* no tty - use best guess from passwd file */
                     27:                        pw = getpwuid(getuid());
                     28:                        strcpy(utmp.ut_name, pw?pw->pw_name: "?");
                     29:                        strcpy(utmp.ut_line, "tty??");
                     30:                        time(&utmp.ut_time);
                     31:                        putline();
                     32:                        exit(0);
                     33:                }
                     34:        }
                     35:        if ((fi = fopen(s, "r")) == NULL) {
                     36:                puts("who: cannot open utmp");
                     37:                exit(1);
                     38:        }
                     39:        while (fread((char *)&utmp, sizeof(utmp), 1, fi) == 1) {
                     40:                if(argc==3) {
                     41:                        if (strcmp(utmp.ut_line, tp))
                     42:                                continue;
                     43: #ifdef vax
                     44:                        printf("(Vax) ");
                     45: #endif
                     46:                        putline();
                     47:                        exit(0);
                     48:                }
                     49:                if(utmp.ut_name[0] == '\0' && argc==1)
                     50:                        continue;
                     51:                putline();
                     52:        }
                     53: }
                     54: 
                     55: putline()
                     56: {
                     57:        register char *cbuf;
                     58: 
                     59:        printf("%-8.8s %-8.8s", utmp.ut_name, utmp.ut_line);
                     60:        cbuf = ctime(&utmp.ut_time);
                     61:        printf("%.12s\n", cbuf+4);
                     62: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.