reverse return code for safemult API to conform to newer djb APIs

master
leitner 21 years ago
parent f2d8be239f
commit ef0495b5e2

@ -60,7 +60,7 @@ $(DNS_OBJS): dns.h stralloc.h taia.h tai.h uint64.h iopause.h
$(CASE_OBJS): case.h
$(ARRAY_OBJS): uint64.h array.h
$(MULT_OBJS): uint64.h uint32.h uint16.h safemult.h
$(IO_OBJS): uint64.h array.h io.h
$(IO_OBJS): uint64.h array.h io.h io_internal.h taia.h tai.h
iopause.o: select.h
openreadclose.o readclose.o: readclose.h

@ -54,7 +54,7 @@ void* array_allocate(array* x,uint64 membersize,int64 pos) {
if (__unlikely(x->allocated<0)) return 0; /* array is failed */
if (__unlikely(pos+1<1)) return 0;
/* second case of overflow: pos*membersize too large */
if (__unlikely(umult64(membersize,pos+1,&wanted))) return 0;
if (__unlikely(!umult64(membersize,pos+1,&wanted))) return 0;
if (__unlikely(wanted > x->allocated)) {
/* round up a little */

@ -23,7 +23,7 @@
void* array_get(array* x,uint64 membersize,int64 pos) {
uint64 wanted;
if (__unlikely(pos+1<1)) return 0;
if (__unlikely(umult64(membersize,pos,&wanted))) return 0;
if (__unlikely(!umult64(membersize,pos,&wanted))) return 0;
if (__unlikely(wanted > x->allocated)) return 0;
return x->p+pos*membersize;

@ -11,7 +11,7 @@
void array_truncate(array* x,uint64 membersize,int64 len) {
uint64 wanted;
if (__unlikely(len<0)) return;
if (__unlikely(umult64(membersize,len,&wanted))) return;
if (__unlikely(!umult64(membersize,len,&wanted))) return;
if (__unlikely(wanted > x->initialized)) return;
x->initialized=wanted;
}

@ -5,30 +5,5 @@
#include "io_internal.h"
void io_wait() {
struct pollfd* p;
long i,r;
if (!io_wanted_fds) return;
for (i=r=0; i<array_length(&io_fds,sizeof(io_entry)); ++i) {
io_entry* e=array_get(&io_fds,sizeof(io_entry),i);
if (!e) return;
e->canread=e->canwrite=0;
if (e->wantread || e->wantwrite) {
struct pollfd* p;
if ((p=array_allocate(&io_pollfds,sizeof(struct pollfd),r))) {
p->fd=i;
p->events=(e->wantread?POLLIN:0) + (e->wantwrite?POLLOUT:0);
++r;
} else
return;
}
}
p=array_start(&io_pollfds);
while ((i=poll(array_start(&io_pollfds),r,99999999))==0);
if (i==-1) return;
for (i=0; i<r; ++i) {
io_entry* e=array_get(&io_fds,sizeof(io_entry),p->fd);
if (p->revents&POLLIN) e->canread=1;
if (p->revents&POLLOUT) e->canwrite=1;
p++;
}
io_waituntil2(-1);
}

@ -14,3 +14,5 @@ typedef struct {
array io_fds;
uint64 io_wanted_fds;
array io_pollfds;
int64 io_waituntil2(int64 milliseconds);

@ -4,7 +4,7 @@ int imult16(int16 a,int16 b,int16* c) {
int neg=(a<0);
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult16(a,b,c)) return 1;
if (umult16(a,b,c)) return 0;
if (neg) *c=-*c;
return 0;
return 1;
}

@ -4,7 +4,7 @@ int imult32(int32 a,int32 b,int32* c) {
int neg=(a<0);
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult32(a,b,c)) return 1;
if (umult32(a,b,c)) return 0;
if (neg) *c=-*c;
return 0;
return 1;
}

@ -4,8 +4,8 @@ int imult64(int64 a,int64 b,int64* c) {
int neg=(a<0);
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult64(a,b,c)) return 1;
if (umult64(a,b,c)) return 0;
if (neg) *c=-*c;
return 0;
return 1;
}

@ -2,7 +2,7 @@
int umult16(uint16 a,uint16 b,uint16* c) {
unsigned long x=(unsigned long)a*b;
if (x>0xffff) return 1;
if (x>0xffff) return 0;
*c=x&0xffff;
return 0;
return 1;
}

@ -2,7 +2,7 @@
int umult32(uint32 a,uint32 b,uint32* c) {
unsigned long long x=(unsigned long long)a*b;
if (x>0xffffffff) return 1;
if (x>0xffffffff) return 0;
*c=x&0xffffffff;
return 0;
return 1;
}

@ -12,11 +12,11 @@ int umult64(uint64 a,uint64 b,uint64* c) {
// = ahi*x*bhi*x + ahi*x*blo + alo*bhi*x + alo*blo
// -> overflow if ahi*bhi != zero */
if (ahi && bhi) return 1;
if (ahi && bhi) return 0;
a=(uint64)(ahi)*blo+(uint64)(alo)*bhi;
if (a>0xffffffff) return 1;
if (a>0xffffffff) return 0;
*c=(a<<32)+(uint64)(alo)*blo;
return 0;
return 1;
}

@ -5,7 +5,7 @@
#include "uint32.h"
#include "uint64.h"
/* return 1 for overflow, 0 for ok */
/* return 0 for overflow, 1 for ok */
int umult16(uint16 a,uint16 b,uint16* c);
int imult16( int16 a, int16 b, int16* c);

@ -15,4 +15,5 @@ main() {
assert(byte_equal(x.p,11,"fnordfoobar"));
array_cate(&x,&y,1,4);
assert(x.initialized=14 && byte_equal(x.p,14,"fnordfoobarnor"));
return 0;
}

Loading…
Cancel
Save