00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 static const char RCS_stat[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbu/stat.c,v 14.8 2006/08/31 23:16:39 lbutler Exp $";
00037
00038 #include "common.h"
00039
00040 #include <stdio.h>
00041
00042 #ifdef HAVE_UNISTD_H
00043 # include <unistd.h>
00044 #endif
00045 #ifdef HAVE_SYS_STAT_H
00046 # include <sys/stat.h>
00047 #endif
00048
00049 #include "machine.h"
00050 #include "bu.h"
00051
00052
00053
00054
00055
00056
00057
00058
00059 int
00060 bu_file_exists(const char *path)
00061 {
00062 struct stat sbuf;
00063
00064 if (bu_debug) {
00065 printf("Does %s exist? ", path);
00066 }
00067
00068 if( path == NULL ) return 0;
00069
00070
00071 #if defined(HAVE_ACCESS) && defined(F_OK)
00072 # define bu_file_exists_method 1
00073 if( access( path, F_OK ) == 0 ) {
00074 if (bu_debug) {
00075 printf("YES\n");
00076 }
00077 return 1;
00078 }
00079 #endif
00080
00081
00082 #if defined(HAVE_STAT)
00083 # define bu_file_exists_method 1
00084 if( stat( path, &sbuf ) == 0 ) {
00085 if (bu_debug) {
00086 printf("YES\n");
00087 }
00088 return 1;
00089 }
00090 #endif
00091
00092 #ifndef bu_file_exists_method
00093 # error "Do not know how to check whether a file exists on this system"
00094 #endif
00095
00096 if (bu_debug) {
00097 printf("NO\n");
00098 }
00099 return 0;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110