Previous 15994 Revisions Next

r7349 Sunday 14th February, 2010 at 09:03:17 UTC by Miodrag Milanović
- Fixed memory issues in zippath [micko]
- SDL win32 file access works now [couriersid]
[src/mess]zippath.c
[src/osd/sdl]sdldir.c

src/osd/sdl/sdldir.c
r7348r7349
5252   struct dirent64 *data;
5353#endif
5454   DIR *fd;
55   char *path;
5556};
5657
58static 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;
5762
63   strcpy(p, path);
64   p += strlen(path);   
65   *p++ = PATHSEPCH;
66   strcpy(p, file);
67   return ret;
68}
69
70
5871#if defined (SDLMAME_LINUX) || defined (SDLMAME_BSD) || defined(SDLMAME_DARWIN)
5972static osd_dir_entry_type get_attributes_enttype(int attributes)
6073{
r7348r7349
6477      return ENTTYPE_FILE;
6578}
6679#else
80
6781static osd_dir_entry_type get_attributes_stat(const char *file)
6882{
6983#if defined(SDLMAME_WIN32) || defined(SDLMAME_NO64BITIO) || defined(SDLMAME_OS2)
r7348r7349
7690      return ENTTYPE_NONE;
7791#endif
7892
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;
8697}
8798#endif
8899
r7348r7349
128139      strcpy(envstr, tmpstr);
129140
130141      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] != '.')
132143      {
133144         i++;
134145      }
r7348r7349
155166   }
156167
157168   dir->fd = opendir(tmpstr);
169   dir->path = tmpstr;
158170
159171   if (dir && (dir->fd == NULL))
160172   {
173      osd_free(dir->path);
161174      osd_free(dir);
162175      dir = NULL;
163176   }
164177
165   if (tmpstr)
166     osd_free(tmpstr);
167178   return dir;
168179}
169180
r7348r7349
174185
175186const osd_directory_entry *osd_readdir(osd_directory *dir)
176187{
188   char *temp;
177189   #if defined(SDLMAME_DARWIN) || defined(SDLMAME_WIN32) || defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD) || defined(SDLMAME_OS2)
178190   dir->data = readdir(dir->fd);
179191   #else
r7348r7349
184196      return NULL;
185197
186198   dir->ent.name = dir->data->d_name;
199   temp = build_full_path(dir->path, dir->data->d_name);
187200   #if defined (SDLMAME_LINUX) || defined (SDLMAME_BSD) || defined(SDLMAME_DARWIN)
188201   dir->ent.type = get_attributes_enttype(dir->data->d_type);
189202   #else
190   dir->ent.type = get_attributes_stat(dir->data->d_name);
203   dir->ent.type = get_attributes_stat(temp);
191204   #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);
193207   return &dir->ent;
194208}
195209
r7348r7349
202216{
203217   if (dir->fd != NULL)
204218      closedir(dir->fd);
219   osd_free(dir->path);
205220   osd_free(dir);
206221}
207222
src/mess/zippath.c
r7348r7349
206206   zip_error ziperr;
207207   void *ptr;
208208
209   ptr = malloc(header->uncompressed_length);
209   ptr = global_alloc_array_clear(UINT8,header->uncompressed_length);
210210   if (ptr == NULL)
211211   {
212212      filerr = FILERR_OUT_OF_MEMORY;
r7348r7349
633633   zippath_directory *result;
634634
635635   /* allocate a directory */
636   result = (zippath_directory *) malloc(sizeof(*result));
636   result = (zippath_directory *) global_alloc_clear(zippath_directory);
637637   if (result == NULL)
638638   {
639639      err = FILERR_OUT_OF_MEMORY;
640640      goto done;
641641   }
642   memset(result, 0, sizeof(*result));
643642
644643   /* resolve the path */
645644   err = zippath_resolve(path, &entry_type, &result->zipfile, newpath);
r7348r7349
817816               if (rdent == NULL)
818817               {
819818                  /* 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));
821820                  rdent->next = directory->returned_dirlist;
822821                  memcpy(rdent->name, relpath, (separator - relpath) * sizeof(rdent->name[0]));
823822                  rdent->name[separator - relpath] = '\0';

Previous 15994 Revisions Next


© 1998-2018 The MESS Team