home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------*/
- /* f o p e n . c */
- /* */
- /* Support routines for UUPC/extended */
- /* */
- /* Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire */
- /* */
- /* History: */
- /* 21Nov1991 Break out of lib.c ahd */
- /*--------------------------------------------------------------------*/
-
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
-
- /*--------------------------------------------------------------------*/
- /* UUPC/extended include files */
- /*--------------------------------------------------------------------*/
-
- #include "lib.h"
- #include "hlib.h"
-
- /*--------------------------------------------------------------------*/
- /* F O P E N */
- /* */
- /* Like fopen() but create imtermediate directories */
- /* */
- /* This routine has dependency on the path separator characters */
- /* being '/', we should relove that somehow someday. */
- /*--------------------------------------------------------------------*/
-
- FILE *FOPEN(const char *name, const char *mode, const char ftype)
- {
-
- char *last;
- FILE *results;
-
- /* are we opening for write or append */
- FILEMODE(ftype);
- results = fopen(name, mode);
-
- if ((results != nil(FILE)) || (*mode == 'r'))
- return results;
-
- /* verify all intermediate directories in the path exist */
- if ((last = strrchr(name, '/')) != nil(char)) {
- *last = '\0';
- MKDIR(name);
- *last = '/';
- }
-
- /* now try open again */
- return fopen(name, mode);
-
- } /*FOPEN*/
-