getttyent.c (52856) | getttyent.c (90045) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. |
32 * 33 * $FreeBSD: head/lib/libc/gen/getttyent.c 52856 1999-11-04 04:16:28Z ache $ | |
34 */ 35 36#if defined(LIBC_SCCS) && !defined(lint) 37static char sccsid[] = "@(#)getttyent.c 8.1 (Berkeley) 6/4/93"; 38#endif /* LIBC_SCCS and not lint */ | 32 */ 33 34#if defined(LIBC_SCCS) && !defined(lint) 35static char sccsid[] = "@(#)getttyent.c 8.1 (Berkeley) 6/4/93"; 36#endif /* LIBC_SCCS and not lint */ |
37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD: head/lib/libc/gen/getttyent.c 90045 2002-02-01 01:32:19Z obrien $"); |
|
39 40#include <ttyent.h> 41#include <stdio.h> 42#include <stdlib.h> 43#include <ctype.h> 44#include <string.h> 45 46static char zapchar; 47static FILE *tf; 48static size_t lbsize; 49static char *line; 50 51#define MALLOCCHUNK 100 52 | 39 40#include <ttyent.h> 41#include <stdio.h> 42#include <stdlib.h> 43#include <ctype.h> 44#include <string.h> 45 46static char zapchar; 47static FILE *tf; 48static size_t lbsize; 49static char *line; 50 51#define MALLOCCHUNK 100 52 |
53static char *skip __P((char *)); 54static char *value __P((char *)); | 53static char *skip(char *); 54static char *value(char *); |
55 56struct ttyent * 57getttynam(tty) 58 const char *tty; 59{ | 55 56struct ttyent * 57getttynam(tty) 58 const char *tty; 59{ |
60 register struct ttyent *t; | 60 struct ttyent *t; |
61 62 if (strncmp(tty, "/dev/", 5) == 0) 63 tty += 5; 64 setttyent(); 65 while ( (t = getttyent()) ) 66 if (!strcmp(tty, t->ty_name)) 67 break; 68 endttyent(); 69 return (t); 70} 71 72struct ttyent * 73getttyent() 74{ 75 static struct ttyent tty; | 61 62 if (strncmp(tty, "/dev/", 5) == 0) 63 tty += 5; 64 setttyent(); 65 while ( (t = getttyent()) ) 66 if (!strcmp(tty, t->ty_name)) 67 break; 68 endttyent(); 69 return (t); 70} 71 72struct ttyent * 73getttyent() 74{ 75 static struct ttyent tty; |
76 register char *p; 77 register int c; | 76 char *p; 77 int c; |
78 size_t i; 79 80 if (!tf && !setttyent()) 81 return (NULL); 82 for (;;) { 83 if (!fgets(p = line, lbsize, tf)) 84 return (NULL); 85 /* extend buffer if line was too big, and retry */ --- 74 unchanged lines hidden (view full) --- 160#define QUOTED 1 161 162/* 163 * Skip over the current field, removing quotes, and return a pointer to 164 * the next field. 165 */ 166static char * 167skip(p) | 78 size_t i; 79 80 if (!tf && !setttyent()) 81 return (NULL); 82 for (;;) { 83 if (!fgets(p = line, lbsize, tf)) 84 return (NULL); 85 /* extend buffer if line was too big, and retry */ --- 74 unchanged lines hidden (view full) --- 160#define QUOTED 1 161 162/* 163 * Skip over the current field, removing quotes, and return a pointer to 164 * the next field. 165 */ 166static char * 167skip(p) |
168 register char *p; | 168 char *p; |
169{ | 169{ |
170 register char *t; 171 register int c, q; | 170 char *t; 171 int c, q; |
172 173 for (q = 0, t = p; (c = *p) != '\0'; p++) { 174 if (c == '"') { 175 q ^= QUOTED; /* obscure, but nice */ 176 continue; 177 } 178 if (q == QUOTED && *p == '\\' && *(p+1) == '"') 179 p++; --- 14 unchanged lines hidden (view full) --- 194 } 195 } 196 *--t = '\0'; 197 return (p); 198} 199 200static char * 201value(p) | 172 173 for (q = 0, t = p; (c = *p) != '\0'; p++) { 174 if (c == '"') { 175 q ^= QUOTED; /* obscure, but nice */ 176 continue; 177 } 178 if (q == QUOTED && *p == '\\' && *(p+1) == '"') 179 p++; --- 14 unchanged lines hidden (view full) --- 194 } 195 } 196 *--t = '\0'; 197 return (p); 198} 199 200static char * 201value(p) |
202 register char *p; | 202 char *p; |
203{ 204 205 return ((p = index(p, '=')) ? ++p : NULL); 206} 207 208int 209setttyent() 210{ --- 28 unchanged lines hidden (view full) --- 239 return (1); 240} 241 242static int 243isttystat(tty, flag) 244 const char *tty; 245 int flag; 246{ | 203{ 204 205 return ((p = index(p, '=')) ? ++p : NULL); 206} 207 208int 209setttyent() 210{ --- 28 unchanged lines hidden (view full) --- 239 return (1); 240} 241 242static int 243isttystat(tty, flag) 244 const char *tty; 245 int flag; 246{ |
247 register struct ttyent *t; | 247 struct ttyent *t; |
248 249 return ((t = getttynam(tty)) == NULL) ? 0 : !!(t->ty_status & flag); 250} 251 252 253int 254isdialuptty(tty) 255 const char *tty; 256{ 257 258 return isttystat(tty, TTY_DIALUP); 259} 260 261int isnettty(tty) 262 const char *tty; 263{ 264 265 return isttystat(tty, TTY_NETWORK); 266} | 248 249 return ((t = getttynam(tty)) == NULL) ? 0 : !!(t->ty_status & flag); 250} 251 252 253int 254isdialuptty(tty) 255 const char *tty; 256{ 257 258 return isttystat(tty, TTY_DIALUP); 259} 260 261int isnettty(tty) 262 const char *tty; 263{ 264 265 return isttystat(tty, TTY_NETWORK); 266} |