From 72bcf1898b3fb6ebb11f65a9b5b1980eafbc9c21 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 21 Mar 2007 16:21:34 +0100 Subject: [PATCH] hwclock: make ggc happy and check return values from fgets, read and write Signed-off-by: Karel Zak --- hwclock/cmos.c | 12 ++++++++---- hwclock/hwclock.c | 18 +++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/hwclock/cmos.c b/hwclock/cmos.c index 93f74294..ca3ca61e 100644 --- a/hwclock/cmos.c +++ b/hwclock/cmos.c @@ -290,9 +290,11 @@ unsigned long cmos_read(unsigned long reg) if (use_dev_port) { unsigned char v = reg | 0x80; lseek(dev_port_fd, clock_ctl_addr, 0); - write(dev_port_fd, &v, 1); + if (write(dev_port_fd, &v, 1) == -1 && debug) + printf("cmos_read(): write to control address %X failed: %s\n", clock_ctl_addr, strerror(errno)); lseek(dev_port_fd, clock_data_addr, 0); - read(dev_port_fd, &v, 1); + if (read(dev_port_fd, &v, 1) == -1 && debug) + printf("cmos_read(): read data address %X failed: %s\n", clock_data_addr, strerror(errno)); return v; } else { /* We only want to read CMOS data, but unfortunately @@ -322,10 +324,12 @@ unsigned long cmos_write(unsigned long reg, unsigned long val) if (use_dev_port) { unsigned char v = reg | 0x80; lseek(dev_port_fd, clock_ctl_addr, 0); - write(dev_port_fd, &v, 1); + if (write(dev_port_fd, &v, 1) == -1 && debug) + printf("cmos_write(): write to control address %X failed: %s\n", clock_ctl_addr, strerror(errno)); v = (val & 0xff); lseek(dev_port_fd, clock_data_addr, 0); - write(dev_port_fd, &v, 1); + if (write(dev_port_fd, &v, 1) == -1 && debug) + printf("cmos_write(): write to data address %X failed: %s\n", clock_data_addr, strerror(errno)); } else { outb (reg, clock_ctl_addr); outb (val, clock_data_addr); diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c index ee6309cb..4b4d3ee8 100644 --- a/hwclock/hwclock.c +++ b/hwclock/hwclock.c @@ -273,12 +273,12 @@ read_adjtime(struct adjtime *adjtime_p) { char line3[81]; /* String: third line of adjtime file */ long timeval; - line1[0] = '\0'; /* In case fgets fails */ - fgets(line1, sizeof(line1), adjfile); - line2[0] = '\0'; /* In case fgets fails */ - fgets(line2, sizeof(line2), adjfile); - line3[0] = '\0'; /* In case fgets fails */ - fgets(line3, sizeof(line3), adjfile); + if (!fgets(line1, sizeof(line1), adjfile)) + line1[0] = '\0'; /* In case fgets fails */ + if (!fgets(line2, sizeof(line2), adjfile)) + line2[0] = '\0'; /* In case fgets fails */ + if (!fgets(line3, sizeof(line3), adjfile)) + line3[0] = '\0'; /* In case fgets fails */ fclose(adjfile); @@ -627,8 +627,8 @@ interpret_date_string(const char *date_opt, time_t * const time_p) { return 10; } - date_resp[0] = '\0'; /* in case fgets fails */ - fgets(date_resp, sizeof(date_resp), date_child_fp); + if (!fgets(date_resp, sizeof(date_resp), date_child_fp)) + date_resp[0] = '\0'; /* in case fgets fails */ if (debug) printf(_("response from date command = %s\n"), date_resp); if (strncmp(date_resp, magic, sizeof(magic)-1) != 0) { @@ -1296,7 +1296,7 @@ main(int argc, char **argv) { struct timeval startup_time; /* The time we started up, in seconds into the epoch, including fractions. */ - time_t set_time; /* Time to which user said to set Hardware Clock */ + time_t set_time = 0; /* Time to which user said to set Hardware Clock */ bool permitted; /* User is permitted to do the function */ int rc, c; -- 2.39.5