diff --git a/checkin_notes b/checkin_notes index 719ddfb323..ec7a69514b 100755 --- a/checkin_notes +++ b/checkin_notes @@ -17216,3 +17216,10 @@ David 9 Sept 2004 sample_trivial_validator.C validate_util.C,h validator.C + +David 9 Sept 2004 + - added try_fopen() (from Jeff Cobb): + like fopen(), but on tells you whether it's recoverable or not + + lib/ + util.C,h diff --git a/lib/util.C b/lib/util.C index 5dd24a28a1..7075969310 100755 --- a/lib/util.C +++ b/lib/util.C @@ -765,3 +765,34 @@ int dir_hier_url( sprintf(result, "%s/%x/%s", root, sum, filename); return 0; } + +// try to open a file. +// On failure: +// return ERR_FOPEN if the dir is there but not file +// (this is generally a nonrecoverable failure) +// return ERR_OPENDIR if dir is not there. +// (this is generally a recoverable error, +// like NFS mount failure, that may go away later) +// +int try_fopen(char* path, FILE*& f, char* mode) { + char* p; + DIR* d; + char dirpath[256]; + + f = fopen(path, mode); + if (!f) { + p = strrchr(path, '/'); + if (p) { + strncpy(dirpath, path, (int)(p-path)); + } else { + strcpy(dirpath, "."); + } + if ((d = opendir(dirpath)) == NULL) { + return ERR_OPENDIR; + } else { + closedir(d); + return ERR_FOPEN; + } + } + return 0; +} diff --git a/lib/util.h b/lib/util.h index 1628e83839..87f534299e 100755 --- a/lib/util.h +++ b/lib/util.h @@ -127,4 +127,6 @@ extern int dir_hier_url( const char* filename, const char* root, int fanout, char* result ); +extern int try_fopen(char* path, FILE*& f, char* mode); + #endif diff --git a/sched/assimilator.C b/sched/assimilator.C index 11cbced5a4..079883dc10 100644 --- a/sched/assimilator.C +++ b/sched/assimilator.C @@ -17,7 +17,10 @@ // Contributor(s): // -// assimilator [ -noinsert ] +// This is a framework for an assimilator. +// You need to link with with an (application-specific) function +// assimilate_handler() +// in order to make a complete program. // #include