From e70d64d49e9f2e59012565ca6901a9086129dfee Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Fri, 15 Jun 2012 16:06:11 +0900 Subject: [PATCH] [Title] Modify an error message when emulator cannot load a disk file properly. [Type] bug fix [Module] emulator / error handling. [Priority] normal [CQ#] [Redmine#] [Problem] The previous error message make users confused because it displayed a path of emulator workspace and path of emulator image. [Cause] [Solution] check the path of emulator image whether absolute path is or not. [TestCase] --- blockdev.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/blockdev.c b/blockdev.c index 1459608925..7b26644571 100644 --- a/blockdev.c +++ b/blockdev.c @@ -524,18 +524,64 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) file, strerror(-ret)); #ifdef CONFIG_MARU - const char _msg[] = "Fail to load disk file. Check if the file is corrupted or missing from the following path.\n\n"; - char* current_path = (char *)g_get_current_dir(); + const char _msg[] = "Failed to load disk file from the following path. Check if the file was corrupted or missing.\n\n"; + char* current_path = NULL; + char* err_msg = NULL; +#ifdef _WIN32 + char* dos_err_msg = NULL; +#endif + int total_len = 0; + int msg_len = 0; + int cur_path_len = 0; + int disk_path_len = 0; + int res = -1; + + res = (int)g_path_is_absolute((gchar*)file); + disk_path_len = (strlen(file) + 1); + msg_len = strlen(_msg) + 1; + + if (!res) { + current_path = (char*)g_get_current_dir(); + cur_path_len = strlen(current_path) + strlen("/") + 1; + total_len += cur_path_len; + } + total_len += (disk_path_len + msg_len); + + err_msg = g_malloc0(total_len * sizeof(char)); + if (!err_msg) { + printf("failed to allocate memory\n"); + } + + snprintf(err_msg, msg_len, "%s", _msg); + total_len = msg_len - 1; + if (!res) { + snprintf(err_msg + total_len, cur_path_len, "%s%s", current_path, "/"); + total_len += (cur_path_len - 1); + } + snprintf(err_msg + total_len, disk_path_len, "%s", file); - int len = strlen(_msg) + strlen(current_path) + strlen(file) + 2; +#ifdef _WIN32 + { + int i; - char* error_msg = g_malloc0(len * sizeof(char)); - snprintf(error_msg, len, "%s%s/%s", _msg, current_path, file); + dos_err_msg = strdup(err_msg); + if (!dos_err_msg) { + printf("failed to duplicate an error message from %p\n", err_msg); + } - start_simple_client(error_msg); + for (i = (total_len - 1); dos_err_msg[i]; i++) { + if (dos_err_msg[i] == '/') { + dos_err_msg[i] = '\\'; + } + } + strncpy(err_msg, dos_err_msg, strlen(dos_err_msg)); + free(dos_err_msg); + } +#endif + start_simple_client(err_msg); g_free(current_path); - g_free(error_msg); + g_free(err_msg); #endif goto err; -- 2.34.1