aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs.c
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 /libbb/xfuncs.c
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 'libbb/xfuncs.c')
-rw-r--r--libbb/xfuncs.c32
1 files changed, 7 insertions, 25 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index efc919491..0a5abb878 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -95,7 +95,7 @@ int xopen(const char *pathname, int flags)
95 if (ENABLE_DEBUG && (flags & O_CREAT)) 95 if (ENABLE_DEBUG && (flags & O_CREAT))
96 bb_error_msg_and_die("xopen() with O_CREAT"); 96 bb_error_msg_and_die("xopen() with O_CREAT");
97 97
98 return xopen3(pathname, flags, 0777); 98 return xopen3(pathname, flags, 0666);
99} 99}
100 100
101// Die if we can't open a new file and return an fd. 101// Die if we can't open a new file and return an fd.
@@ -110,16 +110,6 @@ int xopen3(const char *pathname, int flags, int mode)
110 return ret; 110 return ret;
111} 111}
112 112
113// Die with an error message if we can't read the entire buffer.
114void xread(int fd, void *buf, size_t count)
115{
116 if (count) {
117 ssize_t size = full_read(fd, buf, count);
118 if (size != count)
119 bb_error_msg_and_die("short read");
120 }
121}
122
123// Die with an error message if we can't write the entire buffer. 113// Die with an error message if we can't write the entire buffer.
124void xwrite(int fd, void *buf, size_t count) 114void xwrite(int fd, void *buf, size_t count)
125{ 115{
@@ -131,20 +121,12 @@ void xwrite(int fd, void *buf, size_t count)
131} 121}
132 122
133// Die with an error message if we can't lseek to the right spot. 123// Die with an error message if we can't lseek to the right spot.
134void xlseek(int fd, off_t offset, int whence) 124off_t xlseek(int fd, off_t offset, int whence)
135{ 125{
136 if (offset != lseek(fd, offset, whence)) 126 off_t off = lseek(fd, offset, whence);
137 bb_error_msg_and_die("lseek"); 127 if (off == (off_t)-1)
138} 128 bb_perror_msg_and_die("lseek");
139 129 return off;
140// Die with an error message if we can't read one character.
141unsigned char xread_char(int fd)
142{
143 char tmp;
144
145 xread(fd, &tmp, 1);
146
147 return tmp;
148} 130}
149 131
150// Die with supplied error message if this FILE * has ferror set. 132// Die with supplied error message if this FILE * has ferror set.
@@ -309,7 +291,7 @@ off_t fdlength(int fd)
309 291
310 // If we can read from the current location, it's bigger. 292 // If we can read from the current location, it's bigger.
311 293
312 if (lseek(fd, pos, 0)>=0 && safe_read(fd, &temp, 1)==1) { 294 if (lseek(fd, pos, SEEK_SET)>=0 && safe_read(fd, &temp, 1)==1) {
313 if (bottom == top) bottom = top = (top+1) * 2; 295 if (bottom == top) bottom = top = (top+1) * 2;
314 else bottom = pos; 296 else bottom = pos;
315 297