add io_fd_canwrite (like io_fd but assume the fd is writable)

save a few syscalls here and there
This commit is contained in:
leitner
2012-04-10 21:15:51 +00:00
parent 6e6fc8b85d
commit e175800a8c
15 changed files with 322 additions and 63 deletions

View File

@@ -6,7 +6,7 @@
#include <errmsg.h>
#ifndef O_BINARY
#define O_BINARY
#define O_BINARY 0
#endif
int main(int argc,char* argv[]) {

View File

@@ -303,7 +303,8 @@ invalidpart:
continue;
} else if (str_start(line,"=yend")) {
/* first try to decode it normally and see if the CRC matches */
unsigned long i,wantedcrc;
unsigned long i,wantedcrc,gotcrc;
gotcrc=0;
stralloc out;
char* tmp=strstr(line," pcrc32=");
@@ -311,12 +312,14 @@ invalidpart:
if (!scan_xlong(tmp+8,&wantedcrc))
goto invalidpart;
wantedcrc &= 0xfffffffful;
gotcrc=1;
} else if (part==1) {
tmp=strstr(line," crc32=");
if (!tmp) goto invalidpart;
if (!scan_xlong(tmp+7,&wantedcrc))
goto invalidpart;
wantedcrc &= 0xfffffffful;
gotcrc=1;
endoffset=totalsize;
} else goto invalidpart;
stralloc_init(&out);
@@ -345,6 +348,7 @@ writeerror:
i+=x+1; out.len+=scanned;
}
i=crc32(0,out.s,out.len);
if (!gotcrc) wantedcrc=i;
if (out.len == endoffset-offset && i == wantedcrc) {
if (buffer_put(&fileout,out.s,out.len)) goto writeerror;
++reconstructed;