MCPcopy Create free account
hub / github.com/apache/singa / tinydir_open

Function tinydir_open

include/singa/utils/tinydir.h:126–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124/* definitions*/
125
126_TINYDIR_FUNC
127int tinydir_open(tinydir_dir *dir, const char *path) {
128 if (dir == NULL || path == NULL || strlen(path) == 0) {
129 errno = EINVAL;
130 return -1;
131 }
132 if (strlen(path) + _TINYDIR_PATH_EXTRA >= _TINYDIR_PATH_MAX) {
133 errno = ENAMETOOLONG;
134 return -1;
135 }
136
137 /* initialise dir */
138 dir->_files = NULL;
139#ifdef _WIN32
140 dir->_h = INVALID_HANDLE_VALUE;
141#else
142 dir->_d = NULL;
143#endif
144 tinydir_close(dir);
145
146 strcpy(dir->path, path);
147#ifdef _WIN32
148 strcat(dir->path, "\\*");
149 dir->_h = FindFirstFileA(dir->path, &dir->_f);
150 dir->path[strlen(dir->path) - 2] = '\0';
151 if (dir->_h == INVALID_HANDLE_VALUE)
152#else
153 dir->_d = opendir(path);
154 if (dir->_d == NULL)
155#endif
156 {
157 errno = ENOENT;
158 goto bail;
159 }
160
161 /* read first file */
162 dir->has_next = 1;
163#ifndef _WIN32
164 dir->_e = readdir(dir->_d);
165 if (dir->_e == NULL) {
166 dir->has_next = 0;
167 }
168#endif
169
170 return 0;
171
172bail:
173 tinydir_close(dir);
174 return -1;
175}
176
177_TINYDIR_FUNC
178int tinydir_open_sorted(tinydir_dir *dir, const char *path) {

Callers 2

tinydir_open_sortedFunction · 0.85
tinydir_file_openFunction · 0.85

Calls 1

tinydir_closeFunction · 0.85

Tested by

no test coverage detected