diff options
author | blythe%netscape.com <devnull@localhost> | 2002-03-22 22:19:45 +0000 |
---|---|---|
committer | blythe%netscape.com <devnull@localhost> | 2002-03-22 22:19:45 +0000 |
commit | 74ee84b67a56f3b414cdfaccb8c162bfecd18260 (patch) | |
tree | a01ef35bfc3aba3101371d9a85f204af3c99ee29 | |
parent | 87ffb69633915e691767d469ca039be7efd75a0f (diff) | |
download | nss-hg-74ee84b67a56f3b414cdfaccb8c162bfecd18260.tar.gz |
Work in DBM land.
-rw-r--r-- | dbm/include/mcom_db.h | 6 | ||||
-rw-r--r-- | dbm/include/winfile.h | 2 | ||||
-rw-r--r-- | dbm/src/db.c | 7 | ||||
-rw-r--r-- | dbm/src/h_bigkey.c | 14 | ||||
-rw-r--r-- | dbm/src/h_func.c | 2 | ||||
-rw-r--r-- | dbm/src/h_log2.c | 2 | ||||
-rw-r--r-- | dbm/src/h_page.c | 18 | ||||
-rw-r--r-- | dbm/src/hash.c | 147 | ||||
-rw-r--r-- | dbm/src/hash_buf.c | 5 | ||||
-rw-r--r-- | dbm/src/hsearch.c | 6 | ||||
-rw-r--r-- | dbm/src/mktemp.c | 4 |
11 files changed, 205 insertions, 8 deletions
diff --git a/dbm/include/mcom_db.h b/dbm/include/mcom_db.h index 695162b35..6ec9e2fbc 100644 --- a/dbm/include/mcom_db.h +++ b/dbm/include/mcom_db.h @@ -81,6 +81,10 @@ #endif #include "prtypes.h" +#if defined(WINCE) +typedef PROffset32 off_t; +#endif + #include <limits.h> #ifdef __DBINTERFACE_PRIVATE @@ -216,6 +220,8 @@ #if !defined(WINCE) #include <fcntl.h> +#else +#include "nspr.h" #endif #if defined(_WINDOWS) || defined(XP_OS2) diff --git a/dbm/include/winfile.h b/dbm/include/winfile.h index 1fd54d578..f5031267c 100644 --- a/dbm/include/winfile.h +++ b/dbm/include/winfile.h @@ -16,9 +16,11 @@ #include <sys/types.h> #include <sys/stat.h> #else +#if !defined(WINCE) #include <sys\types.h> #include <sys\stat.h> #endif +#endif typedef struct DIR_Struct { void * directoryPtr; diff --git a/dbm/src/db.c b/dbm/src/db.c index cf6651271..3ee7d56b4 100644 --- a/dbm/src/db.c +++ b/dbm/src/db.c @@ -98,9 +98,14 @@ dbopen(const char *fname, int flags,int mode, DBTYPE type, const void *openinfo) (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ O_RDWR | O_SHLOCK | O_TRUNC) #else +#if !defined(WINCE) #define USE_OPEN_FLAGS \ (O_CREAT | O_EXCL | O_RDONLY | \ O_RDWR | O_TRUNC) +#else +#define USE_OPEN_FLAGS \ + (PR_CREATE_FILE | PR_EXCL | PR_RDONLY | PR_RDWR | PR_TRUNCATE) +#endif #endif if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) @@ -121,7 +126,9 @@ dbopen(const char *fname, int flags,int mode, DBTYPE type, const void *openinfo) default: break; } +#if !defined(WINCE) errno = EINVAL; +#endif return (NULL); } diff --git a/dbm/src/h_bigkey.c b/dbm/src/h_bigkey.c index 53a1a00f3..cbf0f2875 100644 --- a/dbm/src/h_bigkey.c +++ b/dbm/src/h_bigkey.c @@ -62,14 +62,18 @@ static char sccsid[] = "@(#)hash_bigkey.c 8.3 (Berkeley) 5/31/94"; #include <sys/param.h> #endif +#if !defined(WINCE) #include <errno.h> +#endif #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef DEBUG +#if !defined(WINCE) #include <assert.h> #endif +#endif #include "mcom_db.h" #include "hash.h" @@ -433,7 +437,9 @@ __big_return( return (-1); if (save_p->addr != save_addr) { /* We are pretty short on buffers. */ +#if !defined(WINCE) errno = EINVAL; /* OUT OF BUFFERS */ +#endif return (-1); } memmove(hashp->tmp_buf, (save_p->page) + off, len); @@ -497,7 +503,9 @@ collect_data( return (-1); } if (bufp->addr != save_addr) { +#if !defined(WINCE) errno = EINVAL; /* Out of buffers. */ +#endif return (-1); } memmove(&hashp->tmp_buf[len], (bufp->page) + bp[1], (size_t)mylen); @@ -558,7 +566,9 @@ collect_key( return (-1); } if (bufp->addr != save_addr) { +#if !defined(WINCE) errno = EINVAL; /* MIS -- OUT OF BUFFERS */ +#endif return (-1); } memmove(&hashp->tmp_key[len], (bufp->page) + bp[1], (size_t)mylen); @@ -604,7 +614,11 @@ __big_split( /* Now make one of np/op point to the big key/data pair */ #ifdef DEBUG +#if !defined(WINCE) assert(np->ovfl == NULL); +#else + PR_ASSERT(np->ovfl == NULL); +#endif #endif if (change) tmpp = np; diff --git a/dbm/src/h_func.c b/dbm/src/h_func.c index 5819efe23..8238d070c 100644 --- a/dbm/src/h_func.c +++ b/dbm/src/h_func.c @@ -41,8 +41,10 @@ static char sccsid[] = "@(#)hash_func.c 8.2 (Berkeley) 2/21/94"; #include "watcomfx.h" #ifndef macintosh +#if !defined(WINCE) #include <sys/types.h> #endif +#endif #include "mcom_db.h" #include "hash.h" #include "page.h" diff --git a/dbm/src/h_log2.c b/dbm/src/h_log2.c index 4d8b0a715..1c17b4701 100644 --- a/dbm/src/h_log2.c +++ b/dbm/src/h_log2.c @@ -42,8 +42,10 @@ static char sccsid[] = "@(#)hash_log2.c 8.2 (Berkeley) 5/31/94"; #include <stdio.h> #ifndef macintosh +#if !defined(WINCE) #include <sys/types.h> #endif +#endif #include "mcom_db.h" uint32 __log2(uint32 num) diff --git a/dbm/src/h_page.c b/dbm/src/h_page.c index e11ad9451..53ce2f1a0 100644 --- a/dbm/src/h_page.c +++ b/dbm/src/h_page.c @@ -63,19 +63,23 @@ static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; * open_temp */ #ifndef macintosh +#if !defined(WINCE) #include <sys/types.h> #endif +#endif #if defined(macintosh) #include <unistd.h> #endif +#if !defined(WINCE) #include <errno.h> #include <fcntl.h> #if defined(_WIN32) || defined(_WINDOWS) #include <io.h> #endif #include <signal.h> +#endif /* WINCE */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -84,7 +88,9 @@ static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; #include <unistd.h> #endif +#if !defined(WINCE) #include <assert.h> +#endif #include "mcom_db.h" #include "hash.h" @@ -717,7 +723,9 @@ __get_page(HTAB *hashp, bp[0] = 0; /* We hit the EOF, so initialize a new page */ else if ((unsigned)rsize != size) { +#if !defined(WINCE) errno = EFTYPE; +#endif return (-1); } @@ -872,7 +880,9 @@ __put_page(HTAB *hashp, char *p, uint32 bucket, int is_bucket, int is_bitmap) /* Errno is set */ return (-1); if ((unsigned)wsize != size) { +#if !defined(WINCE) errno = EFTYPE; +#endif return (-1); } #if defined(_WIN32) || defined(_WINDOWS) @@ -1200,7 +1210,13 @@ open_temp(HTAB *hashp) #endif #if defined(_WIN32) || defined(_WINDOWS) - if ((hashp->fp = mkstempflags(filename, _O_BINARY|_O_TEMPORARY)) != -1) { + if ((hashp->fp = mkstempflags(filename, +#if !defined(WINCE) + _O_BINARY|_O_TEMPORARY +#else + 0 +#endif + )) != -1) { if (hashp->filename) { free(hashp->filename); } diff --git a/dbm/src/hash.c b/dbm/src/hash.c index 530160244..ecec32f77 100644 --- a/dbm/src/hash.c +++ b/dbm/src/hash.c @@ -48,16 +48,21 @@ static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; #ifdef XP_OS2_EMX #include <sys/types.h> #endif +#if !defined(WINCE) #include <sys/stat.h> #endif +#endif #if defined(macintosh) #include <unix.h> #include <unistd.h> #endif +#if !defined(WINCE) #include <errno.h> #include <fcntl.h> +#endif + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -74,7 +79,9 @@ static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; #define EPERM SOCEPERM #endif +#if !defined(WINCE) #include <assert.h> +#endif #include "mcom_db.h" #include "hash.h" @@ -105,7 +112,12 @@ static void swap_header_copy __P((HASHHDR *, HASHHDR *)); /* Fast arithmetic, relying on powers of 2, */ #define MOD(x, y) ((x) & ((y) - 1)) +#if !defined(WINCE) #define RETURN_ERROR(ERR, LOC) { save_errno = ERR; goto LOC; } +#else +#define RETURN_ERROR(ERR, LOC) { goto LOC; } +#define PR_ACCMODE (PR_RDONLY | PR_WRONLY | PR_RDWR) +#endif /* Return values */ #define SUCCESS (0) @@ -143,20 +155,38 @@ extern DB * __hash_open(const char *file, int flags, int mode, const HASHINFO *info, int dflags) { HTAB *hashp=NULL; +#if !defined(WINCE) struct stat statbuf; +#else + PRFileInfo prInfo; + PRStatus infoResult; +#endif DB *dbp; - int bpages, hdrsize, new_table, nsegs, save_errno; + int bpages, hdrsize, new_table, nsegs; +#if !defined(WINCE) + int save_errno; +#endif +#if !defined(WINCE) if ((flags & O_ACCMODE) == O_WRONLY) { errno = EINVAL; RETURN_ERROR(ENOMEM, error0); } +#else + if ((flags & PR_ACCMODE) == PR_WRONLY) { + RETURN_ERROR(ENOMEM/*???*/, error0); + } +#endif /* zero the statbuffer so that * we can check it for a non-zero * date to see if stat succeeded */ +#if !defined(WINCE) memset(&statbuf, 0, sizeof(struct stat)); +#else + memset(&prInfo, 0, sizeof(prInfo)); +#endif if (!(hashp = (HTAB *)calloc(1, sizeof(HTAB)))) RETURN_ERROR(ENOMEM, error0); @@ -173,25 +203,43 @@ __hash_open(const char *file, int flags, int mode, const HASHINFO *info, int dfl hashp->flags = flags; new_table = 0; - if (!file || (flags & O_TRUNC) || (stat(file, &statbuf) && (errno == ENOENT))) - { +#if !defined(WINCE) + if (!file || (flags & O_TRUNC) || (stat(file, &statbuf) && (errno == ENOENT))) { if (errno == ENOENT) errno = 0; /* Just in case someone looks at errno */ new_table = 1; } - else if(statbuf.st_mtime && statbuf.st_size == 0) - { + else if(statbuf.st_mtime && statbuf.st_size == 0) { /* check for a zero length file and delete it * if it exists */ new_table = 1; } hashp->file_size = statbuf.st_size; +#else + infoResult = PR_GetFileInfo(file, &prInfo); + if (!file || (flags & PR_TRUNCATE) || (PR_FAILURE == PR_Access(file, PR_ACCESS_EXISTS))) { + new_table = 1; + } + else if(PR_SUCCESS == infoResult && 0 == prInfo.size) { + /* check for a zero length file and delete it + * if it exists + */ + new_table = 1; + } + hashp->file_size = prInfo.size; +#endif if (file) { #if defined(_WIN32) || defined(_WINDOWS) || defined (macintosh) || defined(XP_OS2_VACPP) - if ((hashp->fp = DBFILE_OPEN(file, flags | O_BINARY, mode)) == -1) + if ((hashp->fp = +#if !defined(WINCE) + DBFILE_OPEN(file, flags | O_BINARY, mode) +#else + DBFILE_OPEN(file, flags, mode) +#endif + ) == -1) RETURN_ERROR(errno, error0); #else if ((hashp->fp = open(file, flags, mode)) == -1) @@ -297,13 +345,21 @@ __hash_open(const char *file, int flags, int mode, const HASHINFO *info, int dfl #ifdef macintosh hashp->save_file = file && !(hashp->flags & O_RDONLY); #else +#if !defined(WINCE) hashp->save_file = file && (hashp->flags & O_RDWR); +#else + hashp->save_file = file && (hashp->flags & PR_RDWR); +#endif #endif hashp->cbucket = -1; if (!(dbp = (DB *)malloc(sizeof(DB)))) { +#if !defined(WINCE) save_errno = errno; +#endif hdestroy(hashp); +#if !defined(WINCE) errno = save_errno; +#endif RETURN_ERROR(ENOMEM, error0); } dbp->internal = hashp; @@ -353,7 +409,9 @@ error1: error0: free(hashp); +#if !defined(WINCE) errno = save_errno; +#endif return (NULL); } @@ -387,7 +445,9 @@ static int hash_fd(const DB *dbp) return (DBM_ERROR); if (hashp->fp == -1) { +#if !defined(WINCE) errno = ENOENT; +#endif return (-1); } return (hashp->fp); @@ -397,7 +457,9 @@ static int hash_fd(const DB *dbp) static HTAB * init_hash(HTAB *hashp, const char *file, HASHINFO *info) { - struct stat statbuf; +#if !defined(WINCE) + struct stat statbuf; +#endif int nelem; nelem = 1; @@ -415,8 +477,15 @@ init_hash(HTAB *hashp, const char *file, HASHINFO *info) /* Fix bucket size to be optimal for file system */ if (file != NULL) { +#if !defined(WINCE) if (stat(file, &statbuf)) return (NULL); +#else + if(PR_FAILURE == PR_Access(file, PR_ACCESS_EXISTS)) + { + return(NULL); + } +#endif #if !defined(_WIN32) && !defined(_WINDOWS) && !defined(macintosh) && !defined(VMS) && !defined(XP_OS2) #if defined(__QNX__) && !defined(__QNXNTO__) @@ -440,7 +509,9 @@ init_hash(HTAB *hashp, const char *file, HASHINFO *info) hashp->BSHIFT = __log2(info->bsize); hashp->BSIZE = 1 << hashp->BSHIFT; if (hashp->BSIZE > MAX_BSIZE) { +#if !defined(WINCE) errno = EINVAL; +#endif return (NULL); } } @@ -453,7 +524,9 @@ init_hash(HTAB *hashp, const char *file, HASHINFO *info) if (info->lorder) { if (info->lorder != BIG_ENDIAN && info->lorder != LITTLE_ENDIAN) { +#if !defined(WINCE) errno = EINVAL; +#endif return (NULL); } hashp->LORDER = info->lorder; @@ -541,7 +614,11 @@ hdestroy(HTAB *hashp) * write them to disk. */ if (__buf_free(hashp, 1, hashp->save_file)) +#if !defined(WINCE) save_errno = errno; +#else + save_errno = __LINE__; +#endif if (hashp->dir) { free(*hashp->dir); /* Free initial segments */ /* Free extra segments */ @@ -550,7 +627,11 @@ hdestroy(HTAB *hashp) free(hashp->dir); } if (flush_meta(hashp) && !save_errno) +#if !defined(WINCE) save_errno = errno; +#else + save_errno = __LINE__; +#endif /* Free Bigmaps */ for (i = 0; i < hashp->nmaps; i++) if (hashp->mapp[i]) @@ -570,7 +651,9 @@ hdestroy(HTAB *hashp) free(hashp); if (save_errno) { +#if !defined(WINCE) errno = save_errno; +#endif return (DBM_ERROR); } return (SUCCESS); @@ -647,7 +730,9 @@ hash_sync(const DB *dbp, uint flags) HTAB *hashp; if (flags != 0) { +#if !defined(WINCE) errno = EINVAL; +#endif return (DBM_ERROR); } @@ -705,8 +790,12 @@ flush_meta(HTAB *hashp) return (-1); else if (wsize != sizeof(HASHHDR)) { +#if !defined(WINCE) errno = EFTYPE; hashp->dbmerrno = errno; +#else + hashp->dbmerrno = __LINE__; +#endif return (-1); } for (i = 0; i < NCACHED; i++) @@ -741,7 +830,11 @@ hash_get( return (DBM_ERROR); if (flag) { +#if !defined(WINCE) hashp->dbmerrno = errno = EINVAL; +#else + hashp->dbmerrno = __LINE__; +#endif return (DBM_ERROR); } @@ -773,13 +866,24 @@ hash_put( return (DBM_ERROR); if (flag && flag != R_NOOVERWRITE) { +#if !defined(WINCE) hashp->dbmerrno = errno = EINVAL; +#else + hashp->dbmerrno = __LINE__; +#endif return (DBM_ERROR); } +#if !defined(WINCE) if ((hashp->flags & O_ACCMODE) == O_RDONLY) { hashp->dbmerrno = errno = EPERM; return (DBM_ERROR); } +#else + if ((hashp->flags & PR_ACCMODE) == PR_RDONLY) { + hashp->dbmerrno = __LINE__; + return (DBM_ERROR); + } +#endif rv = hash_access(hashp, flag == R_NOOVERWRITE ? HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data); @@ -809,13 +913,24 @@ hash_delete( return (DBM_ERROR); if (flag && flag != R_CURSOR) { +#if !defined(WINCE) hashp->dbmerrno = errno = EINVAL; +#else + hashp->dbmerrno = __LINE__; +#endif return (DBM_ERROR); } +#if !defined(WINCE) if ((hashp->flags & O_ACCMODE) == O_RDONLY) { hashp->dbmerrno = errno = EPERM; return (DBM_ERROR); } +#else + if ((hashp->flags & PR_ACCMODE) == PR_RDONLY) { + hashp->dbmerrno = __LINE__; + return (DBM_ERROR); + } +#endif rv = hash_access(hashp, HASH_DELETE, (DBT *)key, NULL); if(rv == DATABASE_CORRUPTED_ERROR) @@ -975,7 +1090,11 @@ found: return (DBM_ERROR); break; default: +#if !defined(WINCE) abort(); +#else + PR_Abort(); +#endif } save_bufp->flags &= ~BUF_PIN; return (SUCCESS); @@ -997,7 +1116,11 @@ hash_seq( return (DBM_ERROR); if (flag && flag != R_FIRST && flag != R_NEXT) { +#if !defined(WINCE) hashp->dbmerrno = errno = EINVAL; +#else + hashp->dbmerrno = __LINE__; +#endif return (DBM_ERROR); } #ifdef HASH_STATISTICS @@ -1170,21 +1293,31 @@ alloc_segs( register int i; register SEGMENT store; +#if !defined(WINCE) int save_errno; +#endif if ((hashp->dir = (SEGMENT *)calloc((size_t)hashp->DSIZE, sizeof(SEGMENT *))) == NULL) { +#if !defined(WINCE) save_errno = errno; +#endif (void)hdestroy(hashp); +#if !defined(WINCE) errno = save_errno; +#endif return (-1); } /* Allocate segments */ if ((store = (SEGMENT)calloc((size_t)nsegs << hashp->SSHIFT, sizeof(SEGMENT))) == NULL) { +#if !defined(WINCE) save_errno = errno; +#endif (void)hdestroy(hashp); +#if !defined(WINCE) errno = save_errno; +#endif return (-1); } for (i = 0; i < nsegs; i++, hashp->nsegs++) diff --git a/dbm/src/hash_buf.c b/dbm/src/hash_buf.c index 7bfe01a34..ce3fd5c3a 100644 --- a/dbm/src/hash_buf.c +++ b/dbm/src/hash_buf.c @@ -59,15 +59,20 @@ static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94"; #include <sys/param.h> #endif +#if !defined(WINCE) #include <errno.h> +#endif + #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef DEBUG +#if !defined(WINCE) #include <assert.h> #endif +#endif #include "mcom_db.h" #include "hash.h" diff --git a/dbm/src/hsearch.c b/dbm/src/hsearch.c index fb8a58bad..04b343be9 100644 --- a/dbm/src/hsearch.c +++ b/dbm/src/hsearch.c @@ -40,11 +40,13 @@ static char sccsid[] = "@(#)hsearch.c 8.4 (Berkeley) 7/21/94"; #include "watcomfx.h" +#if !defined(WINCE) #ifndef macintosh #include <sys/types.h> #endif #include <fcntl.h> +#endif /* WINCE */ #include <string.h> #include "mcom_db.h" @@ -64,7 +66,11 @@ hcreate(uint nel) info.cachesize = 0; info.hash = NULL; info.lorder = 0; +#if !defined(WINCE) dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0); +#else + dbp = (DB *)__hash_open(NULL, PR_CREATE_FILE | PR_RDWR, 0600, &info, 0); +#endif return ((int)dbp); } diff --git a/dbm/src/mktemp.c b/dbm/src/mktemp.c index 574eb9fe5..56e0e4f76 100644 --- a/dbm/src/mktemp.c +++ b/dbm/src/mktemp.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; #include "watcomfx.h" +#if !defined(WINCE) #ifdef macintosh #include <unix.h> #else @@ -45,6 +46,7 @@ static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; #endif #include <fcntl.h> #include <errno.h> +#endif /* WINCE */ #include <stdio.h> #include <ctype.h> #include "mcom_db.h" @@ -60,7 +62,9 @@ static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; #endif #ifdef _WINDOWS +#if !defined(WINCE) #include <process.h> +#endif #include "winfile.h" #endif |