Aligned sdlfile.c to winfile.c (which is actually included by sdl).

Consequently removed quite some dead code spread across different files.
This commit is contained in:
couriersud 2015-01-10 01:53:20 +01:00
parent d1f0fd9fe8
commit 363b6dd26c
5 changed files with 79 additions and 300 deletions

View File

@ -235,4 +235,5 @@ void osd_closedir(osd_directory *dir)
osd_free(dir);
}
#endif

View File

@ -499,4 +499,82 @@ int osd_is_absolute_path(const char *path)
return result;
}
//============================================================
// osd_stat
//============================================================
osd_directory_entry *osd_stat(const char *path)
{
int err;
osd_directory_entry *result = NULL;
#if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD) || defined(SDLMAME_DARWIN)
struct stat st;
#else
struct stat64 st;
#endif
#if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD) || defined(SDLMAME_DARWIN)
err = stat(path, &st);
#else
err = stat64(path, &st);
#endif
if( err == -1) return NULL;
// create an osd_directory_entry; be sure to make sure that the caller can
// free all resources by just freeing the resulting osd_directory_entry
result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
strcpy(((char *) result) + sizeof(*result), path);
result->name = ((char *) result) + sizeof(*result);
result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
result->size = (UINT64)st.st_size;
return result;
}
//============================================================
// osd_get_full_path
//============================================================
file_error osd_get_full_path(char **dst, const char *path)
{
file_error err;
char path_buffer[512];
err = FILERR_NONE;
if (getcwd(path_buffer, 511) == NULL)
{
printf("osd_get_full_path: failed!\n");
err = FILERR_FAILURE;
}
else
{
*dst = (char *)osd_malloc_array(strlen(path_buffer)+strlen(path)+3);
// if it's already a full path, just pass it through
if (path[0] == '/')
{
strcpy(*dst, path);
}
else
{
sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
}
}
return err;
}
//============================================================
// osd_get_volume_name
//============================================================
const char *osd_get_volume_name(int idx)
{
if (idx!=0) return NULL;
return "/";
}
#endif

View File

@ -122,79 +122,3 @@ char *osd_get_clipboard_text(void)
return result;
}
//============================================================
// osd_stat
//============================================================
osd_directory_entry *osd_stat(const char *path)
{
int err;
osd_directory_entry *result = NULL;
#if defined(SDLMAME_DARWIN) || defined(SDLMAME_NO64BITIO)
struct stat st;
#else
struct stat64 st;
#endif
#if defined(SDLMAME_DARWIN) || defined(SDLMAME_NO64BITIO)
err = stat(path, &st);
#else
err = stat64(path, &st);
#endif
if( err == -1) return NULL;
// create an osd_directory_entry; be sure to make sure that the caller can
// free all resources by just freeing the resulting osd_directory_entry
result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
strcpy(((char *) result) + sizeof(*result), path);
result->name = ((char *) result) + sizeof(*result);
result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
result->size = (UINT64)st.st_size;
return result;
}
//============================================================
// osd_get_volume_name
//============================================================
const char *osd_get_volume_name(int idx)
{
if (idx!=0) return NULL;
return "/";
}
//============================================================
// osd_get_full_path
//============================================================
file_error osd_get_full_path(char **dst, const char *path)
{
file_error err;
char path_buffer[512];
err = FILERR_NONE;
if (getcwd(path_buffer, 511) == NULL)
{
printf("osd_get_full_path: failed!\n");
err = FILERR_FAILURE;
}
else
{
*dst = (char *)osd_malloc_array(strlen(path_buffer)+strlen(path)+3);
// if it's already a full path, just pass it through
if (path[0] == '/')
{
strcpy(*dst, path);
}
else
{
sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
}
}
return err;
}

View File

@ -148,79 +148,5 @@ char *osd_get_clipboard_text(void)
}
#endif
//============================================================
// osd_stat
//============================================================
osd_directory_entry *osd_stat(const char *path)
{
int err;
osd_directory_entry *result = NULL;
#if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD)
struct stat st;
#else
struct stat64 st;
#endif
#if defined(SDLMAME_NO64BITIO) || defined(SDLMAME_BSD)
err = stat(path, &st);
#else
err = stat64(path, &st);
#endif
if( err == -1) return NULL;
// create an osd_directory_entry; be sure to make sure that the caller can
// free all resources by just freeing the resulting osd_directory_entry
result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
strcpy(((char *) result) + sizeof(*result), path);
result->name = ((char *) result) + sizeof(*result);
result->type = S_ISDIR(st.st_mode) ? ENTTYPE_DIR : ENTTYPE_FILE;
result->size = (UINT64)st.st_size;
return result;
}
//============================================================
// osd_get_volume_name
//============================================================
const char *osd_get_volume_name(int idx)
{
if (idx!=0) return NULL;
return "/";
}
//============================================================
// osd_get_full_path
//============================================================
file_error osd_get_full_path(char **dst, const char *path)
{
file_error err;
char path_buffer[512];
err = FILERR_NONE;
if (getcwd(path_buffer, 511) == NULL)
{
printf("osd_get_full_path: failed!\n");
err = FILERR_FAILURE;
}
else
{
*dst = (char *)osd_malloc_array(strlen(path_buffer)+strlen(path)+3);
// if it's already a full path, just pass it through
if (path[0] == '/')
{
strcpy(*dst, path);
}
else
{
sprintf(*dst, "%s%s%s", path_buffer, PATH_SEPARATOR, path);
}
}
return err;
}

View File

@ -144,153 +144,3 @@ WCHAR *wstring_from_utf8(const char *utf8string)
return result;
}
//============================================================
// win_attributes_to_entry_type
//============================================================
static osd_dir_entry_type win_attributes_to_entry_type(DWORD attributes)
{
if (attributes == 0xFFFFFFFF)
return ENTTYPE_NONE;
else if (attributes & FILE_ATTRIBUTE_DIRECTORY)
return ENTTYPE_DIR;
else
return ENTTYPE_FILE;
}
//============================================================
// osd_stat
//============================================================
osd_directory_entry *osd_stat(const char *path)
{
osd_directory_entry *result = NULL;
TCHAR *t_path;
HANDLE find = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA find_data;
// convert the path to TCHARs
t_path = tstring_from_utf8(path);
if (t_path == NULL)
goto done;
// attempt to find the first file
find = FindFirstFile(t_path, &find_data);
if (find == INVALID_HANDLE_VALUE)
goto done;
// create an osd_directory_entry; be sure to make sure that the caller can
// free all resources by just freeing the resulting osd_directory_entry
result = (osd_directory_entry *) osd_malloc_array(sizeof(*result) + strlen(path) + 1);
if (!result)
goto done;
strcpy(((char *) result) + sizeof(*result), path);
result->name = ((char *) result) + sizeof(*result);
result->type = win_attributes_to_entry_type(find_data.dwFileAttributes);
result->size = find_data.nFileSizeLow | ((UINT64) find_data.nFileSizeHigh << 32);
done:
if (t_path)
osd_free(t_path);
return result;
}
//============================================================
// osd_get_volume_name
//============================================================
const char *osd_get_volume_name(int idx)
{
static char szBuffer[128];
const char *p;
GetLogicalDriveStringsA(ARRAY_LENGTH(szBuffer), szBuffer);
p = szBuffer;
while(idx--) {
p += strlen(p) + 1;
if (!*p) return NULL;
}
return p;
}
//============================================================
// win_error_to_mame_file_error
//============================================================
static file_error win_error_to_mame_file_error(DWORD error)
{
file_error filerr;
// convert a Windows error to a file_error
switch (error)
{
case ERROR_SUCCESS:
filerr = FILERR_NONE;
break;
case ERROR_OUTOFMEMORY:
filerr = FILERR_OUT_OF_MEMORY;
break;
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
filerr = FILERR_NOT_FOUND;
break;
case ERROR_ACCESS_DENIED:
filerr = FILERR_ACCESS_DENIED;
break;
case ERROR_SHARING_VIOLATION:
filerr = FILERR_ALREADY_OPEN;
break;
default:
filerr = FILERR_FAILURE;
break;
}
return filerr;
}
//============================================================
// osd_get_full_path
//============================================================
file_error osd_get_full_path(char **dst, const char *path)
{
file_error err;
TCHAR *t_path;
TCHAR buffer[MAX_PATH];
// convert the path to TCHARs
t_path = tstring_from_utf8(path);
if (t_path == NULL)
{
err = FILERR_OUT_OF_MEMORY;
goto done;
}
// cannonicalize the path
if (!GetFullPathName(t_path, ARRAY_LENGTH(buffer), buffer, NULL))
{
err = win_error_to_mame_file_error(GetLastError());
goto done;
}
// convert the result back to UTF-8
*dst = utf8_from_tstring(buffer);
if (!*dst)
{
err = FILERR_OUT_OF_MEMORY;
goto done;
}
err = FILERR_NONE;
done:
if (t_path != NULL)
osd_free(t_path);
return err;
}