#include <dirent.h>
#include <errno.h>
#include <io.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Classes | |
struct | DIR |
Functions | |
DIR * | opendir (const char *name) |
int | closedir (DIR *dir) |
struct dirent * | readdir (DIR *dir) |
void | rewinddir (DIR *dir) |
int closedir | ( | DIR * | dir | ) |
Definition at line 99 of file dirent.c.
References free, DIR::handle, and DIR::name.
00100 { 00101 int result = -1; 00102 00103 if(dir) 00104 { 00105 if(dir->handle != -1) 00106 { 00107 result = _findclose(dir->handle); 00108 } 00109 00110 free(dir->name); 00111 free(dir); 00112 } 00113 00114 if(result == -1) /* map all errors to EBADF */ 00115 { 00116 errno = EBADF; 00117 } 00118 00119 return result; 00120 }
DIR* opendir | ( | const char * | name | ) |
Definition at line 58 of file dirent.c.
References dirent::d_name, free, DIR::handle, DIR::info, malloc, DIR::name, and DIR::result.
00059 { 00060 DIR *dir = 0; 00061 00062 if(name && name[0]) 00063 { 00064 size_t base_length = strlen(name); 00065 const char *all = /* search pattern must end with suitable wildcard */ 00066 strchr("/\\", name[base_length - 1]) ? "*" : "/*"; 00067 00068 if((dir = (DIR *) malloc(sizeof *dir)) != 0 && 00069 (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0) 00070 { 00071 strcat(strcpy(dir->name, name), all); 00072 00073 if((dir->handle = (long) _findfirst(dir->name, &dir->info)) != -1) 00074 { 00075 dir->result.d_name = 0; 00076 } 00077 else /* rollback */ 00078 { 00079 free(dir->name); 00080 free(dir); 00081 dir = 0; 00082 } 00083 } 00084 else /* rollback */ 00085 { 00086 free(dir); 00087 dir = 0; 00088 errno = ENOMEM; 00089 } 00090 } 00091 else 00092 { 00093 errno = EINVAL; 00094 } 00095 00096 return dir; 00097 }
Definition at line 122 of file dirent.c.
References dirent::d_name, DIR::handle, DIR::info, and DIR::result.
00123 { 00124 struct dirent *result = 0; 00125 00126 if(dir && dir->handle != -1) 00127 { 00128 if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) 00129 { 00130 result = &dir->result; 00131 result->d_name = dir->info.name; 00132 } 00133 } 00134 else 00135 { 00136 errno = EBADF; 00137 } 00138 00139 return result; 00140 }
void rewinddir | ( | DIR * | dir | ) |
Definition at line 142 of file dirent.c.
References dirent::d_name, DIR::handle, DIR::info, DIR::name, and DIR::result.
00143 { 00144 if(dir && dir->handle != -1) 00145 { 00146 _findclose(dir->handle); 00147 dir->handle = (long) _findfirst(dir->name, &dir->info); 00148 dir->result.d_name = 0; 00149 } 00150 else 00151 { 00152 errno = EBADF; 00153 } 00154 }