Back to index

glibc  2.9
Functions
ttyslot.c File Reference
#include <ttyent.h>
#include <alloca.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

Go to the source code of this file.

Functions

int ttyslot ()

Function Documentation

int ttyslot ( )

Definition at line 41 of file ttyslot.c.

{
       register struct ttyent *ttyp;
       register int slot;
       register char *p;
       int cnt;
       size_t buflen = __sysconf (_SC_TTY_NAME_MAX) + 1;
       char *name;

       if (buflen == 0)
         /* This should be enough if no fixed value is given.  */
         buflen = 32;

       name = __alloca (buflen);

       setttyent();
       for (cnt = 0; cnt < 3; ++cnt)
              if (__ttyname_r (cnt, name, buflen) == 0) {
                     if ((p = rindex(name, '/')))
                            ++p;
                     else
                            p = name;
                     for (slot = 1; (ttyp = getttyent()); ++slot)
                            if (!strcmp(ttyp->ty_name, p)) {
                                   endttyent();
                                   return(slot);
                            }
                     break;
              }
       endttyent();
       return(0);
}

Here is the call graph for this function: