ls & file pipes (FIFO), curses...
Rich Stevens
rstevens at noao.edu
Thu Feb 21 09:44:34 AEST 1991
In article <471 at bria> uunet!bria!mike writes:
>
>A file that is a named pipe shoould have S_IFIFO set in st_mode;
>such as:
>
> if ( stat(file,&buf) != -1 && buf.st_mode & S_IFIFO )
^^^^^^^^^^^^^^^^^^^^^
You can't do this. You *must* mask the st_mode member with S_IFMT
and then test for equality with the various file types. Better yet,
use the POSIX-style S_ISxxx() macros. The piece above should be
((buf.st_mode & S_IFMT) == S_IFIFO)
For example, on SunOS "st_mode & S_IFREG" will be true for a regular file,
a sybolic link, and a socket. Take a look at <sys.stat.h>. Only 4 bits
are used to code 7 different values.
Rich Stevens
More information about the Comp.unix.programmer
mailing list