|
Packit Service |
82fcde |
/*
|
|
Packit Service |
82fcde |
* Copyright (c) 1989, 1993
|
|
Packit Service |
82fcde |
* The Regents of the University of California. All rights reserved.
|
|
Packit Service |
82fcde |
*
|
|
Packit Service |
82fcde |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
82fcde |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
82fcde |
* are met:
|
|
Packit Service |
82fcde |
* 1. Redistributions of source code must retain the above copyright
|
|
Packit Service |
82fcde |
* notice, this list of conditions and the following disclaimer.
|
|
Packit Service |
82fcde |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit Service |
82fcde |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit Service |
82fcde |
* documentation and/or other materials provided with the distribution.
|
|
Packit Service |
82fcde |
* 4. Neither the name of the University nor the names of its contributors
|
|
Packit Service |
82fcde |
* may be used to endorse or promote products derived from this software
|
|
Packit Service |
82fcde |
* without specific prior written permission.
|
|
Packit Service |
82fcde |
*
|
|
Packit Service |
82fcde |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
Packit Service |
82fcde |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit Service |
82fcde |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit Service |
82fcde |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
Packit Service |
82fcde |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Packit Service |
82fcde |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
Packit Service |
82fcde |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
Packit Service |
82fcde |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
Packit Service |
82fcde |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
Packit Service |
82fcde |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
Packit Service |
82fcde |
* SUCH DAMAGE.
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#if defined(LIBC_SCCS) && !defined(lint)
|
|
Packit Service |
82fcde |
static char sccsid[] = "@(#)getttyent.c 8.1 (Berkeley) 6/4/93";
|
|
Packit Service |
82fcde |
#endif /* LIBC_SCCS and not lint */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <ttyent.h>
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
#include <stdio_ext.h>
|
|
Packit Service |
82fcde |
#include <ctype.h>
|
|
Packit Service |
82fcde |
#include <string.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define flockfile(s) _IO_flockfile (s)
|
|
Packit Service |
82fcde |
#define funlockfile(s) _IO_funlockfile (s)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static char zapchar;
|
|
Packit Service |
82fcde |
static FILE *tf;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
struct ttyent *
|
|
Packit Service |
82fcde |
__getttynam (const char *tty)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
struct ttyent *t;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
__setttyent();
|
|
Packit Service |
82fcde |
while ((t = __getttyent()))
|
|
Packit Service |
82fcde |
if (!strcmp(tty, t->ty_name))
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
__endttyent();
|
|
Packit Service |
82fcde |
return (t);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
weak_alias (__getttynam, getttynam)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static char *skip (char *) __THROW;
|
|
Packit Service |
82fcde |
static char *value (char *) __THROW;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
struct ttyent *
|
|
Packit Service |
82fcde |
__getttyent (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
static struct ttyent tty;
|
|
Packit Service |
82fcde |
int c;
|
|
Packit Service |
82fcde |
char *p;
|
|
Packit Service |
82fcde |
#define MAXLINELENGTH 100
|
|
Packit Service |
82fcde |
static char line[MAXLINELENGTH];
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (!tf && !__setttyent())
|
|
Packit Service |
82fcde |
return (NULL);
|
|
Packit Service |
82fcde |
flockfile (tf);
|
|
Packit Service |
82fcde |
for (;;) {
|
|
Packit Service |
82fcde |
if (!__fgets_unlocked(p = line, sizeof(line), tf)) {
|
|
Packit Service |
82fcde |
funlockfile (tf);
|
|
Packit Service |
82fcde |
return (NULL);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
/* skip lines that are too big */
|
|
Packit Service |
82fcde |
if (!strchr (p, '\n')) {
|
|
Packit Service |
82fcde |
while ((c = __getc_unlocked(tf)) != '\n' && c != EOF)
|
|
Packit Service |
82fcde |
;
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
while (isspace(*p))
|
|
Packit Service |
82fcde |
++p;
|
|
Packit Service |
82fcde |
if (*p && *p != '#')
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
zapchar = 0;
|
|
Packit Service |
82fcde |
tty.ty_name = p;
|
|
Packit Service |
82fcde |
p = skip(p);
|
|
Packit Service |
82fcde |
if (!*(tty.ty_getty = p))
|
|
Packit Service |
82fcde |
tty.ty_getty = tty.ty_type = NULL;
|
|
Packit Service |
82fcde |
else {
|
|
Packit Service |
82fcde |
p = skip(p);
|
|
Packit Service |
82fcde |
if (!*(tty.ty_type = p))
|
|
Packit Service |
82fcde |
tty.ty_type = NULL;
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
p = skip(p);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
tty.ty_status = 0;
|
|
Packit Service |
82fcde |
tty.ty_window = NULL;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1])
|
|
Packit Service |
82fcde |
#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '='
|
|
Packit Service |
82fcde |
for (; *p; p = skip(p)) {
|
|
Packit Service |
82fcde |
if (scmp(_TTYS_OFF))
|
|
Packit Service |
82fcde |
tty.ty_status &= ~TTY_ON;
|
|
Packit Service |
82fcde |
else if (scmp(_TTYS_ON))
|
|
Packit Service |
82fcde |
tty.ty_status |= TTY_ON;
|
|
Packit Service |
82fcde |
else if (scmp(_TTYS_SECURE))
|
|
Packit Service |
82fcde |
tty.ty_status |= TTY_SECURE;
|
|
Packit Service |
82fcde |
else if (vcmp(_TTYS_WINDOW))
|
|
Packit Service |
82fcde |
tty.ty_window = value(p);
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
/* We can release the lock only here since `zapchar' is global. */
|
|
Packit Service |
82fcde |
funlockfile(tf);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (zapchar == '#' || *p == '#')
|
|
Packit Service |
82fcde |
while ((c = *++p) == ' ' || c == '\t')
|
|
Packit Service |
82fcde |
;
|
|
Packit Service |
82fcde |
tty.ty_comment = p;
|
|
Packit Service |
82fcde |
if (*p == 0)
|
|
Packit Service |
82fcde |
tty.ty_comment = 0;
|
|
Packit Service |
82fcde |
if ((p = strchr (p, '\n')))
|
|
Packit Service |
82fcde |
*p = '\0';
|
|
Packit Service |
82fcde |
return (&tty);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
libc_hidden_def (__getttyent)
|
|
Packit Service |
82fcde |
weak_alias (__getttyent, getttyent)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define QUOTED 1
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/*
|
|
Packit Service |
82fcde |
* Skip over the current field, removing quotes, and return a pointer to
|
|
Packit Service |
82fcde |
* the next field.
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
static char *
|
|
Packit Service |
82fcde |
skip (char *p)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
char *t;
|
|
Packit Service |
82fcde |
int c, q;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
for (q = 0, t = p; (c = *p) != '\0'; p++) {
|
|
Packit Service |
82fcde |
if (c == '"') {
|
|
Packit Service |
82fcde |
q ^= QUOTED; /* obscure, but nice */
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (q == QUOTED && *p == '\\' && *(p+1) == '"')
|
|
Packit Service |
82fcde |
p++;
|
|
Packit Service |
82fcde |
*t++ = *p;
|
|
Packit Service |
82fcde |
if (q == QUOTED)
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
if (c == '#') {
|
|
Packit Service |
82fcde |
zapchar = c;
|
|
Packit Service |
82fcde |
*p = 0;
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (c == '\t' || c == ' ' || c == '\n') {
|
|
Packit Service |
82fcde |
zapchar = c;
|
|
Packit Service |
82fcde |
*p++ = 0;
|
|
Packit Service |
82fcde |
while ((c = *p) == '\t' || c == ' ' || c == '\n')
|
|
Packit Service |
82fcde |
p++;
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
*--t = '\0';
|
|
Packit Service |
82fcde |
return (p);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static char *
|
|
Packit Service |
82fcde |
value (char *p)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return ((p = strchr (p, '=')) ? ++p : NULL);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
__setttyent (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (tf) {
|
|
Packit Service |
82fcde |
(void)rewind(tf);
|
|
Packit Service |
82fcde |
return (1);
|
|
Packit Service |
82fcde |
} else if ((tf = fopen(_PATH_TTYS, "rce"))) {
|
|
Packit Service |
82fcde |
/* We do the locking ourselves. */
|
|
Packit Service |
82fcde |
__fsetlocking (tf, FSETLOCKING_BYCALLER);
|
|
Packit Service |
82fcde |
return (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
return (0);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
libc_hidden_def (__setttyent)
|
|
Packit Service |
82fcde |
weak_alias (__setttyent, setttyent)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
__endttyent (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int rval;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (tf) {
|
|
Packit Service |
82fcde |
rval = !(fclose(tf) == EOF);
|
|
Packit Service |
82fcde |
tf = NULL;
|
|
Packit Service |
82fcde |
return (rval);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
return (1);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
libc_hidden_def (__endttyent)
|
|
Packit Service |
82fcde |
weak_alias (__endttyent, endttyent)
|