home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gnulib / libsrc98.zoo / mkdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-24  |  1.1 KB  |  51 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 <stdio.h>
  7. #include <osbind.h>
  8. #include <support.h>
  9. #include <unistd.h>
  10. #include <errno.h>
  11. #include "symdir.h"
  12. #include "lib.h"
  13.  
  14. extern int errno;
  15.  
  16. int mkdir(_path, mode)
  17. const char *_path;
  18. unsigned int mode;
  19. {
  20.     int rv, name_munged;
  21.     char path[FILENAME_MAX];
  22.  
  23. /*
  24.  * _unx2dos indicates whether the name has been modified in some way
  25.  * in its return value. In this case, we try to create an
  26.  * automatic symbolic link which gives the "real" name, which is put
  27.  * in the global variable __link_name[].
  28.  */
  29.     name_munged = (_unx2dos(_path, path) == _NM_CHANGE);
  30.  
  31.     rv = Fattrib(path, 0, 0);    /* Get file attributes */
  32.     if (rv >= 0) {            /* Does it exist ? */
  33.         errno = EEXIST;        /* Yes, so tell user. */
  34.         return -1;
  35.     }
  36.  
  37.     if (rv != -ENOENT) {        /* Return stat error, if other than */
  38.         errno = -rv;        /* File not found. */
  39.         return -1;
  40.     }
  41.  
  42.     rv = Dcreate(path);
  43.     if (rv < 0) {
  44.         errno = -rv;
  45.         return -1;
  46.     }
  47.     if (name_munged)
  48.         _make_autolink(path, __link_name);
  49.     return 0;
  50. }
  51.