Previous 15994 Revisions Next

r3045 Saturday 16th August, 2008 at 13:25:37 UTC by Nathan Woods
More robust handling of zip files that use backslashes internally
[src/mess]zippath.c

src/mess/zippath.c
r3044r3045
179179
180180
181181/*-------------------------------------------------
182    is_zip_separator - special check for path
183   separators
182    is_zip_file_separator - returns whether this
183   character is a path separator within a ZIP file
184184-------------------------------------------------*/
185185
186static int is_zip_separator(char c)
186static int is_zip_file_separator(char c)
187187{
188   return (c == '/') || osd_is_path_separator(c);
188   return (c == '/') || (c == '\\');
189189}
190190
191191
192192
193193/*-------------------------------------------------
194    is_zip_path_separator - returns whether this
195   character is a path separator within a ZIP path
196-------------------------------------------------*/
197
198static int is_zip_path_separator(char c)
199{
200   return is_zip_file_separator(c) || osd_is_path_separator(c);
201}
202
203
204
205/*-------------------------------------------------
194206    zippath_find_sub_path - attempts to identify the
195207   type of a sub path in a zip file
196208-------------------------------------------------*/
r3044r3045
214226      j = 0;
215227      do
216228      {
217         while(header->filename[i] == '/')
229         while(is_zip_file_separator(header->filename[i]))
218230            i++;
219         while(is_zip_separator(subpath[j]))
231         while(is_zip_path_separator(subpath[j]))
220232            j++;
221233         while((header->filename[i] != '\0') && (tolower(header->filename[i]) == tolower(subpath[j])))
222234         {
r3044r3045
224236            j++;
225237         }
226238      }
227      while((header->filename[i] == '/') && is_zip_separator(subpath[j]));
239      while(is_zip_file_separator(header->filename[i]) && is_zip_path_separator(subpath[j]));
228240
229241      if (subpath[j] == '\0')
230242      {
r3044r3045
234246               *type = ENTTYPE_FILE;
235247            return header;
236248         }
237         else if ((i == 0) || (header->filename[i] == '/'))
249         else if ((i == 0) || is_zip_file_separator(header->filename[i]))
238250         {
239251            if (type != NULL)
240252               *type = ENTTYPE_DIR;
r3044r3045
459471      && !strncmp(astring_c(directory->zipprefix), header->filename, len))
460472   {
461473      result = &header->filename[len];
462      while(*result == '/')
474      while(is_zip_file_separator(*result))
463475         result++;
464476   }
465477
r3044r3045
477489   const zip_file_header *header;
478490   const char *relpath;
479491   const char *separator;
492   const char *s;
480493   zippath_returned_directory *rdent;
481494
482495   if (!directory->returned_parent)
r3044r3045
525538         if (relpath != NULL)
526539         {
527540            /* we've found a ZIP entry; but this may be an entry deep within the target directory */
528            separator = strchr(relpath, '/');
541            for (s = relpath; *s && !is_zip_file_separator(*s); s++)
542               ;
543            separator = *s ? s : NULL;
544           
529545            if (separator != NULL)
530546            {
531547               /* a nested entry; loop through returned_dirlist to see if we've returned the parent directory */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team