1: /*
   2:  *! Change to support the new /etc/ttys format.
   3:  *! getttys uses blank or tab as a line terminator
   4:  *!	WFJolitz 4/7/80
   5:  */
   6: 
   7: /*
   8:  * Return the number of the slot in the utmp file
   9:  * corresponding to the current user: try for file 0, 1, 2.
  10:  * Definition is the line number in the /etc/ttys file.
  11:  */
  12: 
  13: 
  14: char    *ttyname();
  15: char    *getttys();
  16: char    *rindex();
  17: static  char    ttys[]  = "/etc/ttys";
  18: 
  19: #define NULL    0
  20: 
  21: ttyslot()
  22: {
  23:     register char *tp, *p;
  24:     register s, tf;
  25: 
  26:     if ((tp=ttyname(0))==NULL && (tp=ttyname(1))==NULL && (tp=ttyname(2))==NULL)
  27:         return(0);
  28:     if ((p = rindex(tp, '/')) == NULL)
  29:         p = tp;
  30:     else
  31:         p++;
  32:     if ((tf=open(ttys, 0)) < 0)
  33:         return(0);
  34:     s = 0;
  35:     while (tp = getttys(tf)) {
  36:         s++;
  37:         if (strcmp(p, tp)==0) {
  38:             close(tf);
  39:             return(s);
  40:         }
  41:     }
  42:     close(tf);
  43:     return(0);
  44: }
  45: 
  46: static char *
  47: getttys(f)
  48: {
  49:     static char line[32];
  50:     register char *lp;
  51: 
  52:     lp = line;
  53:     for (;;) {
  54:         if (read(f, lp, 1) != 1)
  55:             return(NULL);
  56:         if ( *lp == '\t' || *lp == ' ')
  57:         {
  58:             while (read(f, lp, 1) == 1 && *lp != '\n');
  59:             if(*lp != '\n')
  60:                 return(NULL);
  61:         }
  62:         if (*lp =='\n')
  63:         {
  64:             *lp = '\0';
  65:             return(line+2);
  66:         }
  67:         if (lp >= &line[32])
  68:             return(line+2);
  69:         lp++;
  70:     }
  71: }

Defined functions

getttys defined in line 46; used 2 times
ttyslot defined in line 21; used 3 times

Defined variables

ttys defined in line 17; used 1 times
  • in line 32

Defined macros

NULL defined in line 19; used 6 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 687
Valid CSS Valid XHTML 1.0 Strict