OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [sysdeps/] [readdir.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#include <dirent.h>
2
#include <errno.h>
3
#include <syscall.h>
4
 
5
#include "dirstream.h"
6
 
7
static inline
8
_syscall3(int, getdents, int, __fildes, struct dirent *, __buf, size_t, __nbyte);
9
 
10
struct dirent *
11
readdir (DIR *dir)
12
{
13
  int result;
14
  struct dirent *de;
15
 
16
  if (!dir)
17
    {
18
      errno = EBADF;
19
      return NULL;
20
    }
21
 
22
  if (dir->dd_size <= dir->dd_nextloc)
23
    {
24
      /* read dir->dd_max bytes of directory entries. */
25
      result = getdents(dir->dd_fd, dir->dd_buf, dir->dd_max);
26
/*      __asm__ ("movel %2,%/d1\n\t"
27
               "movel %3,%/d2\n\t"
28
               "movel %4,%/d3\n\t"
29
               "movel %1,%/d0\n\t"
30
               "trap  #0\n\t"
31
               "movel %/d0,%0"
32
               : "=g" (result)
33
               : "i" (SYS_getdents), "g" (dir->dd_fd), "g" (dir->dd_buf),
34
                 "g" (dir->dd_max)
35
               : "%d0", "%d1", "%d2", "%d3");
36
*/
37
      /* We must have getdents (). */
38
      dir->dd_getdents = have_getdents;
39
      if (result <= 0)
40
        {
41
          errno = -result;
42
          return NULL;
43
        }
44
 
45
      dir->dd_size = result;
46
      dir->dd_nextloc = 0;
47
    }
48
 
49
  de = (struct dirent *) ((char *) dir->dd_buf + dir->dd_nextloc);
50
 
51
  /* Am I right? H.J. */
52
  dir->dd_nextloc += de->d_reclen;
53
 
54
  /* We have to save the next offset here. */
55
  dir->dd_nextoff = de->d_off;
56
 
57
  return de;
58
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.