mike (02/21/91)
In an article, coombs.anu.edu.au!avalon (avalon) writes: >G'day, can anyone tell me how 'ls' knows whether a >file is a regular file or a pipe ? > >When i do a stat(2) call on the file, it is returned >as a regular file. What tricks does ls perform ? 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 ) printf("%s is a pipe\n",file); Cheers, -- Michael Stefanik, MGI Inc., Los Angeles| Opinions stated are not even my own. Title of the week: Systems Engineer | UUCP: ...!uunet!bria!mike ------------------------------------------------------------------------------- Remember folks: If you can't flame MS-DOS, then what _can_ you flame?
art@pilikia.pegasus.com (Art Neilson) (02/21/91)
In article <avalon.666979740@coombs> avalon@coombs.anu.edu.au (avalon) writes: >G'day, can anyone tell me how 'ls' knows whether a >file is a regular file or a pipe ? > >When i do a stat(2) call on the file, it is returned >as a regular file. What tricks does ls perform ? Here's an example of testing if a file is a pipe or not: if (stat(pathname, &st) == -1) { perror("stat"); exit(1); } if ((st.st_mode & S_IFMT) == S_IFIFO) printf("%s is a fifo\n", pathname); -- Arthur W. Neilson III | INET: art@pilikia.pegasus.com Bank of Hawaii Tech Support | UUCP: uunet!ucsd!nosc!pegasus!pilikia!art