gstdio: Ensure w32_err_to_errno is used everywhere, add ERROR_INVALID_PARAMETER handling

case switches in w32_err_to_errno have been alphabetically sorted.

The only addition is the ERROR_INVALID_PARAMETER->EINVAL case.
This commit is contained in:
Jeremy Tan 2019-06-17 19:13:31 +10:00
parent 3addc38ca2
commit 04dcee1814

View File

@ -102,22 +102,35 @@ w32_error_to_errno (DWORD error_code)
case ERROR_ACCESS_DENIED: case ERROR_ACCESS_DENIED:
return EACCES; return EACCES;
break; break;
case ERROR_INVALID_HANDLE: case ERROR_ALREADY_EXISTS:
return EBADF; case ERROR_FILE_EXISTS:
return EEXIST;
case ERROR_FILE_NOT_FOUND:
return ENOENT;
break; break;
case ERROR_INVALID_FUNCTION: case ERROR_INVALID_FUNCTION:
return EFAULT; return EFAULT;
break; break;
case ERROR_FILE_NOT_FOUND: case ERROR_INVALID_HANDLE:
return ENOENT; return EBADF;
break; break;
case ERROR_PATH_NOT_FOUND: case ERROR_INVALID_PARAMETER:
return ENOENT; /* or ELOOP, or ENAMETOOLONG */ return EINVAL;
break;
case ERROR_LOCK_VIOLATION:
case ERROR_SHARING_VIOLATION:
return EACCES;
break; break;
case ERROR_NOT_ENOUGH_MEMORY: case ERROR_NOT_ENOUGH_MEMORY:
case ERROR_OUTOFMEMORY: case ERROR_OUTOFMEMORY:
return ENOMEM; return ENOMEM;
break; break;
case ERROR_NOT_SAME_DEVICE:
return EXDEV;
break;
case ERROR_PATH_NOT_FOUND:
return ENOENT; /* or ELOOP, or ENAMETOOLONG */
break;
default: default:
return EIO; return EIO;
break; break;
@ -1154,20 +1167,7 @@ g_rename (const gchar *oldfilename,
else else
{ {
retval = -1; retval = -1;
switch (GetLastError ()) save_errno = w32_error_to_errno (GetLastError ());
{
#define CASE(a,b) case ERROR_##a: save_errno = b; break
CASE (FILE_NOT_FOUND, ENOENT);
CASE (PATH_NOT_FOUND, ENOENT);
CASE (ACCESS_DENIED, EACCES);
CASE (NOT_SAME_DEVICE, EXDEV);
CASE (LOCK_VIOLATION, EACCES);
CASE (SHARING_VIOLATION, EACCES);
CASE (FILE_EXISTS, EEXIST);
CASE (ALREADY_EXISTS, EEXIST);
#undef CASE
default: save_errno = EIO;
}
} }
g_free (woldfilename); g_free (woldfilename);