/* isfile.c -- Copyright 1989, 1994, 1995 Liam R. Quin. * All Rights Reserved. * This code is NOT in the public domain. * See the file COPYRIGHT for full details. */ /* $Id: isfile.c,v 1.4 1996/08/14 16:57:25 lee Exp $ */ #include "globals.h" #include "error.h" #include #include #include #include "lqutil.h" #include "lqtrace.h" /* * LQU_IsFile * Utilities/Files * *

Determines whether the given Path refers to a regular file. * Devices (such as /dev/null or a terminal), and directories in * particular are not regular files. The Unix command

*

find filename -type f -print

*

will print out filename if and only if LQU_IsFile would * return 1 for the same filename. * * *

  • 1 if the given Path represents a regular file
  • *
  • zero otherwise
  • * * *

    There is tracing in here so that you can see which files are being * investigated by the calling program; tracing is available if * the liblqutil library was compiled with -DASCIITRACE; if so, you * can set the FindFile trace flag (LQTRACE_FINDFILE) to see tracing for * this routine. * The -t "FindFile|Verbose" command-line option will do this.

    *

    On systems that have the trace, strace or truss utility, * investigate using that instead.

    *
    *
    */ API int LQU_IsFile(Path) CONST char *Path; { struct stat statbuf; if (stat(Path, &statbuf) < 0) { #ifdef ASCIITRACE if (LQT_TraceFlagsSet(LQTRACE_FINDFILE)) { Error(E_WARN|E_SYS, "LQU_IsFile couldn't get file information (stat) for \"%s\"", Path ); } #endif return 0; } if ((statbuf.st_mode & S_IFMT) != S_IFREG) { #ifdef ASCIITRACE LQT_Trace(LQTRACE_FINDFILE, "LQU_IsFile(%s) -> false", Path ); #endif return 0; } #ifdef ASCIITRACE LQT_Trace(LQTRACE_FINDFILE, "LQU_IsFile(%s) -> true", Path ); #endif return 1; }