home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / mkdir.c < prev    next >
C/C++ Source or Header  |  1992-02-12  |  894b  |  46 lines

  1. /* mkdir: make a new directory
  2.  * written by Eric R. Smith and placed in the public domain
  3.  * modified by Alan Hourihane, to check for directory and return EEXIST.
  4.  */
  5.  
  6. #include <errno.h>
  7. #include <limits.h>
  8. #include <osbind.h>
  9. #include <mintbind.h>
  10. #include <stat.h>
  11. #include "lib.h"
  12.  
  13. extern int errno;
  14. extern int __mint;
  15.  
  16. int mkdir(_path, mode)
  17.     const char *_path;
  18.     unsigned mode;
  19. {
  20.     struct stat statbuf;
  21.     int rv;
  22.     char path[PATH_MAX];
  23.  
  24.     _unx2dos(_path, path);
  25.  
  26.     rv = stat(path, &statbuf);    /* Stat directory */
  27.     if (rv == 0) {            /* Does it exist ? */
  28.         errno = EEXIST;        /* Yes, so tell user. */
  29.         return -1;
  30.     }
  31.  
  32.     if (errno != ENOENT) {        /* Return stat error, if other than */
  33.         return -1;        /* File not found. */
  34.     }
  35.  
  36.     rv = Dcreate(path);
  37.     if (rv < 0) {
  38.         errno = -rv;
  39.         return -1;
  40.     }
  41.     if (__mint >= 9) {
  42.         (void)Fchmod(path, mode);
  43.     }
  44.     return 0;
  45. }
  46.