home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / compat / sys / stat / mknod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  710 b   |  39 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <sys/stat.h>
  4. #include <errno.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7.  
  8. /* ARGSUSED */
  9. int
  10. mknod(const char *path, mode_t mode, dev_t dev)
  11. {
  12.   if (S_ISREG(mode))
  13.   {
  14.     int e  = errno;
  15.     int fd = open(path, O_CREAT | O_EXCL, S_IWUSR);
  16.  
  17.     if (fd == -1)
  18.       return fd;
  19.     close(fd);
  20.     errno = e;
  21.     return 0;
  22.   }
  23.   else if (S_ISCHR(mode))
  24.   {
  25.     struct stat statbuf;
  26.  
  27.     if (stat(path, &statbuf) == 0 &&
  28.         S_ISCHR(statbuf.st_mode)  &&
  29.         statbuf.st_dev == dev)
  30.     {
  31.       errno = EEXIST;
  32.       return -1;
  33.     }
  34.   }
  35.  
  36.   errno = EACCES;
  37.   return -1;
  38. }
  39.