Annotation of 43BSD/contrib/mh/uip/ttym.c, revision 1.1.1.1

1.1       root        1: /* ttym.c - miscellaneous routines */
                      2: 
                      3: #include <pwd.h>
                      4: #ifndef        NSIG
                      5: #include <signal.h>
                      6: #endif NSIG
                      7: #include <sys/time.h>
                      8: 
                      9: /*  */
                     10: 
                     11: static  ttym (fd, command, line, user, vec)
                     12: int     fd;
                     13: char   *command,
                     14:        *line,
                     15:        *user,
                     16:       **vec;
                     17: {
                     18:     int     (*pstat) ();
                     19:     char   *ap,
                     20:            *term,
                     21:            *myself,
                     22:            *getlogin (),
                     23:            *rindex (),
                     24:            *ttyname ();
                     25:     struct passwd  *pw,
                     26:                    *getpwuid ();
                     27: 
                     28:     if ((term = ap = ttyname (2)) && (term = rindex (term, '/')))
                     29:        term++;
                     30:     if (term == NULL || *term == NULL)
                     31:        term = ap;
                     32:     if ((myself = getlogin ()) == NULL || *myself == NULL)
                     33:        myself = (pw = getpwuid (getuid ())) ? pw -> pw_name : NULL;
                     34: 
                     35:     pstat = signal (SIGPIPE, SIG_IGN);
                     36:     (void) write (fd, command, strlen (command));
                     37:     (void) write (fd, "", 1);
                     38: 
                     39:     if (term)
                     40:        (void) write (fd, term, strlen (term));
                     41:     (void) write (fd, "", 1);
                     42: 
                     43:     if (myself)
                     44:        (void) write (fd, myself, strlen (myself));
                     45:     (void) write (fd, "", 1);
                     46: 
                     47:     if (line && *line)
                     48:        (void) write (fd, line, strlen (line));
                     49:     (void) write (fd, "", 1);
                     50: 
                     51:     if (user && *user)
                     52:        (void) write (fd, user, strlen (user));
                     53:     (void) write (fd, "", 1);
                     54: 
                     55:     if (vec)
                     56:        while (ap = *vec++) {
                     57:            (void) write (fd, ap, strlen (ap));
                     58:            (void) write (fd, "", 1);
                     59:        }
                     60: 
                     61:     (void) write (fd, "", 1);
                     62:     (void) signal (SIGPIPE, pstat);
                     63: }
                     64: 
                     65: /*  */
                     66: 
                     67: static int  ttyv (fd)
                     68: int     fd;
                     69: {
                     70:     int     ifds,
                     71:            nbits;
                     72:     char    c;
                     73:     struct timeval tv;
                     74: 
                     75:     ifds = 1 << fd;
                     76:     nbits = getdtablesize();
                     77:     tv.tv_sec = SMLWAIT;
                     78:     tv.tv_usec = 0;
                     79:     if (select (nbits, &ifds, (int *) 0, (int *) 0, &tv) <= 0
                     80:            || read (fd, &c, 1) != 1)
                     81:        return NOTOK;
                     82:     if (c == NULL)
                     83:        return fd;
                     84:     putc (c, stderr);
                     85: 
                     86:     (void) ttyf (fd, stderr);
                     87:     return NOTOK;
                     88: }
                     89: 
                     90: 
                     91: static int  ttyf (fd, f)
                     92: int     fd;
                     93: FILE * f;
                     94: {
                     95:     int     i;
                     96:     char    buffer[BUFSIZ];
                     97: 
                     98:     while ((i = read (fd, buffer, sizeof buffer)) > 0)
                     99:        (void) fwrite (buffer, sizeof (char), i, f);
                    100:     return i;
                    101: }

unix.superglobalmegacorp.com

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