The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dirent.h File Reference
#include <defs.h>
+ Include dependency graph for dirent.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dirent
 

Typedefs

typedef struct DIR DIR
 

Functions

SWDLLEXPORT int closedir (DIR *)
 
SWDLLEXPORT DIRopendir (const char *)
 
SWDLLEXPORT struct direntreaddir (DIR *)
 
SWDLLEXPORT void rewinddir (DIR *)
 

Typedef Documentation

typedef struct DIR DIR

Definition at line 22 of file dirent.h.

Function Documentation

SWDLLEXPORT int closedir ( DIR )

Definition at line 76 of file dirent.cpp.

77 {
78  int result = -1;
79 
80  if(dir)
81  {
82  if(dir->handle != -1)
83  {
84  result = _findclose(dir->handle);
85  }
86 
87  free(dir->name);
88  free(dir);
89  }
90 
91  if(result == -1) /* map all errors to EBADF */
92  {
93  errno = EBADF;
94  }
95 
96  return result;
97 }
free(preg->fastmap)
result
Definition: regex.c:5545
SWDLLEXPORT DIR* opendir ( const char *  )

Definition at line 35 of file dirent.cpp.

36 {
37  DIR *dir = 0;
38 
39  if(name && name[0])
40  {
41  size_t base_length = strlen(name);
42  const char *all = /* the root directory is a special case... */
43  strchr("/\\", name[base_length - 1]) ? "*" : "/*";
44 
45  if((dir = (DIR *) malloc(sizeof *dir)) != 0 &&
46  (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0)
47  {
48  strcat(strcpy(dir->name, name), all);
49 
50  if((dir->handle = _findfirst(dir->name, &dir->info)) != -1)
51  {
52  dir->result.d_name = 0;
53  }
54  else /* rollback */
55  {
56  free(dir->name);
57  free(dir);
58  dir = 0;
59  }
60  }
61  else /* rollback */
62  {
63  free(dir);
64  dir = 0;
65  errno = ENOMEM;
66  }
67  }
68  else
69  {
70  errno = EINVAL;
71  }
72 
73  return dir;
74 }
long handle
Definition: dirent.cpp:29
struct dirent result
Definition: dirent.cpp:31
struct _finddata_t info
Definition: dirent.cpp:30
Definition: dirent.cpp:27
char * malloc()
free(preg->fastmap)
char * d_name
Definition: dirent.h:26
char * name
Definition: dirent.cpp:32
SWDLLEXPORT struct dirent* readdir ( DIR )

Definition at line 99 of file dirent.cpp.

100 {
101  struct dirent *result = 0;
102 
103  if(dir && dir->handle != -1)
104  {
105  if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1)
106  {
107  result = &dir->result;
108  result->d_name = dir->info.name;
109  }
110  }
111  else
112  {
113  errno = EBADF;
114  }
115 
116  return result;
117 }
Definition: dirent.h:24
char * d_name
Definition: dirent.h:26
result
Definition: regex.c:5545
SWDLLEXPORT void rewinddir ( DIR )

Definition at line 119 of file dirent.cpp.

120 {
121  if(dir && dir->handle != -1)
122  {
123  _findclose(dir->handle);
124  dir->handle = _findfirst(dir->name, &dir->info);
125  dir->result.d_name = 0;
126  }
127  else
128  {
129  errno = EBADF;
130  }
131 }