home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / xenix / sco / 2563 < prev    next >
Encoding:
Text File  |  1992-07-23  |  2.3 KB  |  91 lines

  1. Path: sparky!uunet!ahmcs!alan
  2. From: alan@ahmcs.mq.com (Alan Mintz)
  3. Newsgroups: comp.unix.xenix.sco
  4. Subject: dirent and strerror problems in SCO XENIX 2.3?
  5. Message-ID: <466@ahmcs.mq.com>
  6. Date: 24 Jul 92 06:40:31 GMT
  7. Organization: Micro-Quick Systems, Inc.
  8. Lines: 81
  9.  
  10. I have encountered a couple of oddities while building Taylor-uucp for
  11. SCO XENIX 2.3.
  12.  
  13. For some reason, in the routines that scan directories for work, the
  14. d_name field in dirent structures seems to start 2 bytes too far into
  15. the structure, chopping off the first two chars of the filename. I 
  16. have a hunch that it has to do with the d_off field being of the
  17. wrong type (off_t, which is a long, instead of short).
  18.  
  19. For example:
  20.  
  21. ************************************************
  22. #include <sys/types.h>
  23. #include <stdio.h>
  24. #include <dirent.h>
  25.  
  26. main()
  27. {
  28.  DIR *topdir;
  29.  struct dirent *entry;
  30.  int i;
  31.  
  32.  topdir=opendir((char *) ".");
  33.  
  34.  for(i=1;i<5;i++)
  35.  {
  36.   entry=readdir(topdir);
  37.   printf("Inode: %11d  Offset: %11d  RecLen: %11d  Name: %s\n",
  38.    entry->d_ino, entry->d_off, entry->d_reclen, entry->d_name);
  39.  }
  40. }
  41. ************************************************
  42.  
  43. yields chopped off filenames, whereas :
  44.  
  45. ************************************************
  46.  
  47. #include <stdio.h>
  48.  
  49. typedef struct
  50.     {
  51.     int    dd_fd;            /* file descriptor */
  52.     int    dd_loc;            /* offset in block */
  53.     int    dd_size;        /* amount of valid data */
  54.     char    *dd_buf;        /* directory block */
  55.     }    DIR;            /* stream data from opendir() */
  56.  
  57. struct dirent {
  58.     long        d_ino;        /* inode number of entry */
  59.     unsigned short    d_off;        /* offset of disk direntory entry */
  60.     unsigned short    d_reclen;    /* length of this record */
  61.     char        d_name[1];    /* name of file */
  62. };
  63.  
  64. main()
  65. {
  66.  DIR *topdir;
  67.  struct dirent *entry;
  68.  int i;
  69.  
  70.  topdir=opendir((char *) ".");
  71.  
  72.  for(i=1;i<5;i++)
  73.  {
  74.   entry=readdir(topdir);
  75.   printf("Inode: %11d  Offset: %11d  RecLen: %11d  Name: %s\n",
  76.    entry->d_ino, entry->d_off, entry->d_reclen, entry->d_name);
  77.  }
  78. }
  79. ************************************************
  80.  
  81. seems to work correctly. What gives here? Is sys/dirent.h wrong?
  82.  
  83.  
  84. Also, has anyone had trouble with the strerror macro in string.h under
  85. gcc? I get unexplainable "parse errors" when using it, yet, in looking
  86. at the output of cpp, all looks normal. What am I missing?
  87. ---
  88. < Alan H. Mintz  | alan@ahmcs.mq.com | ...!uunet!ahmcs!alan >
  89. -- 
  90. < Alan H. Mintz  | alan@ahmcs.mq.com | ...!uunet!ahmcs!alan >
  91.