From 9ffe8b0b4e2ff9b98813521f79c840d983424f82 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Sat, 22 Aug 2009 10:34:40 -0700 Subject: [PATCH] hdt: make get_error behaves like perror This simplifies buffer handling. Misc.: clean some old error code handling. Signed-off-by: Pierre-Alexandre Meyer --- com32/gplinclude/disk/errno_disk.h | 3 --- com32/gpllib/disk/error.c | 7 +++---- com32/hdt/hdt-cli-disk.c | 15 ++++----------- com32/hdt/hdt-common.c | 7 ------- com32/hdt/hdt-menu-disk.c | 8 ++------ 5 files changed, 9 insertions(+), 31 deletions(-) diff --git a/com32/gplinclude/disk/errno_disk.h b/com32/gplinclude/disk/errno_disk.h index 055eaf5..60b511f 100644 --- a/com32/gplinclude/disk/errno_disk.h +++ b/com32/gplinclude/disk/errno_disk.h @@ -10,9 +10,6 @@ #ifndef _ERRNO_DISK_H #define _ERRNO_DISK_H -/* Max length of the error string */ -#define MAX_DISK_ERRNO 9 - extern int errno_disk; /* Prefix with ED to avoid confusion with errno */ diff --git a/com32/gpllib/disk/error.c b/com32/gpllib/disk/error.c index 2b82c35..1853092 100644 --- a/com32/gpllib/disk/error.c +++ b/com32/gpllib/disk/error.c @@ -8,8 +8,7 @@ * ----------------------------------------------------------------------- */ #include -#include - +#include #include /** @@ -18,7 +17,7 @@ * * Fill @buffer_ptr with the last errno_disk **/ -void get_error(void* buffer_ptr) +void get_error(const char* s) { - snprintf(buffer_ptr, MAX_DISK_ERRNO, "Disklib: error %d\n", errno_disk); + fprintf(stderr, "%s: error %d\n", s, errno_disk); } diff --git a/com32/hdt/hdt-cli-disk.c b/com32/hdt/hdt-cli-disk.c index 080e132..fec98a1 100644 --- a/com32/hdt/hdt-cli-disk.c +++ b/com32/hdt/hdt-cli-disk.c @@ -64,8 +64,6 @@ static void show_partition_information(struct driveinfo *drive_info, { char size[9]; char *parttype; - int error = 0; - char error_buffer[MAX_DISK_ERRNO]; unsigned int start, end; int i = nb_partitions_seen; @@ -90,12 +88,8 @@ static void show_partition_information(struct driveinfo *drive_info, ptab->ostype, parttype); /* Extra info */ - if (ptab->ostype == 0x82 && swsusp_check(drive_info, ptab)) { + if (ptab->ostype == 0x82 && swsusp_check(drive_info, ptab)) more_printf("%s", " (Swsusp sig. detected)"); - } else if (error) { - get_error(&error_buffer); - more_printf("%s\n", error_buffer); - } more_printf("\n"); @@ -120,7 +114,6 @@ void main_show_disk(int argc, char **argv, int i = drive - 0x80; struct driveinfo *d = &hardware->disk_info[i]; - char error_buffer[MAX_DISK_ERRNO]; char disk_size[9]; detect_disks(hardware); @@ -143,9 +136,9 @@ void main_show_disk(int argc, char **argv, disk_size, (int) d->edd_params.bytes_per_sector, (int) d->edd_params.sectors_per_track, remove_spaces(d->edd_params.host_bus_type), remove_spaces(d->edd_params.interface_type)); - if (parse_partition_table(d, &show_partition_information) == -1) { - get_error(&error_buffer); - more_printf("%s\n", error_buffer); + if (parse_partition_table(d, &show_partition_information)) { + fprintf(stderr, "Error parsing disk 0x%X\n", d->disk); + get_error("parse_partition_table"); } } diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index 0f98ab9..80305a3 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -252,7 +252,6 @@ void detect_disks(struct s_hardware *hardware) { int i = -1; int err; - char *error_msg; if (hardware->disk_detection) return; @@ -270,12 +269,6 @@ void detect_disks(struct s_hardware *hardware) if (err == -1 || !hardware->disk_info[i].cbios) continue; - if (err) { - get_error(err, &error_msg); - more_printf("Error 0x%Xh while reading disk 0x%X:\n\t%s\n", - err, drive, error_msg); - free(error_msg); - } hardware->disks_count++; } } diff --git a/com32/hdt/hdt-menu-disk.c b/com32/hdt/hdt-menu-disk.c index e564407..bd33bdf 100644 --- a/com32/hdt/hdt-menu-disk.c +++ b/com32/hdt/hdt-menu-disk.c @@ -210,12 +210,8 @@ static int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu, dn=disk_number; parse_partition_table(&d[disk_number], &show_partition_information); - if (parse_partition_table(&d[disk_number], &compute_partition_information) == -1) { - char error_buffer[MAX_DISK_ERRNO]; - get_error(&error_buffer); - snprintf(buffer, sizeof buffer, "I/O error : %s", error_buffer); - snprintf(statbuffer, sizeof statbuffer, "I/O error : %s", error_buffer); - add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); + if (!parse_partition_table(&d[disk_number], &compute_partition_information)) { + get_error("parse_partition_table"); menu[nb_sub_disk_menu].items_count++; } -- 2.7.4