diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-14 02:23:43 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-14 02:23:43 +0000 |
commit | ea62077b850076c4d7dc3cf78ebd1888928c6ddf (patch) | |
tree | 37b7584ae40b99edb5583fbc4392b62ffdadf278 /util-linux/readprofile.c | |
parent | 88ca06769028e442bf873b270c176ca0e9f021f8 (diff) | |
download | busybox-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/readprofile.c')
-rw-r--r-- | util-linux/readprofile.c | 24 |
1 files changed, 6 insertions, 18 deletions
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"; | |||
44 | int readprofile_main(int argc, char **argv) | 44 | int 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; |