|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 729 (0x2d9) Types: TextFile Notes: UNIX file Names: »ttyname.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦f4b8d8c84⟧ UNIX Filesystem └─⟦this⟧ »libc/gen/ttyname.c«
/* * Coherent I/O Library * Return the name of the terminal device * associated with the given file descriptor. */ #include <stdio.h> #include <stat.h> #include <dir.h> #include <canon.h> static char tname[6+DIRSIZ] = "/dev/console"; #define tstart (tname+5) /* Where to put terminal name */ char * ttyname(fd) int fd; { struct stat sb; struct direct db; register devfd; if (fstat(fd, &sb)<0 || (sb.st_mode&S_IFMT)!=S_IFCHR) return (NULL); if ((devfd = open("/dev", 0)) < 0) return (NULL); while (read(devfd, &db, sizeof(db)) == sizeof(db)) { canino(db.d_ino); if (db.d_ino == sb.st_ino) { strncpy(tstart, db.d_name, DIRSIZ); close(devfd); return (tname); } } close(devfd); return (NULL); }