home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / W2KPRK.iso / apps / posix / source / PAX / XN.C < prev   
Encoding:
C/C++ Source or Header  |  1999-11-17  |  2.0 KB  |  126 lines

  1. /*++
  2.  
  3. Copyright 1992 DataFocus Incorporated
  4.  
  5. Module Name:
  6.  
  7.     xn.c
  8.  
  9. Abstract:
  10.  
  11.     Create mknod, seekdir, and telldir for use with Windows NT POSIX.
  12.  
  13. Author:
  14.  
  15.     Christian Carey    (xn@DataFocus.COM)    28-May-1993
  16.  
  17. Notes:
  18.  
  19.     This was written for the X86 implementation. It would probably be best
  20.     to test this on other architectures as well.
  21.  
  22. Revision History:
  23.  
  24.     28-May-1993    xn@DataFocus.COM
  25.  
  26.         Initial version.
  27.  
  28. --*/
  29.  
  30. #define DIR_DEBUG 0
  31.  
  32. #if DIR_DEBUG
  33. #include <stdio.h>
  34. #endif
  35. #include <dirent.h>
  36. #include <errno.h>
  37. #include <limits.h>
  38. #include <sys/types.h>
  39. #include <sys/stat.h>
  40.  
  41. signed int mknod (const char *path, mode_t mode, dev_t dev)
  42. {
  43.     signed int status;
  44.     mode_t file_type;
  45.  
  46.     if (&dev == NULL)
  47.     {
  48.         ;
  49.     }
  50.     file_type = mode & S_IFMT;
  51.     if (file_type == S_IFIFO)
  52.     {
  53.         status = mkfifo(path, mode);
  54.     }
  55.     else if (file_type == S_IFDIR)
  56.     {
  57.         status = mkdir(path, mode);
  58.     }
  59.     else
  60.     {
  61.         status = -1;
  62.         errno = ENOSYS;
  63.     }
  64.     return status;
  65. }
  66.  
  67. void seekdir (DIR *dirp, off_t loc)
  68. {
  69.     unsigned int entries;
  70.  
  71. #if DIR_DEBUG
  72.     (void) fprintf(stderr, "xn.c/seekdir - loc: %ld\n", (signed long) loc);
  73.     (void) fflush(stderr);
  74. #endif
  75.     if (dirp == NULL)
  76.     {
  77.         errno = EFAULT;
  78.     }
  79.     else if (dirp->Directory < 0 || dirp->Directory >= OPEN_MAX)
  80.     {
  81.         errno = EBADF;
  82.     }
  83.     else if (loc < (off_t) 0)
  84.     {
  85.         errno = EINVAL;
  86.     }
  87.     else
  88.     {
  89.         rewinddir(dirp);
  90.         entries = (unsigned int) (loc/sizeof(struct dirent));
  91. #if DIR_DEBUG
  92.         (void) fprintf(stderr, "xn.c/seekdir - entries: %u\n", entries);
  93.         (void) fflush(stderr);
  94. #endif
  95.         while (entries--)
  96.         {
  97.             (void) readdir(dirp);
  98.         }
  99.     }
  100. }
  101.  
  102. off_t telldir (DIR *dirp)
  103. {
  104.     off_t status;
  105.  
  106.     if (dirp == NULL)
  107.     {
  108.         status = (off_t) -1;
  109.         errno = EFAULT;
  110.     }
  111.     else if (dirp->Directory < 0 || dirp->Directory >= OPEN_MAX)
  112.     {
  113.         status = (off_t) -1;
  114.         errno = EBADF;
  115.     }
  116.     else
  117.     {
  118.         status = (off_t) dirp->Index * sizeof(struct dirent);
  119.     }
  120. #if DIR_DEBUG
  121.     (void) fprintf(stderr, "xn.c/telldir - returning %ld\n", (signed long) status);
  122.     (void) fflush(stderr);
  123. #endif
  124.     return status;
  125. }
  126.