home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / LIBC / LIBC-4.6 / LIBC-4 / libc-linux / sysdeps / linux / m68k / readdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-24  |  1.8 KB  |  72 lines

  1. #include <dirent.h>
  2. #include <errno.h>
  3. #include <sys/syscall.h>
  4.  
  5. /*
  6.  * readdir fills up the buffer with the readdir system call. it also
  7.  * gives a third parameter (currently ignored, but should be 1) that
  8.  * can with a future kernel be enhanced to be the number of entries
  9.  * to be gotten.
  10.  *
  11.  * Right now the readdir system call return the number of characters
  12.  * in the name - in the future it will probably return the number of
  13.  * entries gotten. No matter - right now we just check for positive:
  14.  * that will always work (as we know that it cannot be bigger than 1
  15.  * in the future: we just asked for one entry).
  16.  */
  17. struct dirent *readdir(DIR * dir)
  18. {
  19.   int result;
  20.   int count = NUMENT;
  21.  
  22.   if (!dir) {
  23.     errno = EBADF;
  24.     return NULL;
  25.   }
  26.  
  27.   if (dir->dd_size <= dir->dd_loc) {
  28.     /* read count of directory entries. For now it should be one. */
  29. #if defined(__PIC__) || defined (__pic__)
  30.     __asm__ volatile ("pushl %%ebx\n\t"
  31.               "movl %%esi,%%ebx\n\t"
  32.               "int $0x80\n\t"
  33.               "popl %%ebx"
  34.     :"=a" (result)
  35.     :"0" (SYS_readdir),"S" (dir->dd_fd),
  36.     "c" ((long) dir->dd_buf),"d" (count));
  37. #else
  38.     __asm__ ("movel %2,d1\n\t"
  39.          "movel %3,d2\n\t"
  40.          "movel %4,d3\n\t"
  41.          "movel %1,d0\n\t"
  42.          "trap  #0\n\t"
  43.          "movel d0,%0"
  44.          : "=g" (result)
  45.          : "i" (SYS_readdir), "g" (dir->dd_fd), "g" (dir->dd_buf),
  46.            "g" (count)
  47.          : "d0", "d1", "d2", "d3" );
  48. #endif
  49.     if (result <= 0) {
  50.       if (result < 0)
  51.     errno = -result;
  52.       return NULL;
  53.     }
  54.  
  55.     /*
  56.      * Right now the readdir system call return the number of
  57.      * characters in the name - in the future it will probably return
  58.      * the number of entries gotten. No matter - right now we just
  59.      * check for positive:
  60.      */
  61. #if 0
  62.     dir->dd_size = result;
  63. #else
  64.     dir->dd_size = 1;
  65. #endif
  66.  
  67.     dir->dd_loc = 0;
  68.   }
  69.  
  70.   return &(dir->dd_buf [(dir->dd_loc)++]);
  71. }
  72.