home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / INTERNET / UPC2S1.ZIP / CREAT.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  2KB  |  62 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    C R E A T . C                                                   */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <fcntl.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <time.h>
  17.  
  18. #ifndef __GNUC__
  19. #include <io.h>
  20. #endif
  21.  
  22. /*--------------------------------------------------------------------*/
  23. /*                    UUPC/extended include files                     */
  24. /*--------------------------------------------------------------------*/
  25.  
  26. #include "lib.h"
  27. #include "hlib.h"
  28.  
  29. /*--------------------------------------------------------------------*/
  30. /*    C R E A T                                                       */
  31. /*                                                                    */
  32. /*    Create a file with the specified mode                           */
  33. /*--------------------------------------------------------------------*/
  34.  
  35. int CREAT(const char *name, const int mode, const char ftyp)
  36. {
  37.  
  38.    char *last;
  39.    char *path;
  40.    int results;
  41.  
  42.    /* are we opening for write or append */
  43.    FILEMODE(ftyp);
  44.    results = creat(name, mode);
  45.  
  46.    if (results != -1)
  47.       return results;
  48.  
  49.    /* see if we need to make any intermediate directories */
  50.    path = normalize( name );
  51.  
  52.    if ((last = strrchr(path, '/')) != nil(char))
  53.    {
  54.       *last = '\0';
  55.       MKDIR(path);
  56.    }
  57.  
  58.    /* now try open again */
  59.    return creat(name, mode);
  60.  
  61. } /*CREAT*/
  62.