Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!paperboy!think.com!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!asuvax!noao!rstevens From: rstevens@noao.edu (Rich Stevens) Newsgroups: comp.unix.programmer Subject: Re: ls & file pipes (FIFO), curses... Summary: you have to mask st_mode to test file type Message-ID: <1991Feb20.224434.24579@noao.edu> Date: 20 Feb 91 22:44:34 GMT References: <471@bria> Organization: National Optical Astronomy Observatories, Tucson AZ Lines: 19 In article <471@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 . Only 4 bits are used to code 7 different values. Rich Stevens