#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 | |
| SWDLLEXPORT int | closedir (DIR *dir) |
| SWDLLEXPORT DIR * | opendir (const char *name) |
| SWDLLEXPORT struct dirent * | readdir (DIR *dir) |
| SWDLLEXPORT void | rewinddir (DIR *dir) |
| SWDLLEXPORT int closedir | ( | DIR * | dir | ) |
Definition at line 76 of file dirent.cpp.
00077 { 00078 int result = -1; 00079 00080 if(dir) 00081 { 00082 if(dir->handle != -1) 00083 { 00084 result = _findclose(dir->handle); 00085 } 00086 00087 free(dir->name); 00088 free(dir); 00089 } 00090 00091 if(result == -1) /* map all errors to EBADF */ 00092 { 00093 errno = EBADF; 00094 } 00095 00096 return result; 00097 }
| SWDLLEXPORT DIR* opendir | ( | const char * | name | ) |
Definition at line 35 of file dirent.cpp.
00036 { 00037 DIR *dir = 0; 00038 00039 if(name && name[0]) 00040 { 00041 size_t base_length = strlen(name); 00042 const char *all = /* the root directory is a special case... */ 00043 strchr("/\\", name[base_length - 1]) ? "*" : "/*"; 00044 00045 if((dir = (DIR *) malloc(sizeof *dir)) != 0 && 00046 (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0) 00047 { 00048 strcat(strcpy(dir->name, name), all); 00049 00050 if((dir->handle = _findfirst(dir->name, &dir->info)) != -1) 00051 { 00052 dir->result.d_name = 0; 00053 } 00054 else /* rollback */ 00055 { 00056 free(dir->name); 00057 free(dir); 00058 dir = 0; 00059 } 00060 } 00061 else /* rollback */ 00062 { 00063 free(dir); 00064 dir = 0; 00065 errno = ENOMEM; 00066 } 00067 } 00068 else 00069 { 00070 errno = EINVAL; 00071 } 00072 00073 return dir; 00074 }
Definition at line 99 of file dirent.cpp.
00100 { 00101 struct dirent *result = 0; 00102 00103 if(dir && dir->handle != -1) 00104 { 00105 if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) 00106 { 00107 result = &dir->result; 00108 result->d_name = dir->info.name; 00109 } 00110 } 00111 else 00112 { 00113 errno = EBADF; 00114 } 00115 00116 return result; 00117 }
| SWDLLEXPORT void rewinddir | ( | DIR * | dir | ) |
1.6.1