Back to index

glibc  2.9
Defines | Functions | Variables
getttyent.c File Reference
#include <ttyent.h>
#include <stdio.h>
#include <stdio_ext.h>
#include <ctype.h>
#include <string.h>

Go to the source code of this file.

Defines

#define MAXLINELENGTH   100
#define scmp(e)   !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1])
#define vcmp(e)   !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '='
#define QUOTED   1

Functions

struct ttyentgetttynam (char *tty) const
static char * skip (char *)
 libc_hidden_def (getttyent)
static char *internal_function value (char *p)
int setttyent ()
 libc_hidden_def (setttyent)

Variables

static char zapchar
static FILEtf

Define Documentation

#define MAXLINELENGTH   100
#define QUOTED   1
#define scmp (   e)    !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1])
#define vcmp (   e)    !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '='

Function Documentation

struct ttyent* getttynam ( char *  tty) const [read]

Definition at line 49 of file getttyent.c.

{
       register struct ttyent *t;

       setttyent();
       while ((t = getttyent()))
              if (!strcmp(tty, t->ty_name))
                     break;
       endttyent();
       return (t);
}

Here is the call graph for this function:

Definition at line 136 of file getttyent.c.

{
       register char *t;
       register int c, q;

       for (q = 0, t = p; (c = *p) != '\0'; p++) {
              if (c == '"') {
                     q ^= QUOTED;  /* obscure, but nice */
                     continue;
              }
              if (q == QUOTED && *p == '\\' && *(p+1) == '"')
                     p++;
              *t++ = *p;
              if (q == QUOTED)
                     continue;
              if (c == '#') {
                     zapchar = c;
                     *p = 0;
                     break;
              }
              if (c == '\t' || c == ' ' || c == '\n') {
                     zapchar = c;
                     *p++ = 0;
                     while ((c = *p) == '\t' || c == ' ' || c == '\n')
                            p++;
                     break;
              }
       }
       *--t = '\0';
       return (p);
}

Definition at line 202 of file getttyent.c.

{
       int rval;

       if (tf) {
              rval = !(fclose(tf) == EOF);
              tf = NULL;
              return (rval);
       }
       return (1);
}

Here is the call graph for this function:

int setttyent ( void  )

Definition at line 189 of file getttyent.c.

{

       if (tf) {
              (void)rewind(tf);
              return (1);
       } else if ((tf = fopen(_PATH_TTYS, "rc"))) {
              /* We do the locking ourselves.  */
              __fsetlocking (tf, FSETLOCKING_BYCALLER);
              return (1);
       }
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* skip ( char *  ) [static]

Definition at line 62 of file getttyent.c.

{
       static struct ttyent tty;
       register int c;
       register char *p;
#define       MAXLINELENGTH 100
       static char line[MAXLINELENGTH];

       if (!tf && !setttyent())
              return (NULL);
       flockfile (tf);
       for (;;) {
              if (!fgets_unlocked(p = line, sizeof(line), tf)) {
                     funlockfile (tf);
                     return (NULL);
              }
              /* skip lines that are too big */
              if (!index(p, '\n')) {
                     while ((c = getc_unlocked(tf)) != '\n' && c != EOF)
                            ;
                     continue;
              }
              while (isspace(*p))
                     ++p;
              if (*p && *p != '#')
                     break;
       }

       zapchar = 0;
       tty.ty_name = p;
       p = skip(p);
       if (!*(tty.ty_getty = p))
              tty.ty_getty = tty.ty_type = NULL;
       else {
              p = skip(p);
              if (!*(tty.ty_type = p))
                     tty.ty_type = NULL;
              else
                     p = skip(p);
       }
       tty.ty_status = 0;
       tty.ty_window = NULL;

#define       scmp(e)       !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1])
#define       vcmp(e)       !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '='
       for (; *p; p = skip(p)) {
              if (scmp(_TTYS_OFF))
                     tty.ty_status &= ~TTY_ON;
              else if (scmp(_TTYS_ON))
                     tty.ty_status |= TTY_ON;
              else if (scmp(_TTYS_SECURE))
                     tty.ty_status |= TTY_SECURE;
              else if (vcmp(_TTYS_WINDOW))
                     tty.ty_window = value(p);
              else
                     break;
       }
       /* We can release the lock only here since `zapchar' is global.  */
       funlockfile(tf);

       if (zapchar == '#' || *p == '#')
              while ((c = *++p) == ' ' || c == '\t')
                     ;
       tty.ty_comment = p;
       if (*p == 0)
              tty.ty_comment = 0;
       if ((p = index(p, '\n')))
              *p = '\0';
       return (&tty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* internal_function value ( char *  p) [static]

Definition at line 181 of file getttyent.c.

{

       return ((p = index(p, '=')) ? ++p : NULL);
}

Here is the call graph for this function:


Variable Documentation

FILE* tf [static]

Definition at line 46 of file getttyent.c.

char zapchar [static]

Definition at line 45 of file getttyent.c.