ttyname.c (165903) | ttyname.c (188497) |
---|---|
1/* 2 * Copyright (c) 1988, 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 --- 17 unchanged lines hidden (view full) --- 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#if defined(LIBC_SCCS) && !defined(lint) 31static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94"; 32#endif /* LIBC_SCCS and not lint */ 33#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1988, 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 --- 17 unchanged lines hidden (view full) --- 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#if defined(LIBC_SCCS) && !defined(lint) 31static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94"; 32#endif /* LIBC_SCCS and not lint */ 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/lib/libc/gen/ttyname.c 165903 2007-01-09 00:28:16Z imp $"); | 34__FBSDID("$FreeBSD: head/lib/libc/gen/ttyname.c 188497 2009-02-11 20:24:59Z ed $"); |
35 36#include "namespace.h" 37#include <sys/types.h> | 35 36#include "namespace.h" 37#include <sys/types.h> |
38#include <sys/stat.h> | |
39#include <sys/ioctl.h> 40#include <sys/filio.h> 41#include <fcntl.h> 42#include <dirent.h> 43#include <stdlib.h> 44#include <termios.h> 45#include <unistd.h> 46#include <string.h> --- 8 unchanged lines hidden (view full) --- 55 56static once_t ttyname_init_once = ONCE_INITIALIZER; 57static thread_key_t ttyname_key; 58static int ttyname_keycreated = 0; 59 60int 61ttyname_r(int fd, char *buf, size_t len) 62{ | 38#include <sys/ioctl.h> 39#include <sys/filio.h> 40#include <fcntl.h> 41#include <dirent.h> 42#include <stdlib.h> 43#include <termios.h> 44#include <unistd.h> 45#include <string.h> --- 8 unchanged lines hidden (view full) --- 54 55static once_t ttyname_init_once = ONCE_INITIALIZER; 56static thread_key_t ttyname_key; 57static int ttyname_keycreated = 0; 58 59int 60ttyname_r(int fd, char *buf, size_t len) 61{ |
63 struct stat sb; 64 struct fiodgname_arg fgn; | |
65 size_t used; 66 67 *buf = '\0'; 68 69 /* Must be a terminal. */ 70 if (!isatty(fd)) 71 return (ENOTTY); | 62 size_t used; 63 64 *buf = '\0'; 65 66 /* Must be a terminal. */ 67 if (!isatty(fd)) 68 return (ENOTTY); |
72 /* Must be a character device. */ 73 if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) 74 return (ENOTTY); | |
75 /* Must have enough room */ 76 if (len <= sizeof(_PATH_DEV)) 77 return (ERANGE); 78 79 strcpy(buf, _PATH_DEV); 80 used = strlen(buf); | 69 /* Must have enough room */ 70 if (len <= sizeof(_PATH_DEV)) 71 return (ERANGE); 72 73 strcpy(buf, _PATH_DEV); 74 used = strlen(buf); |
81 fgn.len = len - used; 82 fgn.buf = buf + used; 83 if (!_ioctl(fd, FIODGNAME, &fgn)) 84 return (0); 85 used = strlen(buf); 86 devname_r(sb.st_rdev, S_IFCHR, buf + used, len - used); | 75 if (fdevname_r(fd, buf + used, len - used) == NULL) 76 return (ENOTTY); |
87 return (0); 88} 89 90static void 91ttyname_keycreate(void) 92{ 93 ttyname_keycreated = (thr_keycreate(&ttyname_key, free) == 0); 94} --- 26 unchanged lines hidden --- | 77 return (0); 78} 79 80static void 81ttyname_keycreate(void) 82{ 83 ttyname_keycreated = (thr_keycreate(&ttyname_key, free) == 0); 84} --- 26 unchanged lines hidden --- |