• Home
  • Raw
  • Download

Lines Matching full:dir

159 #define _TINYDIR_DIR DIR
219 int tinydir_open(tinydir_dir *dir, const _tinydir_char_t *path);
221 int tinydir_open_sorted(tinydir_dir *dir, const _tinydir_char_t *path);
223 void tinydir_close(tinydir_dir *dir);
226 int tinydir_next(tinydir_dir *dir);
228 int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file);
230 int tinydir_readfile_n(const tinydir_dir *dir, tinydir_file *file, size_t i);
232 int tinydir_open_subdir_n(tinydir_dir *dir, size_t i);
251 int tinydir_open(tinydir_dir *dir, const _tinydir_char_t *path) in tinydir_open() argument
263 if (dir == NULL || path == NULL || _tinydir_strlen(path) == 0) in tinydir_open()
274 /* initialise dir */ in tinydir_open()
275 dir->_files = NULL; in tinydir_open()
277 dir->_h = INVALID_HANDLE_VALUE; in tinydir_open()
279 dir->_d = NULL; in tinydir_open()
281 dir->_ep = NULL; in tinydir_open()
284 tinydir_close(dir); in tinydir_open()
286 _tinydir_strcpy(dir->path, path); in tinydir_open()
288 pathp = &dir->path[_tinydir_strlen(dir->path) - 1]; in tinydir_open()
289 while (pathp != dir->path && (*pathp == TINYDIR_STRING('\\') || *pathp == TINYDIR_STRING('/'))) in tinydir_open()
295 _tinydir_strcpy(path_buf, dir->path); in tinydir_open()
298 dir->_h = FindFirstFileEx(path_buf, FindExInfoStandard, &dir->_f, FindExSearchNameMatch, NULL, 0); in tinydir_open()
300 dir->_h = FindFirstFile(path_buf, &dir->_f); in tinydir_open()
302 if (dir->_h == INVALID_HANDLE_VALUE) in tinydir_open()
306 dir->_d = _tinydir_opendir(path); in tinydir_open()
307 if (dir->_d == NULL) in tinydir_open()
314 dir->has_next = 1; in tinydir_open()
317 dir->_e = _tinydir_readdir(dir->_d); in tinydir_open()
320 size = _tinydir_dirent_buf_size(dir->_d); /* conversion to int */ in tinydir_open()
322 dir->_ep = (struct _tinydir_dirent*)_TINYDIR_MALLOC(size); in tinydir_open()
323 if (dir->_ep == NULL) return -1; in tinydir_open()
325 error = readdir_r(dir->_d, dir->_ep, &dir->_e); in tinydir_open()
328 if (dir->_e == NULL) in tinydir_open()
330 dir->has_next = 0; in tinydir_open()
337 tinydir_close(dir); in tinydir_open()
342 int tinydir_open_sorted(tinydir_dir *dir, const _tinydir_char_t *path) in tinydir_open() argument
346 if (tinydir_open(dir, path) == -1) in tinydir_open()
350 while (dir->has_next) in tinydir_open()
353 if (tinydir_next(dir) == -1) in tinydir_open()
358 tinydir_close(dir); in tinydir_open()
360 if (tinydir_open(dir, path) == -1) in tinydir_open()
365 dir->n_files = 0; in tinydir_open()
366 dir->_files = (tinydir_file *)_TINYDIR_MALLOC(sizeof *dir->_files * n_files); in tinydir_open()
367 if (dir->_files == NULL) in tinydir_open()
371 while (dir->has_next) in tinydir_open()
374 dir->n_files++; in tinydir_open()
376 p_file = &dir->_files[dir->n_files - 1]; in tinydir_open()
377 if (tinydir_readfile(dir, p_file) == -1) in tinydir_open()
382 if (tinydir_next(dir) == -1) in tinydir_open()
389 if (dir->n_files == n_files) in tinydir_open()
395 qsort(dir->_files, dir->n_files, sizeof(tinydir_file), _tinydir_file_cmp); in tinydir_open()
400 tinydir_close(dir); in tinydir_open()
405 void tinydir_close(tinydir_dir *dir) in tinydir_open() argument
407 if (dir == NULL) in tinydir_open()
412 memset(dir->path, 0, sizeof(dir->path)); in tinydir_open()
413 dir->has_next = 0; in tinydir_open()
414 dir->n_files = 0; in tinydir_open()
415 _TINYDIR_FREE(dir->_files); in tinydir_open()
416 dir->_files = NULL; in tinydir_open()
418 if (dir->_h != INVALID_HANDLE_VALUE) in tinydir_open()
420 FindClose(dir->_h); in tinydir_open()
422 dir->_h = INVALID_HANDLE_VALUE; in tinydir_open()
424 if (dir->_d) in tinydir_open()
426 _tinydir_closedir(dir->_d); in tinydir_open()
428 dir->_d = NULL; in tinydir_open()
429 dir->_e = NULL; in tinydir_open()
431 _TINYDIR_FREE(dir->_ep); in tinydir_open()
432 dir->_ep = NULL; in tinydir_open()
438 int tinydir_next(tinydir_dir *dir) in tinydir_open() argument
440 if (dir == NULL) in tinydir_open()
445 if (!dir->has_next) in tinydir_open()
452 if (FindNextFile(dir->_h, &dir->_f) == 0) in tinydir_open()
455 dir->_e = _tinydir_readdir(dir->_d); in tinydir_open()
457 if (dir->_ep == NULL) in tinydir_open()
461 if (readdir_r(dir->_d, dir->_ep, &dir->_e) != 0) in tinydir_open()
466 if (dir->_e == NULL) in tinydir_open()
469 dir->has_next = 0; in tinydir_open()
474 tinydir_close(dir); in tinydir_open()
485 int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file) in tinydir_open() argument
487 if (dir == NULL || file == NULL) in tinydir_open()
493 if (dir->_h == INVALID_HANDLE_VALUE) in tinydir_open()
495 if (dir->_e == NULL) in tinydir_open()
501 if (_tinydir_strlen(dir->path) + in tinydir_open()
504 dir->_f.cFileName in tinydir_open()
506 dir->_e->d_name in tinydir_open()
517 dir->_f.cFileName in tinydir_open()
519 dir->_e->d_name in tinydir_open()
527 _tinydir_strcpy(file->path, dir->path); in tinydir_open()
531 dir->_f.cFileName in tinydir_open()
533 dir->_e->d_name in tinydir_open()
552 !!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); in tinydir_open()
558 !!(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || in tinydir_open()
560 !(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) && in tinydir_open()
561 !(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && in tinydir_open()
562 !(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED) && in tinydir_open()
564 !(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_INTEGRITY_STREAM) && in tinydir_open()
567 !(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_NO_SCRUB_DATA) && in tinydir_open()
569 !(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) && in tinydir_open()
570 !(dir->_f.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)); in tinydir_open()
579 int tinydir_readfile_n(const tinydir_dir *dir, tinydir_file *file, size_t i) in tinydir_open() argument
581 if (dir == NULL || file == NULL) in tinydir_open()
586 if (i >= dir->n_files) in tinydir_open()
592 memcpy(file, &dir->_files[i], sizeof(tinydir_file)); in tinydir_open()
599 int tinydir_open_subdir_n(tinydir_dir *dir, size_t i) in tinydir_open() argument
602 if (dir == NULL) in tinydir_open()
607 if (i >= dir->n_files || !dir->_files[i].is_dir) in tinydir_open()
613 _tinydir_strcpy(path, dir->_files[i].path); in tinydir_open()
614 tinydir_close(dir); in tinydir_open()
615 if (tinydir_open_sorted(dir, path) == -1) in tinydir_open()
627 tinydir_dir dir; in tinydir_open() local
681 /* Emulate the behavior of dirname by returning "." for dir name if it's in tinydir_open()
687 /* Concatenate the drive letter and dir name to form full dir name */ in tinydir_open()
701 if (tinydir_open(&dir, dir_name) == -1) in tinydir_open()
707 while (dir.has_next) in tinydir_open()
709 if (tinydir_readfile(&dir, file) == -1) in tinydir_open()
720 tinydir_next(&dir); in tinydir_open()
729 tinydir_close(&dir); in tinydir_open()