aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-14 02:23:43 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-14 02:23:43 +0000
commitea62077b850076c4d7dc3cf78ebd1888928c6ddf (patch)
tree37b7584ae40b99edb5583fbc4392b62ffdadf278 /util-linux
parent88ca06769028e442bf873b270c176ca0e9f021f8 (diff)
downloadbusybox-w32-ea62077b850076c4d7dc3cf78ebd1888928c6ddf.tar.gz
busybox-w32-ea62077b850076c4d7dc3cf78ebd1888928c6ddf.tar.bz2
busybox-w32-ea62077b850076c4d7dc3cf78ebd1888928c6ddf.zip
add open_read_close() and similar stuff
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/hwclock.c8
-rw-r--r--util-linux/mdev.c4
-rw-r--r--util-linux/readprofile.c24
3 files changed, 11 insertions, 25 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index cce31335e..1aff87c11 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -51,11 +51,11 @@ static time_t read_rtc(int utc)
51 51
52 if (( rtc = open ( "/dev/rtc", O_RDONLY )) < 0 ) { 52 if (( rtc = open ( "/dev/rtc", O_RDONLY )) < 0 ) {
53 if (( rtc = open ( "/dev/misc/rtc", O_RDONLY )) < 0 ) 53 if (( rtc = open ( "/dev/misc/rtc", O_RDONLY )) < 0 )
54 bb_perror_msg_and_die ( "Could not access RTC" ); 54 bb_perror_msg_and_die ( "cannot access RTC" );
55 } 55 }
56 memset ( &tm, 0, sizeof( struct tm )); 56 memset ( &tm, 0, sizeof( struct tm ));
57 if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 ) 57 if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 )
58 bb_perror_msg_and_die ( "Could not read time from RTC" ); 58 bb_perror_msg_and_die ( "cannot read time from RTC" );
59 tm.tm_isdst = -1; /* not known */ 59 tm.tm_isdst = -1; /* not known */
60 60
61 close ( rtc ); 61 close ( rtc );
@@ -85,14 +85,14 @@ static void write_rtc(time_t t, int utc)
85 85
86 if (( rtc = open ( "/dev/rtc", O_WRONLY )) < 0 ) { 86 if (( rtc = open ( "/dev/rtc", O_WRONLY )) < 0 ) {
87 if (( rtc = open ( "/dev/misc/rtc", O_WRONLY )) < 0 ) 87 if (( rtc = open ( "/dev/misc/rtc", O_WRONLY )) < 0 )
88 bb_perror_msg_and_die ( "Could not access RTC" ); 88 bb_perror_msg_and_die ( "cannot access RTC" );
89 } 89 }
90 90
91 tm = *( utc ? gmtime ( &t ) : localtime ( &t )); 91 tm = *( utc ? gmtime ( &t ) : localtime ( &t ));
92 tm.tm_isdst = 0; 92 tm.tm_isdst = 0;
93 93
94 if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) 94 if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 )
95 bb_perror_msg_and_die ( "Could not set the RTC time" ); 95 bb_perror_msg_and_die ( "cannot set the RTC time" );
96 96
97 close ( rtc ); 97 close ( rtc );
98} 98}
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index f43393692..1df144fa9 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -39,10 +39,8 @@ static void make_device(char *path, int delete)
39 39
40 if (!delete) { 40 if (!delete) {
41 strcat(path, "/dev"); 41 strcat(path, "/dev");
42 fd = open(path, O_RDONLY); 42 len = open_read_close(path, temp + 1, 64);
43 len = read(fd, temp + 1, 64);
44 *temp++ = 0; 43 *temp++ = 0;
45 close(fd);
46 if (len < 1) return; 44 if (len < 1) return;
47 } 45 }
48 46
diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c
index b368067ef..e635f6bf3 100644
--- a/util-linux/readprofile.c
+++ b/util-linux/readprofile.c
@@ -44,9 +44,9 @@ static const char defaultpro[] = "/proc/profile";
44int readprofile_main(int argc, char **argv) 44int readprofile_main(int argc, char **argv)
45{ 45{
46 FILE *map; 46 FILE *map;
47 int proFd;
48 const char *mapFile, *proFile, *mult=0; 47 const char *mapFile, *proFile, *mult=0;
49 unsigned long len=0, indx=1; 48 unsigned long indx=1;
49 size_t len;
50 uint64_t add0=0; 50 uint64_t add0=0;
51 unsigned int step; 51 unsigned int step;
52 unsigned int *buf, total, fn_len; 52 unsigned int *buf, total, fn_len;
@@ -97,20 +97,8 @@ int readprofile_main(int argc, char **argv)
97 /* 97 /*
98 * Use an fd for the profiling buffer, to skip stdio overhead 98 * Use an fd for the profiling buffer, to skip stdio overhead
99 */ 99 */
100 100 len = INT_MAX;
101 proFd = xopen(proFile,O_RDONLY); 101 buf = xmalloc_open_read_close(proFile, &len);
102
103 if (((int)(len=lseek(proFd,0,SEEK_END)) < 0)
104 || (lseek(proFd,0,SEEK_SET) < 0))
105 bb_perror_msg_and_die(proFile);
106
107 buf = xmalloc(len);
108
109 if (read(proFd,buf,len) != len)
110 bb_perror_msg_and_die(proFile);
111
112 close(proFd);
113
114 if (!optNative) { 102 if (!optNative) {
115 int entries = len/sizeof(*buf); 103 int entries = len/sizeof(*buf);
116 int big = 0,small = 0,i; 104 int big = 0,small = 0,i;
@@ -123,8 +111,8 @@ int readprofile_main(int argc, char **argv)
123 small++; 111 small++;
124 } 112 }
125 if (big > small) { 113 if (big > small) {
126 bb_error_msg("Assuming reversed byte order. " 114 bb_error_msg("assuming reversed byte order, "
127 "Use -n to force native byte order."); 115 "use -n to force native byte order");
128 for (p = buf; p < buf+entries; p++) 116 for (p = buf; p < buf+entries; p++)
129 for (i = 0; i < sizeof(*buf)/2; i++) { 117 for (i = 0; i < sizeof(*buf)/2; i++) {
130 unsigned char *b = (unsigned char *) p; 118 unsigned char *b = (unsigned char *) p;