home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / sysdeps / mach / hurd / __mknod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-21  |  2.0 KB  |  72 lines

  1. /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <errno.h>
  21. #include <sys/stat.h>
  22. #include <hurd.h>
  23.  
  24. /* Create a device file named PATH, with permission and special bits MODE
  25.    and device number DEV (which can be constructed from major and minor
  26.    device numbers with the `makedev' macro above).  */
  27. int
  28. DEFUN(__mknod, (path, mode, dev),
  29.       CONST char *path AND mode_t mode AND dev_t dev)
  30. {
  31.   const char *name;
  32.   file_t node;
  33.   error_t err;
  34.   const char *translator;
  35.   size_t n;
  36.  
  37.   if (S_ISCHR (mode))
  38.     translator = _HURD_CHRDEV;
  39.   else if (S_ISBLK (mode))
  40.     translator = _HURD_BLKDEV;
  41.   else if (S_ISFIFO (mode))
  42.     translator = _HURD_FIFO;
  43.   else
  44.     {
  45.       errno = EINVAL;
  46.       return -1;
  47.     }
  48.  
  49.   node = __path_lookup (path,
  50.             FS_LOOKUP_CREATE|FS_LOOKUP_EXCL|FS_LOOKUP_WRITE,
  51.             mode & 0777,
  52.             &node);
  53.   if (node == MACH_PORT_NULL)
  54.     return -1;
  55.  
  56.   err = __file_set_translator (node,
  57.                    FS_GOAWAY_DONT,
  58.                    translator, strlen (translator) + 1,
  59.                    MACH_PORT_NULL);
  60.  
  61.   if (!err)
  62.     err = __io_write (node, &dev, sizeof (dev), &n);
  63.   if (!err && n != sizeof (dev))
  64.     err = EIO;
  65.  
  66.   if (err)
  67.     /* XXX The node still exists.... */
  68.     return __hurd_fail (err);
  69.  
  70.   return 0;
  71. }
  72.