Deleted Added
full compact
36c36
< static char rcsid[] = "$Id$";
---
> static char rcsid[] = "$Id: subr.c,v 1.9 1997/02/22 14:21:40 peter Exp $";
48a49
> #include <syslog.h>
73a75,77
> int l;
> char *p;
> char *msg = NULL;
74a79,81
>
> static int firsttime = 1;
>
78c85,130
< if (cgetent(&buf, dba, name) != 0)
---
> if (firsttime) {
> /*
> * we need to strdup() anything in the strings array
> * initially in order to simplify things later
> */
> for (sp = gettystrs; sp->field; sp++)
> if (sp->value != NULL) {
> /* handle these ones more carefully */
> if (sp >= &gettystrs[4] && sp <= &gettystrs[6])
> l = 2;
> else
> l = strlen(sp->value) + 1;
> if ((p = malloc(l)) != NULL) {
> strncpy(p, sp->value, l);
> p[l-1] = '\0';
> }
> /*
> * replace, even if NULL, else we'll
> * have problems with free()ing static mem
> */
> sp->value = p;
> }
> firsttime = 0;
> }
>
> switch (cgetent(&buf, (char **)dba, (char *)name)) {
> case 1:
> msg = "%s: couldn't resolve 'tc=' in gettytab '%s'";
> case 0:
> break;
> case -1:
> msg = "%s: unknown gettytab entry '%s'";
> break;
> case -2:
> msg = "%s: retrieving gettytab entry '%s': %m";
> break;
> case -3:
> msg = "%s: recursive 'tc=' reference gettytab entry '%s'";
> break;
> default:
> msg = "%s: unexpected cgetent() error for entry '%s'";
> break;
> }
>
> if (msg != NULL) {
> syslog(LOG_ERR, msg, "getty", name);
79a132
> }
81,82c134,151
< for (sp = gettystrs; sp->field; sp++)
< cgetstr(buf, sp->field, &sp->value);
---
> for (sp = gettystrs; sp->field; sp++) {
> if ((l = cgetstr(buf, (char*)sp->field, &p)) >= 0) {
> if (sp->value) {
> /* prefer existing value */
> if (strcmp(p, sp->value) != 0)
> free(sp->value);
> else {
> free(p);
> p = sp->value;
> }
> }
> sp->value = p;
> } else if (l == -1) {
> free(sp->value);
> sp->value = NULL;
> }
> }
>
84c153
< if (cgetnum(buf, np->field, &n) == -1)
---
> if (cgetnum(buf, (char*)np->field, &n) == -1)
90a160
>
92c162
< if (cgetcap(buf, fp->field, ':') == NULL)
---
> if (cgetcap(buf, (char *)fp->field, ':') == NULL)
98a169
>
120c191
< sp->defalt = sp->value;
---
> sp->defalt = strdup(sp->value);
140c211,212
< sp->value = sp->defalt;
---
> sp->value = !sp->defalt ? sp->defalt
> : strdup(sp->defalt);