src/osd/sdl/sdldir.c
| r7348 | r7349 | |
| 52 | 52 | struct dirent64 *data; |
| 53 | 53 | #endif |
| 54 | 54 | DIR *fd; |
| 55 | char *path; |
| 55 | 56 | }; |
| 56 | 57 | |
| 58 | static char *build_full_path(const char *path, const char *file) |
| 59 | { |
| 60 | char *ret = (char *) osd_malloc(strlen(path)+strlen(file)+2); |
| 61 | char *p = ret; |
| 57 | 62 | |
| 63 | strcpy(p, path); |
| 64 | p += strlen(path); |
| 65 | *p++ = PATHSEPCH; |
| 66 | strcpy(p, file); |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | |
| 58 | 71 | #if defined (SDLMAME_LINUX) || defined (SDLMAME_BSD) || defined(SDLMAME_DARWIN) |
| 59 | 72 | static osd_dir_entry_type get_attributes_enttype(int attributes) |
| 60 | 73 | { |
| r7348 | r7349 | |
| 64 | 77 | return ENTTYPE_FILE; |
| 65 | 78 | } |
| 66 | 79 | #else |
| 80 | |
| 67 | 81 | static osd_dir_entry_type get_attributes_stat(const char *file) |
| 68 | 82 | { |
| 69 | 83 | #if defined(SDLMAME_WIN32) || defined(SDLMAME_NO64BITIO) || defined(SDLMAME_OS2) |
| r7348 | r7349 | |
| 76 | 90 | return ENTTYPE_NONE; |
| 77 | 91 | #endif |
| 78 | 92 | |
| 79 | | #ifdef SDLMAME_WIN32 |
| 80 | | if (S_ISBLK(st.st_mode)) return ENTTYPE_DIR; |
| 81 | | #else |
| 82 | | if (S_ISDIR(st.st_mode)) return ENTTYPE_DIR; |
| 83 | | #endif |
| 84 | | |
| 85 | | return ENTTYPE_FILE; |
| 93 | if (S_ISDIR(st.st_mode)) |
| 94 | return ENTTYPE_DIR; |
| 95 | else |
| 96 | return ENTTYPE_FILE; |
| 86 | 97 | } |
| 87 | 98 | #endif |
| 88 | 99 | |
| r7348 | r7349 | |
| 128 | 139 | strcpy(envstr, tmpstr); |
| 129 | 140 | |
| 130 | 141 | i = 0; |
| 131 | | while (envstr[i] != PATHSEPCH && envstr[i] != 0 && envstr[i] != '.') |
| 142 | while (envstr[i] != PATHSEPCH && envstr[i] != INVPATHSEPCH && envstr[i] != 0 && envstr[i] != '.') |
| 132 | 143 | { |
| 133 | 144 | i++; |
| 134 | 145 | } |
| r7348 | r7349 | |
| 155 | 166 | } |
| 156 | 167 | |
| 157 | 168 | dir->fd = opendir(tmpstr); |
| 169 | dir->path = tmpstr; |
| 158 | 170 | |
| 159 | 171 | if (dir && (dir->fd == NULL)) |
| 160 | 172 | { |
| 173 | osd_free(dir->path); |
| 161 | 174 | osd_free(dir); |
| 162 | 175 | dir = NULL; |
| 163 | 176 | } |
| 164 | 177 | |
| 165 | | if (tmpstr) |
| 166 | | osd_free(tmpstr); |
| 167 | 178 | return dir; |
| 168 | 179 | } |
| 169 | 180 | |
| r7348 | r7349 | |
| 174 | 185 | |
| 175 | 186 | const osd_directory_entry *osd_readdir(osd_directory *dir) |
| 176 | 187 | { |
| 188 | char *temp; |
| 177 | 189 | #if defined(SDLMAME_DARWIN) || defined(SDLMAME_WIN32) || defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD) || defined(SDLMAME_OS2) |
| 178 | 190 | dir->data = readdir(dir->fd); |
| 179 | 191 | #else |
| r7348 | r7349 | |
| 184 | 196 | return NULL; |
| 185 | 197 | |
| 186 | 198 | dir->ent.name = dir->data->d_name; |
| 199 | temp = build_full_path(dir->path, dir->data->d_name); |
| 187 | 200 | #if defined (SDLMAME_LINUX) || defined (SDLMAME_BSD) || defined(SDLMAME_DARWIN) |
| 188 | 201 | dir->ent.type = get_attributes_enttype(dir->data->d_type); |
| 189 | 202 | #else |
| 190 | | dir->ent.type = get_attributes_stat(dir->data->d_name); |
| 203 | dir->ent.type = get_attributes_stat(temp); |
| 191 | 204 | #endif |
| 192 | | dir->ent.size = osd_get_file_size(dir->data->d_name); |
| 205 | dir->ent.size = osd_get_file_size(temp); |
| 206 | osd_free(temp); |
| 193 | 207 | return &dir->ent; |
| 194 | 208 | } |
| 195 | 209 | |
| r7348 | r7349 | |
| 202 | 216 | { |
| 203 | 217 | if (dir->fd != NULL) |
| 204 | 218 | closedir(dir->fd); |
| 219 | osd_free(dir->path); |
| 205 | 220 | osd_free(dir); |
| 206 | 221 | } |
| 207 | 222 | |
src/mess/zippath.c
| r7348 | r7349 | |
| 206 | 206 | zip_error ziperr; |
| 207 | 207 | void *ptr; |
| 208 | 208 | |
| 209 | | ptr = malloc(header->uncompressed_length); |
| 209 | ptr = global_alloc_array_clear(UINT8,header->uncompressed_length); |
| 210 | 210 | if (ptr == NULL) |
| 211 | 211 | { |
| 212 | 212 | filerr = FILERR_OUT_OF_MEMORY; |
| r7348 | r7349 | |
| 633 | 633 | zippath_directory *result; |
| 634 | 634 | |
| 635 | 635 | /* allocate a directory */ |
| 636 | | result = (zippath_directory *) malloc(sizeof(*result)); |
| 636 | result = (zippath_directory *) global_alloc_clear(zippath_directory); |
| 637 | 637 | if (result == NULL) |
| 638 | 638 | { |
| 639 | 639 | err = FILERR_OUT_OF_MEMORY; |
| 640 | 640 | goto done; |
| 641 | 641 | } |
| 642 | | memset(result, 0, sizeof(*result)); |
| 643 | 642 | |
| 644 | 643 | /* resolve the path */ |
| 645 | 644 | err = zippath_resolve(path, &entry_type, &result->zipfile, newpath); |
| r7348 | r7349 | |
| 817 | 816 | if (rdent == NULL) |
| 818 | 817 | { |
| 819 | 818 | /* we've found a new directory; add this to returned_dirlist */ |
| 820 | | rdent = (zippath_returned_directory*)malloc(sizeof(*rdent) + (separator - relpath)); |
| 819 | rdent = (zippath_returned_directory*)global_alloc_array_clear(UINT8,sizeof(*rdent) + (separator - relpath)); |
| 821 | 820 | rdent->next = directory->returned_dirlist; |
| 822 | 821 | memcpy(rdent->name, relpath, (separator - relpath) * sizeof(rdent->name[0])); |
| 823 | 822 | rdent->name[separator - relpath] = '\0'; |