Previous 199869 Revisions Next

r34300 Saturday 10th January, 2015 at 00:53:20 UTC by Couriersud
Aligned sdlfile.c to winfile.c (which is actually included by sdl).
Consequently removed quite some dead code spread across different files.
[src/osd/sdl]sdldir.c sdlfile.c sdlos_macosx.c sdlos_unix.c sdlos_win32.c

trunk/src/osd/sdl/sdldir.c
r242811r242812
235235   osd_free(dir);
236236}
237237
238
238239#endif
trunk/src/osd/sdl/sdlfile.c
r242811r242812
499499
500500   return result;
501501}
502
503//============================================================
504//  osd_stat
505//============================================================
506
507osd_directory_entry *osd_stat(const char *path)
508{
509    int err;
510    osd_directory_entry *result = NULL;
511    #if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD) || defined(SDLMAME_DARWIN)
512    struct stat st;
513    #else
514    struct stat64 st;
515    #endif
516
517    #if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD) || defined(SDLMAME_DARWIN)
518    err = stat(path, &st);
519    #else
520    err = stat64(path, &st);
521    #endif
522
523    if( err == -1) return NULL;
524
525    // create an osd_directory_entry; be sure to make sure that the caller can
526    // free all resources by just freeing the resulting osd_directory_entry
527    result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
528    strcpy(((char *) result) + sizeof(*result), path);
529    result->name = ((char *) result) + sizeof(*result);
530    result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
531    result->size = (UINT64)st.st_size;
532
533    return result;
534}
535
536//============================================================
537//  osd_get_full_path
538//============================================================
539
540file_error osd_get_full_path(char **dst, const char *path)
541{
542    file_error err;
543    char path_buffer[512];
544
545    err = FILERR_NONE;
546
547    if (getcwd(path_buffer, 511) == NULL)
548    {
549        printf("osd_get_full_path: failed!\n");
550        err = FILERR_FAILURE;
551    }
552    else
553    {
554        *dst = (char *)osd_malloc_array(strlen(path_buffer)+strlen(path)+3);
555
556        // if it's already a full path, just pass it through
557        if (path[0] == '/')
558        {
559            strcpy(*dst, path);
560        }
561        else
562        {
563            sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
564        }
565    }
566
567    return err;
568}
569
570//============================================================
571//  osd_get_volume_name
572//============================================================
573
574const char *osd_get_volume_name(int idx)
575{
576    if (idx!=0) return NULL;
577    return "/";
578}
579
502580#endif
trunk/src/osd/sdl/sdlos_macosx.c
r242811r242812
122122   return result;
123123}
124124
125//============================================================
126//  osd_stat
127//============================================================
128
129osd_directory_entry *osd_stat(const char *path)
130{
131   int err;
132   osd_directory_entry *result = NULL;
133   #if defined(SDLMAME_DARWIN) || defined(SDLMAME_NO64BITIO)
134   struct stat st;
135   #else
136   struct stat64 st;
137   #endif
138
139   #if defined(SDLMAME_DARWIN) || defined(SDLMAME_NO64BITIO)
140   err = stat(path, &st);
141   #else
142   err = stat64(path, &st);
143   #endif
144
145   if( err == -1) return NULL;
146
147   // create an osd_directory_entry; be sure to make sure that the caller can
148   // free all resources by just freeing the resulting osd_directory_entry
149   result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
150   strcpy(((char *) result) + sizeof(*result), path);
151   result->name = ((char *) result) + sizeof(*result);
152   result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
153   result->size = (UINT64)st.st_size;
154
155   return result;
156}
157
158//============================================================
159//  osd_get_volume_name
160//============================================================
161
162const char *osd_get_volume_name(int idx)
163{
164   if (idx!=0) return NULL;
165   return "/";
166}
167
168//============================================================
169//  osd_get_full_path
170//============================================================
171
172file_error osd_get_full_path(char **dst, const char *path)
173{
174   file_error err;
175   char path_buffer[512];
176
177   err = FILERR_NONE;
178
179   if (getcwd(path_buffer, 511) == NULL)
180   {
181      printf("osd_get_full_path: failed!\n");
182      err = FILERR_FAILURE;
183   }
184   else
185   {
186      *dst = (char *)osd_malloc_array(strlen(path_buffer)+strlen(path)+3);
187
188      // if it's already a full path, just pass it through
189      if (path[0] == '/')
190      {
191         strcpy(*dst, path);
192      }
193      else
194      {
195         sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
196      }
197   }
198
199   return err;
200}
trunk/src/osd/sdl/sdlos_unix.c
r242811r242812
148148}
149149#endif
150150
151//============================================================
152//  osd_stat
153//============================================================
154151
155osd_directory_entry *osd_stat(const char *path)
156{
157   int err;
158   osd_directory_entry *result = NULL;
159   #if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD)
160   struct stat st;
161   #else
162   struct stat64 st;
163   #endif
164152
165   #if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD)
166   err = stat(path, &st);
167   #else
168   err = stat64(path, &st);
169   #endif
170
171   if( err == -1) return NULL;
172
173   // create an osd_directory_entry; be sure to make sure that the caller can
174   // free all resources by just freeing the resulting osd_directory_entry
175   result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
176   strcpy(((char *) result) + sizeof(*result), path);
177   result->name = ((char *) result) + sizeof(*result);
178   result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
179   result->size = (UINT64)st.st_size;
180
181   return result;
182}
183
184//============================================================
185//  osd_get_volume_name
186//============================================================
187
188const char *osd_get_volume_name(int idx)
189{
190   if (idx!=0) return NULL;
191   return "/";
192}
193
194//============================================================
195//  osd_get_full_path
196//============================================================
197
198file_error osd_get_full_path(char **dst, const char *path)
199{
200   file_error err;
201   char path_buffer[512];
202
203   err = FILERR_NONE;
204
205   if (getcwd(path_buffer, 511) == NULL)
206   {
207      printf("osd_get_full_path: failed!\n");
208      err = FILERR_FAILURE;
209   }
210   else
211   {
212      *dst = (char *)osd_malloc_array(strlen(path_buffer)+strlen(path)+3);
213
214      // if it's already a full path, just pass it through
215      if (path[0] == '/')
216      {
217         strcpy(*dst, path);
218      }
219      else
220      {
221         sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
222      }
223   }
224
225   return err;
226}
trunk/src/osd/sdl/sdlos_win32.c
r242811r242812
144144   return result;
145145}
146146
147//============================================================
148//  win_attributes_to_entry_type
149//============================================================
150
151static osd_dir_entry_type win_attributes_to_entry_type(DWORD attributes)
152{
153   if (attributes == 0xFFFFFFFF)
154      return ENTTYPE_NONE;
155   else if (attributes & FILE_ATTRIBUTE_DIRECTORY)
156      return ENTTYPE_DIR;
157   else
158      return ENTTYPE_FILE;
159}
160
161//============================================================
162//  osd_stat
163//============================================================
164
165osd_directory_entry *osd_stat(const char *path)
166{
167   osd_directory_entry *result = NULL;
168   TCHAR *t_path;
169   HANDLE find = INVALID_HANDLE_VALUE;
170   WIN32_FIND_DATA find_data;
171
172   // convert the path to TCHARs
173   t_path = tstring_from_utf8(path);
174   if (t_path == NULL)
175      goto done;
176
177   // attempt to find the first file
178   find = FindFirstFile(t_path, &find_data);
179   if (find == INVALID_HANDLE_VALUE)
180      goto done;
181
182   // create an osd_directory_entry; be sure to make sure that the caller can
183   // free all resources by just freeing the resulting osd_directory_entry
184   result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
185   if (!result)
186      goto done;
187   strcpy(((char *) result) + sizeof(*result), path);
188   result->name = ((char *) result) + sizeof(*result);
189   result->type = win_attributes_to_entry_type(find_data.dwFileAttributes);
190   result->size = find_data.nFileSizeLow | ((UINT64) find_data.nFileSizeHigh << 32);
191
192done:
193   if (t_path)
194      osd_free(t_path);
195   return result;
196}
197
198//============================================================
199//  osd_get_volume_name
200//============================================================
201
202const char *osd_get_volume_name(int idx)
203{
204   static char szBuffer[128];
205   const char *p;
206
207   GetLogicalDriveStringsA(ARRAY_LENGTH(szBuffer), szBuffer);
208
209   p = szBuffer;
210   while(idx--) {
211      p += strlen(p) + 1;
212      if (!*p) return NULL;
213   }
214
215   return p;
216}
217
218//============================================================
219//  win_error_to_mame_file_error
220//============================================================
221
222static file_error win_error_to_mame_file_error(DWORD error)
223{
224   file_error filerr;
225
226   // convert a Windows error to a file_error
227   switch (error)
228   {
229      case ERROR_SUCCESS:
230         filerr = FILERR_NONE;
231         break;
232
233      case ERROR_OUTOFMEMORY:
234         filerr = FILERR_OUT_OF_MEMORY;
235         break;
236
237      case ERROR_FILE_NOT_FOUND:
238      case ERROR_PATH_NOT_FOUND:
239         filerr = FILERR_NOT_FOUND;
240         break;
241
242      case ERROR_ACCESS_DENIED:
243         filerr = FILERR_ACCESS_DENIED;
244         break;
245
246      case ERROR_SHARING_VIOLATION:
247         filerr = FILERR_ALREADY_OPEN;
248         break;
249
250      default:
251         filerr = FILERR_FAILURE;
252         break;
253   }
254   return filerr;
255}
256
257//============================================================
258//  osd_get_full_path
259//============================================================
260
261file_error osd_get_full_path(char **dst, const char *path)
262{
263   file_error err;
264   TCHAR *t_path;
265   TCHAR buffer[MAX_PATH];
266
267   // convert the path to TCHARs
268   t_path = tstring_from_utf8(path);
269   if (t_path == NULL)
270   {
271      err = FILERR_OUT_OF_MEMORY;
272      goto done;
273   }
274
275   // cannonicalize the path
276   if (!GetFullPathName(t_path, ARRAY_LENGTH(buffer), buffer, NULL))
277   {
278      err = win_error_to_mame_file_error(GetLastError());
279      goto done;
280   }
281
282   // convert the result back to UTF-8
283   *dst = utf8_from_tstring(buffer);
284   if (!*dst)
285   {
286      err = FILERR_OUT_OF_MEMORY;
287      goto done;
288   }
289
290   err = FILERR_NONE;
291
292done:
293   if (t_path != NULL)
294      osd_free(t_path);
295   return err;
296}


Previous 199869 Revisions Next


© 1997-2024 The MAME Team