📄 filestat.par.lib
字号:
FILESTAT - Functions to determine and output the type of a file from file descriptorfilestat - determine type of file from file descriptorprintstat - print the FileType as a stringFunction Prototypes:FileType filestat(int fd);char *printstat(int fd);filestat:Input:fd file descriptorReturns: FileType filestat(fd)printstat:Input:fd file descriptorReturns: char *printstat(fd)Notes:Example: FileType ftype; ... ftype = filestat(STDOUT) if (ftype = TTY) { ...BADFILETYPE is the error return and it is up to the calling program tocheck for it.FileType is defined in par.h as:typedef enum {BADFILETYPE = -1, TTY, DISK, DIRECTORY, TAPE, PIPE, FIFO, SOCKET, SYMLINK} FileType;SOCKETS and SYMLINKS are unlikely to be used.Rochkind's Advanced Unix Programming assures us that the link countfor a pipe is 0. But it's an old book. It seems that PIPES aresometimes implemented as FIFOs. In most cases, the number of links fora pipe is 0, even so. But on NeXT (at least) the link count is 1.In the code, I test for PIPE first and FIFO second, so for a PIPEyou'll actually get FIFO on machines that do it NeXT's way.Portability: the code assumes that /dev/rmt0 and /dev/mt0are tape devices on your system. If not, make the obvious changes.dev/null is handled as a special case and classified as a disk file.The check on tapes allows either the raw or buffered version.This is moot and easily changed.If new types are added, the typedef "FileType" in par.h must be extended.Authors:SEP: Einar Kjartansson , Stew LevinCWP: Jack Cohen
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -