* grub-core/osdep/windows/hostdisk.c (grub_util_fd_strerror):

Cut tailing newline. Remove arbitrary limitation. Always use
	grub_util_tchar_to_utf8.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-10-15 15:14:58 +02:00
parent 148f100768
commit 8f53bb3fd2
2 changed files with 32 additions and 17 deletions

View file

@ -1,3 +1,9 @@
2013-10-15 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/osdep/windows/hostdisk.c (grub_util_fd_strerror):
Cut tailing newline. Remove arbitrary limitation. Always use
grub_util_tchar_to_utf8.
2013-10-15 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/misc.c (grub_vsnprintf_real): Handle %% properly.

View file

@ -255,24 +255,33 @@ grub_util_fd_close (grub_util_fd_t fd)
const char *
grub_util_fd_strerror (void)
{
DWORD err;
static TCHAR tbuf[1024];
err = GetLastError ();
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
tbuf, ARRAY_SIZE (tbuf), NULL);
DWORD err = GetLastError ();
LPTSTR tstr = NULL;
static char *last;
char *ret, *ptr;
#if SIZEOF_TCHAR == 1
return (char *) tbuf;
#elif SIZEOF_TCHAR == 2
static grub_uint8_t buf[ARRAY_SIZE (tbuf) * GRUB_MAX_UTF8_PER_UTF16 + 1];
*grub_utf16_to_utf8 (buf, tbuf, ARRAY_SIZE (tbuf)) = '\0';
return (char *) buf;
#else
#error "Unsupported TCHAR size"
#endif
free (last);
last = 0;
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, 0, (LPTSTR) &tstr, 0, NULL);
if (!tstr)
return "unknown error";
ret = grub_util_tchar_to_utf8 (tstr);
LocalFree (tstr);
last = ret;
for (ptr = ret + strlen (ret) - 1;
ptr >= ret && (*ptr == '\n' || *ptr == '\r');
ptr--);
ptr[1] = '\0';
return ret;
}
char *