mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
make flate crc32 work when ulong is 64 bits
R=, rsc CC= http://codereview.appspot.com/203061
This commit is contained in:
parent
28afa898ee
commit
9a05452085
7 changed files with 25 additions and 19 deletions
|
@ -42,10 +42,10 @@ int deflatezlibblock(uchar *dst, int dsize, uchar *src, int ssize, int level, in
|
||||||
|
|
||||||
char *flateerr(int err);
|
char *flateerr(int err);
|
||||||
|
|
||||||
ulong *mkcrctab(ulong);
|
uint32 *mkcrctab(uint32);
|
||||||
ulong blockcrc(ulong *tab, ulong crc, void *buf, int n);
|
uint32 blockcrc(uint32 *tab, uint32 crc, void *buf, int n);
|
||||||
|
|
||||||
ulong adler32(ulong adler, void *buf, int n);
|
uint32 adler32(uint32 adler, void *buf, int n);
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -157,6 +157,13 @@ typedef intptr_t intptr;
|
||||||
typedef uint32_t u32int;
|
typedef uint32_t u32int;
|
||||||
typedef int32_t s32int;
|
typedef int32_t s32int;
|
||||||
|
|
||||||
|
typedef u32int uint32;
|
||||||
|
typedef s32int int32;
|
||||||
|
typedef u16int uint16;
|
||||||
|
typedef s16int int16;
|
||||||
|
typedef u64int uint64;
|
||||||
|
typedef s64int int64;
|
||||||
|
|
||||||
#undef _NEEDUCHAR
|
#undef _NEEDUCHAR
|
||||||
#undef _NEEDUSHORT
|
#undef _NEEDUSHORT
|
||||||
#undef _NEEDUINT
|
#undef _NEEDUINT
|
||||||
|
|
|
@ -44,11 +44,11 @@ typedef struct ZlibR{
|
||||||
ZlibW *w;
|
ZlibW *w;
|
||||||
} ZlibR;
|
} ZlibR;
|
||||||
|
|
||||||
static ulong *crctab;
|
static uint32 *crctab;
|
||||||
static uchar PNGmagic[] = {137,80,78,71,13,10,26,10};
|
static uchar PNGmagic[] = {137,80,78,71,13,10,26,10};
|
||||||
static char memerr[] = "ReadPNG: malloc failed: %r";
|
static char memerr[] = "ReadPNG: malloc failed: %r";
|
||||||
|
|
||||||
static ulong
|
static uint32
|
||||||
get4(uchar *a)
|
get4(uchar *a)
|
||||||
{
|
{
|
||||||
return (a[0]<<24) | (a[1]<<16) | (a[2]<<8) | a[3];
|
return (a[0]<<24) | (a[1]<<16) | (a[2]<<8) | a[3];
|
||||||
|
@ -87,7 +87,7 @@ static int
|
||||||
getchunk(Biobuf *b, char *type, uchar *d, int m)
|
getchunk(Biobuf *b, char *type, uchar *d, int m)
|
||||||
{
|
{
|
||||||
uchar buf[8];
|
uchar buf[8];
|
||||||
ulong crc = 0, crc2;
|
uint32 crc = 0, crc2;
|
||||||
int n, nr;
|
int n, nr;
|
||||||
|
|
||||||
if(Bread(b, buf, 8) != 8)
|
if(Bread(b, buf, 8) != 8)
|
||||||
|
|
|
@ -31,11 +31,11 @@ typedef struct ZlibW{
|
||||||
uchar *e; /* past end of buf */
|
uchar *e; /* past end of buf */
|
||||||
} ZlibW;
|
} ZlibW;
|
||||||
|
|
||||||
static ulong *crctab;
|
static uint32 *crctab;
|
||||||
static uchar PNGmagic[] = {137,80,78,71,13,10,26,10};
|
static uchar PNGmagic[] = {137,80,78,71,13,10,26,10};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
put4(uchar *a, ulong v)
|
put4(uchar *a, uint32 v)
|
||||||
{
|
{
|
||||||
a[0] = v>>24;
|
a[0] = v>>24;
|
||||||
a[1] = v>>16;
|
a[1] = v>>16;
|
||||||
|
@ -47,7 +47,7 @@ static void
|
||||||
chunk(Biobuf *bo, char *type, uchar *d, int n)
|
chunk(Biobuf *bo, char *type, uchar *d, int n)
|
||||||
{
|
{
|
||||||
uchar buf[4];
|
uchar buf[4];
|
||||||
ulong crc = 0;
|
uint32 crc = 0;
|
||||||
|
|
||||||
if(strlen(type) != 4)
|
if(strlen(type) != 4)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
typedef s32int int32;
|
|
||||||
|
|
||||||
#define DIR "#9/sky"
|
#define DIR "#9/sky"
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -8,10 +8,10 @@ enum
|
||||||
ADLERBASE = 65521 /* largest prime smaller than 65536 */
|
ADLERBASE = 65521 /* largest prime smaller than 65536 */
|
||||||
};
|
};
|
||||||
|
|
||||||
ulong
|
uint32
|
||||||
adler32(ulong adler, void *vbuf, int n)
|
adler32(uint32 adler, void *vbuf, int n)
|
||||||
{
|
{
|
||||||
ulong s1, s2;
|
uint32 s1, s2;
|
||||||
uchar *buf, *ebuf;
|
uchar *buf, *ebuf;
|
||||||
int m;
|
int m;
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include <flate.h>
|
#include <flate.h>
|
||||||
|
|
||||||
ulong*
|
uint32*
|
||||||
mkcrctab(ulong poly)
|
mkcrctab(uint32 poly)
|
||||||
{
|
{
|
||||||
ulong *crctab;
|
uint32 *crctab;
|
||||||
ulong crc;
|
uint32 crc;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
crctab = malloc(256 * sizeof(ulong));
|
crctab = malloc(256 * sizeof(ulong));
|
||||||
|
@ -26,8 +26,8 @@ mkcrctab(ulong poly)
|
||||||
return crctab;
|
return crctab;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong
|
uint32
|
||||||
blockcrc(ulong *crctab, ulong crc, void *vbuf, int n)
|
blockcrc(uint32 *crctab, uint32 crc, void *vbuf, int n)
|
||||||
{
|
{
|
||||||
uchar *buf, *ebuf;
|
uchar *buf, *ebuf;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue