Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

fileops.c

Go to the documentation of this file.
00001 /*
00002   fileops.c
00003 
00004   File operations: is it a file, directory, link, etc.
00005 
00006   Modification history:
00007 
00008   17-Mar-2000  FMP created, to solve problem where fopen() was passed a
00009   directory, and it succeeded, but we really wanted success only if it
00010   was a real, useful file.
00011 */
00012 
00013 #if defined (LINUX) || defined (SUN)
00014 
00015 #include "fileops.h"            /* these decls */
00016 #include <sys/types.h>
00017 #include <sys/stat.h>
00018 
00019 int
00020 rcs_fileop_isfile (const char *path)
00021 {
00022   struct stat buf;
00023 
00024   /* use stat here, so link to regular file will be considered a file */
00025   if (stat (path, &buf) < 0)
00026     {
00027       return 0;
00028     }
00029 
00030   if (S_ISREG (buf.st_mode))
00031     {
00032       return 1;
00033     }
00034 
00035   return 0;
00036 }
00037 
00038 int
00039 rcs_fileop_isdir (const char *path)
00040 {
00041   struct stat buf;
00042 
00043   /* use stat here, so link to directory will be considered a directory */
00044   if (stat (path, &buf) < 0)
00045     {
00046       return 0;
00047     }
00048 
00049   if (S_ISDIR (buf.st_mode))
00050     {
00051       return 1;
00052     }
00053 
00054   return 0;
00055 }
00056 
00057 int
00058 rcs_fileop_islink (const char *path)
00059 {
00060   struct stat buf;
00061 
00062   /* use lstat here, so link to anything will be considered a link */
00063   if (lstat (path, &buf) < 0)
00064     {
00065       return 0;
00066     }
00067 
00068   if (S_ISLNK (buf.st_mode))
00069     {
00070       return 1;
00071     }
00072 
00073   return 0;
00074 }
00075 
00076 #endif /* LINUX, SUN */
00077 
00078 
00079 #if defined (WIN32)
00080 
00081 #include "fileops.h"            /* these decls */
00082 
00083 /* FIXME-- for this plat, 'path' is always considered a file */
00084 
00085 int
00086 rcs_fileop_isfile (const char *path)
00087 {
00088   return 1;
00089 }
00090 
00091 int
00092 rcs_fileop_isdir (const char *path)
00093 {
00094   return 0;
00095 }
00096 
00097 int
00098 rcs_fileop_islink (const char *path)
00099 {
00100   return 0;
00101 }
00102 
00103 #endif /* WIN32 */

Generated on Sun Dec 2 15:56:49 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001