changed uint32_t to uint32

This commit is contained in:
Leopold Toetsch 2000-09-19 16:30:52 +00:00
parent de7694e0f2
commit c24677522b
17 changed files with 95 additions and 97 deletions

View File

@ -44,7 +44,7 @@ void cdb_free(struct cdb *cdb) {
void cdb_findstart(struct cdb *cdb) { void cdb_findstart(struct cdb *cdb) {
} }
int cdb_read(struct cdb *cdb, char *buf,unsigned int len, uint32_t pos) { int cdb_read(struct cdb *cdb, char *buf,unsigned int len, uint32 pos) {
/* actually we don't need pos, because the previous findnext /* actually we don't need pos, because the previous findnext
postioned us correctly postioned us correctly
if you want to have a real read - you know what to do */ if you want to have a real read - you know what to do */
@ -53,7 +53,7 @@ int cdb_read(struct cdb *cdb, char *buf,unsigned int len, uint32_t pos) {
} }
int cdb_findnext(struct cdb *cdb ,char *key, unsigned int len) { int cdb_findnext(struct cdb *cdb ,char *key, unsigned int len) {
uint32_t dlen; uint32 dlen;
int ret = cdb_seek(cdb->fd, key, len, &dlen); int ret = cdb_seek(cdb->fd, key, len, &dlen);
if (ret == 1) { /* found */ if (ret == 1) { /* found */
cdb->dlen = dlen; cdb->dlen = dlen;
@ -78,7 +78,7 @@ int cdb_make_start(struct cdb_make *c,int fd) {
return 0; return 0;
} }
static inline uint32_t safeadd(u,v) uint32_t u; uint32_t v; static inline uint32 safeadd(u,v) uint32 u; uint32 v;
{ {
u += v; u += v;
// if (u < v) overflow(); we don't ;-) // if (u < v) overflow(); we don't ;-)
@ -90,12 +90,12 @@ static inline uint32_t safeadd(u,v) uint32_t u; uint32_t v;
so no problem. so no problem.
*/ */
int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) { int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) {
uint32_t h, pos; uint32 h, pos;
int i , ch; int i , ch;
pos = c->pos; pos = c->pos;
cdbmake_pack(packbuf,(uint32_t) keylen); cdbmake_pack(packbuf,(uint32) keylen);
cdbmake_pack(packbuf + 4,(uint32_t) datalen); cdbmake_pack(packbuf + 4,(uint32) datalen);
if (write(c->fd,packbuf,8) != 8) if (write(c->fd,packbuf,8) != 8)
return -1; return -1;
h = CDBMAKE_HASHSTART; h = CDBMAKE_HASHSTART;
@ -112,16 +112,16 @@ int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,uns
} }
if (!cdbmake_add(&c->cdbm,h,pos,malloc)) if (!cdbmake_add(&c->cdbm,h,pos,malloc))
return -1; return -1;
pos = safeadd(pos,(uint32_t) 8); pos = safeadd(pos,(uint32) 8);
pos = safeadd(pos,(uint32_t) keylen); pos = safeadd(pos,(uint32) keylen);
pos = safeadd(pos,(uint32_t) datalen); pos = safeadd(pos,(uint32) datalen);
c->pos = pos; c->pos = pos;
return 0; return 0;
} }
int cdb_make_finish(struct cdb_make *c) { int cdb_make_finish(struct cdb_make *c) {
int i, u; int i, u;
uint32_t len, pos; uint32 len, pos;
pos = c->pos; pos = c->pos;
if (!cdbmake_split(&c->cdbm,malloc)) if (!cdbmake_split(&c->cdbm,malloc))
@ -134,7 +134,7 @@ int cdb_make_finish(struct cdb_make *c) {
cdbmake_pack(packbuf + 4,c->cdbm.hash[u].p); cdbmake_pack(packbuf + 4,c->cdbm.hash[u].p);
if (write(c->fd,packbuf,8) != 8) if (write(c->fd,packbuf,8) != 8)
return -1; return -1;
pos = safeadd(pos,(uint32_t) 8); pos = safeadd(pos,(uint32) 8);
} }
} }
lseek(c->fd, 0, SEEK_SET); lseek(c->fd, 0, SEEK_SET);

View File

@ -3,17 +3,15 @@
#include "freecdb.h" #include "freecdb.h"
typedef uint32_t uint32;
struct cdb { struct cdb {
int fd; int fd;
uint32_t dpos; uint32 dpos;
uint32_t dlen; uint32 dlen;
} ; } ;
void cdb_init(struct cdb *cdb, int fd); void cdb_init(struct cdb *cdb, int fd);
void cdb_free(struct cdb *cdb); void cdb_free(struct cdb *cdb);
int cdb_read(struct cdb *cdb, char *buf,unsigned int len, uint32_t pos); int cdb_read(struct cdb *cdb, char *buf,unsigned int len, uint32 pos);
void cdb_findstart(struct cdb *cdb); void cdb_findstart(struct cdb *cdb);
int cdb_findnext(struct cdb *cdb ,char *key, unsigned int len); int cdb_findnext(struct cdb *cdb ,char *key, unsigned int len);

View File

@ -1,16 +1,16 @@
#include "freecdb.h" #include "freecdb.h"
uint32_t cdb_hash(buf,len) uint32 cdb_hash(buf,len)
unsigned char *buf; unsigned char *buf;
unsigned int len; unsigned int len;
{ {
uint32_t h; uint32 h;
h = 5381; h = 5381;
while (len) { while (len) {
--len; --len;
h += (h << 5); h += (h << 5);
h ^= (uint32_t) *buf++; h ^= (uint32) *buf++;
} }
return h; return h;
} }

View File

@ -7,7 +7,7 @@
struct cdb_make{ struct cdb_make{
int fd; int fd;
struct cdbmake cdbm; struct cdbmake cdbm;
uint32_t pos; uint32 pos;
}; };
#define cdb_datapos(c) ((c)->dpos) #define cdb_datapos(c) ((c)->dpos)

View File

@ -51,15 +51,15 @@ int cdb_seek(fd,key,len,dlen)
int fd; int fd;
char *key; char *key;
unsigned int len; unsigned int len;
uint32_t *dlen; uint32 *dlen;
{ {
char packbuf[8]; char packbuf[8];
uint32_t pos; uint32 pos;
uint32_t h; uint32 h;
uint32_t lenhash; uint32 lenhash;
uint32_t h2; uint32 h2;
uint32_t loop; uint32 loop;
uint32_t poskd; uint32 poskd;
h = cdb_hash(key,len); h = cdb_hash(key,len);

View File

@ -1,9 +1,9 @@
#include "freecdb.h" #include "freecdb.h"
uint32_t cdb_unpack(buf) uint32 cdb_unpack(buf)
unsigned char *buf; unsigned char *buf;
{ {
uint32_t num; uint32 num;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
num = buf[0]; num <<= 8; num = buf[0]; num <<= 8;
num += buf[1]; num <<= 8; num += buf[1]; num <<= 8;

View File

@ -15,10 +15,10 @@ void readerror()
int main() int main()
{ {
uint32_t eod; uint32 eod;
uint32_t pos; uint32 pos;
uint32_t klen; uint32 klen;
uint32_t dlen; uint32 dlen;
char buf[8]; char buf[8];
int i; int i;
int c; int c;

View File

@ -5,7 +5,7 @@ int main(argc,argv)
int argc; int argc;
char **argv; char **argv;
{ {
uint32_t len; uint32 len;
int c; int c;
if (!argv[1]) { if (!argv[1]) {

View File

@ -30,7 +30,7 @@ int get()
return c; return c;
} }
uint32_t safeadd(u,v) uint32_t u; uint32_t v; uint32 safeadd(u,v) uint32 u; uint32 v;
{ {
u += v; u += v;
if (u < v) overflow(); if (u < v) overflow();
@ -38,7 +38,7 @@ uint32_t safeadd(u,v) uint32_t u; uint32_t v;
} }
struct cdbmake cdbm; struct cdbmake cdbm;
uint32_t pos; uint32 pos;
char packbuf[8]; char packbuf[8];
int main(argc,argv) int main(argc,argv)
@ -48,9 +48,9 @@ char **argv;
char *fntemp; char *fntemp;
char *fn; char *fn;
FILE *fi; FILE *fi;
uint32_t len; uint32 len;
uint32_t u; uint32 u;
uint32_t h; uint32 h;
int i; int i;
int c; int c;
unsigned long keylen; unsigned long keylen;
@ -77,8 +77,8 @@ char **argv;
while ((c = get()) != ',') keylen = keylen * 10 + (c - '0'); while ((c = get()) != ',') keylen = keylen * 10 + (c - '0');
datalen = 0; datalen = 0;
while ((c = get()) != ':') datalen = datalen * 10 + (c - '0'); while ((c = get()) != ':') datalen = datalen * 10 + (c - '0');
cdbmake_pack(packbuf,(uint32_t) keylen); cdbmake_pack(packbuf,(uint32) keylen);
cdbmake_pack(packbuf + 4,(uint32_t) datalen); cdbmake_pack(packbuf + 4,(uint32) datalen);
if (fwrite(packbuf,1,8,fi) < 8) writeerror(); if (fwrite(packbuf,1,8,fi) < 8) writeerror();
@ -97,9 +97,9 @@ char **argv;
if (get() != '\n') format(); if (get() != '\n') format();
if (!cdbmake_add(&cdbm,h,pos,malloc)) nomem(); if (!cdbmake_add(&cdbm,h,pos,malloc)) nomem();
pos = safeadd(pos,(uint32_t) 8); pos = safeadd(pos,(uint32) 8);
pos = safeadd(pos,(uint32_t) keylen); pos = safeadd(pos,(uint32) keylen);
pos = safeadd(pos,(uint32_t) datalen); pos = safeadd(pos,(uint32) datalen);
} }
if (!cdbmake_split(&cdbm,malloc)) nomem(); if (!cdbmake_split(&cdbm,malloc)) nomem();
@ -110,7 +110,7 @@ char **argv;
cdbmake_pack(packbuf,cdbm.hash[u].h); cdbmake_pack(packbuf,cdbm.hash[u].h);
cdbmake_pack(packbuf + 4,cdbm.hash[u].p); cdbmake_pack(packbuf + 4,cdbm.hash[u].p);
if (fwrite(packbuf,1,8,fi) < 8) writeerror(); if (fwrite(packbuf,1,8,fi) < 8) writeerror();
pos = safeadd(pos,(uint32_t) 8); pos = safeadd(pos,(uint32) 8);
} }
} }

View File

@ -11,8 +11,8 @@ struct cdbmake *cdbm;
int cdbmake_add(cdbm,h,p,alloc) int cdbmake_add(cdbm,h,p,alloc)
struct cdbmake *cdbm; struct cdbmake *cdbm;
uint32_t h; uint32 h;
uint32_t p; uint32 p;
char *(*alloc)(); char *(*alloc)();
{ {
struct cdbmake_hplist *head; struct cdbmake_hplist *head;
@ -37,8 +37,8 @@ struct cdbmake *cdbm;
char *(*alloc)(); char *(*alloc)();
{ {
int i; int i;
uint32_t u; uint32 u;
uint32_t memsize; uint32 memsize;
struct cdbmake_hplist *x; struct cdbmake_hplist *x;
for (i = 0;i < 256;++i) for (i = 0;i < 256;++i)
@ -58,7 +58,7 @@ char *(*alloc)();
} }
memsize += cdbm->numentries; /* no overflow possible up to now */ memsize += cdbm->numentries; /* no overflow possible up to now */
u = (uint32_t) 0 - (uint32_t) 1; u = (uint32) 0 - (uint32) 1;
u /= sizeof(struct cdbmake_hp); u /= sizeof(struct cdbmake_hp);
if (memsize > u) return 0; if (memsize > u) return 0;
@ -82,16 +82,16 @@ char *(*alloc)();
return 1; return 1;
} }
uint32_t cdbmake_throw(cdbm,pos,b) uint32 cdbmake_throw(cdbm,pos,b)
struct cdbmake *cdbm; struct cdbmake *cdbm;
uint32_t pos; uint32 pos;
int b; int b;
{ {
uint32_t len; uint32 len;
uint32_t j; uint32 j;
uint32_t count; uint32 count;
struct cdbmake_hp *hp; struct cdbmake_hp *hp;
uint32_t where; uint32 where;
count = cdbm->count[b]; count = cdbm->count[b];

View File

@ -1,10 +1,10 @@
#include "freecdbmake.h" #include "freecdbmake.h"
uint32_t cdbmake_hashadd(h,c) uint32 cdbmake_hashadd(h,c)
uint32_t h; uint32 h;
unsigned int c; unsigned int c;
{ {
h += (h << 5); h += (h << 5);
h ^= (uint32_t) (unsigned char) c; h ^= (uint32) (unsigned char) c;
return h; return h;
} }

View File

@ -2,7 +2,7 @@
void cdbmake_pack(buf,num) void cdbmake_pack(buf,num)
unsigned char *buf; unsigned char *buf;
uint32_t num; uint32 num;
{ {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
buf[3] = num; num >>= 8; buf[3] = num; num >>= 8;

View File

@ -22,25 +22,25 @@ char buf[8];
int main() int main()
{ {
uint32_t pos; uint32 pos;
int i; int i;
uint32_t len; uint32 len;
uint32_t slot; uint32 slot;
uint32_t records; uint32 records;
uint32_t slots; uint32 slots;
uint32_t d0; uint32 d0;
uint32_t d1; uint32 d1;
uint32_t d2; uint32 d2;
uint32_t d3; uint32 d3;
uint32_t d4; uint32 d4;
uint32_t d5; uint32 d5;
uint32_t d6; uint32 d6;
uint32_t d7; uint32 d7;
uint32_t d8; uint32 d8;
uint32_t d9; uint32 d9;
uint32_t dfar; uint32 dfar;
uint32_t h; uint32 h;
uint32_t where; uint32 where;
if (fread(pointers,1,2048,stdin) < 2048) readerror(); if (fread(pointers,1,2048,stdin) < 2048) readerror();
pos = cdb_unpack(pointers); pos = cdb_unpack(pointers);

View File

@ -32,11 +32,11 @@ int numfound = 0;
int main() int main()
{ {
int i; int i;
uint32_t eod; uint32 eod;
uint32_t klen; uint32 klen;
uint32_t pos; uint32 pos;
uint32_t dlen; uint32 dlen;
uint32_t dlen2; uint32 dlen2;
char buf[8]; char buf[8];
if (cdb_bread(0,buf,4) == -1) readerror(); if (cdb_bread(0,buf,4) == -1) readerror();

View File

@ -13,7 +13,7 @@ dnl Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(unistd.h)
dnl Only look for uint32_t dnl Only look for uint32
AC_CHECK_SIZEOF(long,4) AC_CHECK_SIZEOF(long,4)
AC_CHECK_SIZEOF(int,4) AC_CHECK_SIZEOF(int,4)
AC_C_BIGENDIAN AC_C_BIGENDIAN

View File

@ -4,14 +4,14 @@
#include <stdio.h> #include <stdio.h>
#include "config.h" #include "config.h"
#if SIZEOF_INT==4 #if SIZEOF_INT==4
typedef unsigned int uint32_t ; typedef unsigned int uint32 ;
#elif SIZEOF_LONG==4 #elif SIZEOF_LONG==4
typedef unsigned long uint32_t ; typedef unsigned long uint32 ;
#else #else
#error "No uint32" #error "No uint32"
#endif #endif
extern uint32_t cdb_hash(); extern uint32 cdb_hash();
extern uint32_t cdb_unpack(); extern uint32 cdb_unpack();
extern int cdb_bread(); extern int cdb_bread();
extern int cdb_seek(); extern int cdb_seek();

View File

@ -5,9 +5,9 @@
#ifndef CDB_H #ifndef CDB_H
#include "config.h" #include "config.h"
#if SIZEOF_INT==4 #if SIZEOF_INT==4
typedef unsigned int uint32_t ; typedef unsigned int uint32 ;
#elif SIZEOF_LONG==4 #elif SIZEOF_LONG==4
typedef unsigned long uint32_t ; typedef unsigned long uint32 ;
#else #else
#error "No uint32" #error "No uint32"
#endif #endif
@ -15,7 +15,7 @@ typedef unsigned long uint32_t ;
#define CDBMAKE_HPLIST 1000 #define CDBMAKE_HPLIST 1000
struct cdbmake_hp { uint32_t h; uint32_t p; } ; struct cdbmake_hp { uint32 h; uint32 p; } ;
struct cdbmake_hplist { struct cdbmake_hplist {
struct cdbmake_hp hp[CDBMAKE_HPLIST]; struct cdbmake_hp hp[CDBMAKE_HPLIST];
@ -25,21 +25,21 @@ struct cdbmake_hplist {
struct cdbmake { struct cdbmake {
char final[2048]; char final[2048];
uint32_t count[256]; uint32 count[256];
uint32_t start[256]; uint32 start[256];
struct cdbmake_hplist *head; struct cdbmake_hplist *head;
struct cdbmake_hp *split; /* includes space for hash */ struct cdbmake_hp *split; /* includes space for hash */
struct cdbmake_hp *hash; struct cdbmake_hp *hash;
uint32_t numentries; uint32 numentries;
} ; } ;
extern void cdbmake_pack(); extern void cdbmake_pack();
#define CDBMAKE_HASHSTART ((uint32_t) 5381) #define CDBMAKE_HASHSTART ((uint32) 5381)
extern uint32_t cdbmake_hashadd(); extern uint32 cdbmake_hashadd();
extern void cdbmake_init(); extern void cdbmake_init();
extern int cdbmake_add(); extern int cdbmake_add();
extern int cdbmake_split(); extern int cdbmake_split();
extern uint32_t cdbmake_throw(); extern uint32 cdbmake_throw();
#endif #endif