瀏覽代碼

turns out the imult routines (which I never used) were incorrect.

Noted by Matthew Dempsky
  open_* from open.h now open in large file mode
master
Felix von Leitner 15 年之前
父節點
當前提交
237ff729b3
共有 12 個檔案被更改,包括 61 行新增13 行删除
  1. +3
    -0
      CHANGES
  2. +3
    -6
      mult/imult16.c
  3. +3
    -6
      mult/imult32.c
  4. +2
    -1
      mult/imult64.c
  5. +1
    -0
      open/open_append.c
  6. +1
    -0
      open/open_excl.c
  7. +1
    -0
      open/open_read.c
  8. +1
    -0
      open/open_rw.c
  9. +1
    -0
      open/open_trunc.c
  10. +1
    -0
      open/open_write.c
  11. +18
    -0
      t.c
  12. +26
    -0
      test/mult.c

+ 3
- 0
CHANGES 查看文件

@@ -4,6 +4,9 @@
if _XOPEN_SOURCE is defined, which is needed for Solaris.
OpenBSD sucks. I checked in a _really_ kludge now. Please do not
use OpenBSD if you have a choice. Or Solaris, for that matter.
turns out the imult routines (which I never used) were incorrect.
Noted by Matthew Dempsky
open_* from open.h now open in large file mode

0.23:
also recognize EPFNOSUPPORT as EAFNOSUPPORT (groan)


+ 3
- 6
mult/imult16.c 查看文件

@@ -1,11 +1,8 @@
#include "safemult.h"

int imult16(int16 a,int16 b,int16* c) {
int neg=(a<0);
uint16 d;
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult16(a,b,&d)) return 0;
*c=(neg?-d:d);
int32 x=(int32)a*b;
if ((int16)x != x) return 0;
*c=x;
return 1;
}

+ 3
- 6
mult/imult32.c 查看文件

@@ -1,11 +1,8 @@
#include "safemult.h"

int imult32(int32 a,int32 b,int32* c) {
int neg=(a<0);
uint32 d;
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult32(a,b,&d)) return 0;
*c=(neg?-d:d);
int64 x=(int64)a*b;
if ((int32)x != x) return 0;
*c=x;
return 1;
}

+ 2
- 1
mult/imult64.c 查看文件

@@ -5,7 +5,8 @@ int imult64(int64 a,int64 b,int64* c) {
uint64 d;
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult64(a,b,&d)) return 0;
if (!umult64(a,b,&d)) return 0;
if (d > 0x7fffffffffffffffULL + neg) return 0;
*c=(neg?-d:d);
return 1;
}


+ 1
- 0
open/open_append.c 查看文件

@@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"


+ 1
- 0
open/open_excl.c 查看文件

@@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"


+ 1
- 0
open/open_read.c 查看文件

@@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"


+ 1
- 0
open/open_rw.c 查看文件

@@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"


+ 1
- 0
open/open_trunc.c 查看文件

@@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"


+ 1
- 0
open/open_write.c 查看文件

@@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"


+ 18
- 0
t.c 查看文件

@@ -21,6 +21,7 @@
#include <assert.h>
#include "errmsg.h"
#include "iob.h"
#include "safemult.h"

#define rdtscl(low) \
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
@@ -328,8 +329,25 @@ int main(int argc,char* argv[]) {
write(1,tmp,x);
}
#endif
#if 0
printf("%d %d\n",strcmp("foo","bar"),str_diff("foo","bar"));
printf("%d %d\n",strcmp("foo","üar"),str_diff("foo","üar"));
return 0;
#endif
{
int16 a;
int32 b;
int64 c;
assert(imult16(4,10000,&a)==0);
assert(imult16(-4,10000,&a)==0);
assert(imult16(5,10,&a)==1 && a==50);
assert(imult16(-3,10000,&a)==1 && a==-30000);

assert(imult32(0x40000000,2,&b)==0);
assert(imult32(0x3fffffff,2,&b)==1 && b==0x7ffffffe);

assert(imult64(0x4000000000000000ll,2,&c)==0);
assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell);
}
}


+ 26
- 0
test/mult.c 查看文件

@@ -0,0 +1,26 @@
#include <assert.h>
#include "safemult.h"

int main() {
int16 a;
int32 b;
int64 c;
uint16 d;
uint32 e;
uint64 f;

assert(imult16(4,10000,&a)==0);
assert(imult16(-4,10000,&a)==0);
assert(imult16(5,10,&a)==1 && a==50);
assert(imult16(-3,10000,&a)==1 && a==-30000);

assert(imult32(0x40000000,2,&b)==0);
assert(imult32(-0x40000000,2,&b)==1 && b==-0x80000000);
assert(imult32(0x3fffffff,2,&b)==1 && b==0x7ffffffe);

assert(imult64(0x4000000000000000ll,2,&c)==0);
assert(imult64(-0x4000000000000000ll,2,&c)==1 && c==-0x8000000000000000ll);
assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell);

return 0;
}

Loading…
取消
儲存