* grub-core/kern/emu/hostdisk.c (grub_util_biosdisk_open): Use

grub_util_fd_strerror when using grub_util_fd_*.
	(grub_util_fd_open_device): Likewise.
	(grub_util_biosdisk_read): Likewise.
	(grub_util_biosdisk_write): Likewise.
	* grub-core/kern/emu/hostdisk_unix.c (grub_util_fd_open): New function.
	(grub_util_fd_strerror): Likewise.
	(grub_util_fd_sync): Likewise.
	(grub_util_fd_close): Likewise.
	* grub-core/kern/emu/hostdisk_windows.c (grub_util_fd_sync): Likewise.
	(grub_util_fd_close): Likewise.
	(grub_util_fd_strerror): Likewise.
	* include/grub/emu/hostdisk.h (grub_util_fd_close): Make into real
	function proto rather than macro.
	(grub_util_fd_sync): Likewise.
	(grub_util_fd_open): Likewise.
	(grub_util_fd_strerror): New proto.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-09-24 19:08:34 +02:00
parent e8fd80bc3d
commit 43b1c99d53
5 changed files with 92 additions and 11 deletions

View file

@ -204,3 +204,38 @@ grub_util_fd_write (grub_util_fd_t fd, const char *buf, size_t len)
grub_util_info ("successful write");
return real_read;
}
void
grub_util_fd_sync (grub_util_fd_t fd)
{
FlushFileBuffers (fd);
}
void
grub_util_fd_close (grub_util_fd_t fd)
{
CloseHandle (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);
#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
}