COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
dirent.h File Reference
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

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

Typedef Documentation

typedef struct DIR DIR

Function Documentation

DIR* opendir ( const char *  )
33 {
34  DIR *dir = 0;
35 
36  if(name && name[0])
37  {
38  size_t base_length = strlen(name);
39  const char *all = /* search pattern must end with suitable wildcard */
40  strchr("/\\", name[base_length - 1]) ? "*" : "/*";
41 
42  if((dir = (DIR *) malloc(sizeof *dir)) != 0 &&
43  (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0)
44  {
45  strcat(strcpy(dir->name, name), all);
46 
47  if((dir->handle =
48  (handle_type) _findfirst(dir->name, &dir->info)) != -1)
49  {
50  dir->result.d_name = 0;
51  }
52  else /* rollback */
53  {
54  free(dir->name);
55  free(dir);
56  dir = 0;
57  }
58  }
59  else /* rollback */
60  {
61  free(dir);
62  dir = 0;
63  errno = ENOMEM;
64  }
65  }
66  else
67  {
68  errno = EINVAL;
69  }
70 
71  return dir;
72 }
handle_type handle
Definition: dirent.c:26
Definition: dirent.c:24
local const int base_length[LENGTH_CODES]
Definition: trees.h:118
char * d_name
Definition: dirent.h:23
char * name
Definition: dirent.c:29
string name
Definition: cubesat2obj.cpp:6
ptrdiff_t handle_type
Definition: dirent.c:22
struct dirent result
Definition: dirent.c:28
struct _finddata_t info
Definition: dirent.c:27
int closedir ( DIR )
75 {
76  int result = -1;
77 
78  if(dir)
79  {
80  if(dir->handle != -1)
81  {
82  result = _findclose(dir->handle);
83  }
84 
85  free(dir->name);
86  free(dir);
87  }
88 
89  if(result == -1) /* map all errors to EBADF */
90  {
91  errno = EBADF;
92  }
93 
94  return result;
95 }
struct dirent* readdir ( DIR )
98 {
99  struct dirent *result = 0;
100 
101  if(dir && dir->handle != -1)
102  {
103  if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1)
104  {
105  result = &dir->result;
106  result->d_name = dir->info.name;
107  }
108  }
109  else
110  {
111  errno = EBADF;
112  }
113 
114  return result;
115 }
Definition: dirent.h:21
char * d_name
Definition: dirent.h:23
void rewinddir ( DIR )
118 {
119  if(dir && dir->handle != -1)
120  {
121  _findclose(dir->handle);
122  dir->handle = (handle_type) _findfirst(dir->name, &dir->info);
123  dir->result.d_name = 0;
124  }
125  else
126  {
127  errno = EBADF;
128  }
129 }
ptrdiff_t handle_type
Definition: dirent.c:22