diff options
author | Denis Vlasenko | 2006-10-14 02:23:43 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-10-14 02:23:43 +0000 |
commit | ea62077b850076c4d7dc3cf78ebd1888928c6ddf (patch) | |
tree | 37b7584ae40b99edb5583fbc4392b62ffdadf278 /util-linux | |
parent | 88ca06769028e442bf873b270c176ca0e9f021f8 (diff) | |
download | busybox-ea62077b850076c4d7dc3cf78ebd1888928c6ddf.zip busybox-ea62077b850076c4d7dc3cf78ebd1888928c6ddf.tar.gz |
add open_read_close() and similar stuff
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/hwclock.c | 8 | ||||
-rw-r--r-- | util-linux/mdev.c | 4 | ||||
-rw-r--r-- | util-linux/readprofile.c | 24 |
3 files changed, 11 insertions, 25 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index cce3133..1aff87c 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c @@ -51,11 +51,11 @@ static time_t read_rtc(int utc) if (( rtc = open ( "/dev/rtc", O_RDONLY )) < 0 ) { if (( rtc = open ( "/dev/misc/rtc", O_RDONLY )) < 0 ) - bb_perror_msg_and_die ( "Could not access RTC" ); + bb_perror_msg_and_die ( "cannot access RTC" ); } memset ( &tm, 0, sizeof( struct tm )); if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 ) - bb_perror_msg_and_die ( "Could not read time from RTC" ); + bb_perror_msg_and_die ( "cannot read time from RTC" ); tm.tm_isdst = -1; /* not known */ close ( rtc ); @@ -85,14 +85,14 @@ static void write_rtc(time_t t, int utc) if (( rtc = open ( "/dev/rtc", O_WRONLY )) < 0 ) { if (( rtc = open ( "/dev/misc/rtc", O_WRONLY )) < 0 ) - bb_perror_msg_and_die ( "Could not access RTC" ); + bb_perror_msg_and_die ( "cannot access RTC" ); } tm = *( utc ? gmtime ( &t ) : localtime ( &t )); tm.tm_isdst = 0; if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) - bb_perror_msg_and_die ( "Could not set the RTC time" ); + bb_perror_msg_and_die ( "cannot set the RTC time" ); close ( rtc ); } diff --git a/util-linux/mdev.c b/util-linux/mdev.c index f433936..1df144f 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -39,10 +39,8 @@ static void make_device(char *path, int delete) if (!delete) { strcat(path, "/dev"); - fd = open(path, O_RDONLY); - len = read(fd, temp + 1, 64); + len = open_read_close(path, temp + 1, 64); *temp++ = 0; - close(fd); if (len < 1) return; } diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index b368067..e635f6b 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c @@ -44,9 +44,9 @@ static const char defaultpro[] = "/proc/profile"; int readprofile_main(int argc, char **argv) { FILE *map; - int proFd; const char *mapFile, *proFile, *mult=0; - unsigned long len=0, indx=1; + unsigned long indx=1; + size_t len; uint64_t add0=0; unsigned int step; unsigned int *buf, total, fn_len; @@ -97,20 +97,8 @@ int readprofile_main(int argc, char **argv) /* * Use an fd for the profiling buffer, to skip stdio overhead */ - - proFd = xopen(proFile,O_RDONLY); - - if (((int)(len=lseek(proFd,0,SEEK_END)) < 0) - || (lseek(proFd,0,SEEK_SET) < 0)) - bb_perror_msg_and_die(proFile); - - buf = xmalloc(len); - - if (read(proFd,buf,len) != len) - bb_perror_msg_and_die(proFile); - - close(proFd); - + len = INT_MAX; + buf = xmalloc_open_read_close(proFile, &len); if (!optNative) { int entries = len/sizeof(*buf); int big = 0,small = 0,i; @@ -123,8 +111,8 @@ int readprofile_main(int argc, char **argv) small++; } if (big > small) { - bb_error_msg("Assuming reversed byte order. " - "Use -n to force native byte order."); + bb_error_msg("assuming reversed byte order, " + "use -n to force native byte order"); for (p = buf; p < buf+entries; p++) for (i = 0; i < sizeof(*buf)/2; i++) { unsigned char *b = (unsigned char *) p; |