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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [sys/] [go32/] [dir.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 1010 ivang
#include <string.h>
2
 
3
#include "sys/dir.h"
4
#include "sys/dirent.h"
5
#include <errno.h>
6
 
7
DIR *opendir(char *name)
8
{
9
  int length;
10
  DIR *dir = (DIR *)malloc(sizeof(DIR));
11
  dir->num_read = 0;
12
  dir->name = (char *)malloc(strlen(name)+6);
13
  strcpy(dir->name, name);
14
 
15
  /* Append a "." if we got only the device name */
16
  if (dir->name[1] == ':' && strlen(dir->name) == 2)
17
      strcat(dir->name, ".");
18
 
19
  /* Strip trailing slashes, so we can append "/*.*" */
20
  while (1)
21
  {
22
      length = strlen(dir->name);
23
      if (length == 0) break;
24
      if (dir->name[length - 1] == '/' ||
25
          dir->name[length - 1] == '\\')
26
          dir->name[length - 1] = '\0';
27
      else
28
          break;
29
  }
30
 
31
  strcat(dir->name, "/*.*");
32
  return dir;
33
}
34
 
35
 
36
 
37
static char *strlwr(char *s)
38
{
39
  char *p = s;
40
  while (*s)
41
  {
42
    if ((*s >= 'A') && (*s <= 'Z'))
43
      *s += 'a'-'A';
44
    s++;
45
  }
46
  return p;
47
}
48
 
49
struct dirent *readdir(DIR *dir)
50
{
51
  int done;
52
  int oerrno = errno;
53
  if (dir->num_read)
54
    done = findnext(&dir->ff);
55
  else
56
    done = findfirst(dir->name, &dir->ff,
57
                     FA_ARCH|FA_RDONLY|FA_DIREC|FA_HIDDEN|FA_SYSTEM);
58
  if (done)
59
  {
60
    if (errno == ENMFILE)
61
      errno = oerrno;
62
    return 0;
63
  }
64
  dir->num_read ++;
65
  dir->de.d_namlen = strlen(dir->ff.ff_name);
66
  strcpy(dir->de.d_name,dir->ff.ff_name);
67
  strlwr(dir->de.d_name);
68
  return &dir->de;
69
}
70
 
71
long telldir(DIR *dir)
72
{
73
  return dir->num_read;
74
}
75
 
76
void seekdir(DIR *dir, long loc)
77
{
78
  int i;
79
  rewinddir(dir);
80
  for (i=0; i<loc; i++)
81
    readdir(dir);
82
}
83
 
84
void rewinddir(DIR *dir)
85
{
86
  dir->num_read = 0;
87
}
88
 
89
int closedir(DIR *dir)
90
{
91
  free(dir->name);
92
  free(dir);
93
  return 0;
94
}
95
 

powered by: WebSVN 2.1.0

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