ttyname.c (188497) | ttyname.c (278038) |
---|---|
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 188497 2009-02-11 20:24:59Z ed $"); | 34__FBSDID("$FreeBSD: head/lib/libc/gen/ttyname.c 278038 2015-02-01 22:50:33Z jilles $"); |
35 36#include "namespace.h" 37#include <sys/types.h> 38#include <sys/ioctl.h> 39#include <sys/filio.h> 40#include <fcntl.h> 41#include <dirent.h> 42#include <stdlib.h> --- 17 unchanged lines hidden (view full) --- 60ttyname_r(int fd, char *buf, size_t len) 61{ 62 size_t used; 63 64 *buf = '\0'; 65 66 /* Must be a terminal. */ 67 if (!isatty(fd)) | 35 36#include "namespace.h" 37#include <sys/types.h> 38#include <sys/ioctl.h> 39#include <sys/filio.h> 40#include <fcntl.h> 41#include <dirent.h> 42#include <stdlib.h> --- 17 unchanged lines hidden (view full) --- 60ttyname_r(int fd, char *buf, size_t len) 61{ 62 size_t used; 63 64 *buf = '\0'; 65 66 /* Must be a terminal. */ 67 if (!isatty(fd)) |
68 return (ENOTTY); | 68 return (errno); |
69 /* Must have enough room */ 70 if (len <= sizeof(_PATH_DEV)) 71 return (ERANGE); 72 73 strcpy(buf, _PATH_DEV); 74 used = strlen(buf); 75 if (fdevname_r(fd, buf + used, len - used) == NULL) | 69 /* Must have enough room */ 70 if (len <= sizeof(_PATH_DEV)) 71 return (ERANGE); 72 73 strcpy(buf, _PATH_DEV); 74 used = strlen(buf); 75 if (fdevname_r(fd, buf + used, len - used) == NULL) |
76 return (ENOTTY); | 76 return (errno == EINVAL ? ERANGE : errno); |
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 --- | 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 --- |