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

Subversion Repositories or1k

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

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 <sys/syscall.h>
4
 
5
#include "../dirstream.h"
6
 
7
/*
8
 * readdir fills up the buffer with the readdir system call. it also
9
 * gives a third parameter (currently ignored, but should be 1) that
10
 * can with a future kernel be enhanced to be the number of entries
11
 * to be gotten.
12
 *
13
 * Right now the readdir system call return the number of characters
14
 * in the name - in the future it will probably return the number of
15
 * entries gotten. No matter - right now we just check for positive:
16
 * that will always work (as we know that it cannot be bigger than 1
17
 * in the future: we just asked for one entry).
18
 */
19
static struct dirent *
20
old_readdir (DIR *dir)
21
{
22
  int result;
23
  int count = NUMENT;
24
 
25
  if (dir->dd_size <= dir->dd_nextloc) {
26
    /* read count of directory entries. For now it should be one. */
27
    __asm__ ("movel %2,%/d1\n\t"
28
             "movel %3,%/d2\n\t"
29
             "movel %4,%/d3\n\t"
30
             "movel %1,%/d0\n\t"
31
             "trap  #0\n\t"
32
             "movel %/d0,%0"
33
             : "=g" (result)
34
             : "i" (SYS_readdir), "g" (dir->dd_fd), "g" (dir->dd_buf),
35
               "g" (count)
36
             : "%d0", "%d1", "%d2", "%d3" );
37
    if (result <= 0) {
38
      if (result < 0)
39
        errno = -result;
40
      return NULL;
41
    }
42
 
43
    /*
44
     * Right now the readdir system call return the number of
45
     * characters in the name - in the future it will probably return
46
     * the number of entries gotten. No matter - right now we just
47
     * check for positive:
48
     */
49
#if 0
50
    dir->dd_size = result;
51
#else
52
    dir->dd_size = 1;
53
#endif
54
 
55
    dir->dd_nextloc = 0;
56
  }
57
 
58
  return &(dir->dd_buf [(dir->dd_nextloc)++]);
59
}
60
 
61
#ifdef __ELF__
62
#pragma weak readdir = __libc_readdir
63
#endif
64
 
65
struct dirent *
66
__libc_readdir (DIR *dir)
67
{
68
  int result;
69
  struct dirent *de;
70
 
71
  if (!dir)
72
    {
73
      errno = EBADF;
74
      return NULL;
75
    }
76
 
77
  /* Are we running an old kernel? */
78
  if (dir->dd_getdents == no_getdents)
79
    return old_readdir (dir);
80
 
81
  if (dir->dd_size <= dir->dd_nextloc)
82
    {
83
      /* read dir->dd_max bytes of directory entries. */
84
      __asm__ ("movel %2,%/d1\n\t"
85
               "movel %3,%/d2\n\t"
86
               "movel %4,%/d3\n\t"
87
               "movel %1,%/d0\n\t"
88
               "trap  #0\n\t"
89
               "movel %/d0,%0"
90
               : "=g" (result)
91
               : "i" (SYS_getdents), "g" (dir->dd_fd), "g" (dir->dd_buf),
92
                 "g" (dir->dd_max)
93
               : "%d0", "%d1", "%d2", "%d3");
94
 
95
      /* We assume we have getdents (). */
96
      dir->dd_getdents = have_getdents;
97
      if (result <= 0)
98
        {
99
          result = -result;
100
          if (result > 0)
101
            {
102
              /* Are we right? */
103
              if (result == ENOSYS)
104
                {
105
                  dir->dd_getdents = no_getdents;
106
                  return old_readdir (dir);
107
                }
108
              errno = result;
109
            }
110
 
111
          return NULL;
112
        }
113
 
114
      dir->dd_size = result;
115
      dir->dd_nextloc = 0;
116
    }
117
 
118
  de = (struct dirent *) ((char *) dir->dd_buf + dir->dd_nextloc);
119
 
120
  /* Am I right? H.J. */
121
  dir->dd_nextloc += de->d_reclen;
122
 
123
  /* We have to save the next offset here. */
124
  dir->dd_nextoff = de->d_off;
125
 
126
  return de;
127
}

powered by: WebSVN 2.1.0

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