diff options
Diffstat (limited to 'db2/os')
-rw-r--r-- | db2/os/os_alloc.c | 75 | ||||
-rw-r--r-- | db2/os/os_config.c | 75 | ||||
-rw-r--r-- | db2/os/os_stat.c | 31 |
3 files changed, 110 insertions, 71 deletions
diff --git a/db2/os/os_alloc.c b/db2/os/os_alloc.c new file mode 100644 index 0000000000..27abffbf0d --- /dev/null +++ b/db2/os/os_alloc.c @@ -0,0 +1,75 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1997 + * Sleepycat Software. All rights reserved. + */ + +#include "config.h" + +#ifndef lint +static const char sccsid[] = "@(#)os_alloc.c 10.1 (Sleepycat) 12/1/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include <sys/types.h> + +#include <errno.h> +#include <string.h> +#endif + +#include "db_int.h" + +/* + * XXX + * Correct for systems that return NULL when you allocate 0 bytes of memory. + * There are several places in DB where we allocate the number of bytes held + * by the key/data item, and it can be 0. Correct here so that malloc never + * returns a NULL for that reason (which behavior is permitted by ANSI). We + * could make these calls macros on non-Alpha architectures (that's where we + * saw the problem), but it's probably not worth the autoconf complexity. + */ +/* + * __db_calloc -- + * The calloc(3) function for DB. + * + * PUBLIC: void *__db_calloc __P((size_t, size_t)); + */ +void * +__db_calloc(num, size) + size_t num, size; +{ + void *p; + + size *= num; + if ((p = __db_jump.db_malloc(size == 0 ? 1 : size)) != NULL) + memset(p, 0, size); + return (p); +} + +/* + * __db_malloc -- + * The malloc(3) function for DB. + * + * PUBLIC: void *__db_malloc __P((size_t)); + */ +void * +__db_malloc(size) + size_t size; +{ + return (__db_jump.db_malloc(size == 0 ? 1 : size)); +} + +/* + * __db_realloc -- + * The realloc(3) function for DB. + * + * PUBLIC: void *__db_realloc __P((void *, size_t)); + */ +void * +__db_realloc(ptr, size) + void *ptr; + size_t size; +{ + return (__db_jump.db_realloc(ptr, size == 0 ? 1 : size)); +} diff --git a/db2/os/os_config.c b/db2/os/os_config.c index ecb4f1c2e7..7a89ba58ab 100644 --- a/db2/os/os_config.c +++ b/db2/os/os_config.c @@ -8,7 +8,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)os_config.c 10.9 (Sleepycat) 11/28/97"; +static const char sccsid[] = "@(#)os_config.c 10.12 (Sleepycat) 1/8/98"; #endif /* not lint */ #ifndef NO_SYSTEM_INCLUDES @@ -20,6 +20,22 @@ static const char sccsid[] = "@(#)os_config.c 10.9 (Sleepycat) 11/28/97"; #include "db_int.h" /* + * __os_oldwin -- + * Return if Windows 95 (as opposed to Windows NT). + * + * PUBLIC: int __os_oldwin __P((void)); + */ +int +__os_oldwin() +{ +#ifdef _WIN32 + return ((GetVersion() & 0x80000000) != 0); +#else + return (0); +#endif +} + +/* * XXX * We provide our own extern declarations so that we don't collide with * systems that get them wrong, e.g., SunOS. @@ -41,7 +57,6 @@ imported extern char *strdup __P((const char *)); imported extern void *realloc __P((void *, size_t)); imported extern int unlink __P((const char *)); imported extern ssize_t write __P((int, const void *, size_t)); -imported extern void *memset __P((void *, int, size_t)); /* * __db_jump -- @@ -110,8 +125,8 @@ db_jump_set(func, which) __db_jump.db_fsync = (int (*) __P((int)))func; break; case DB_FUNC_IOINFO: - __db_jump.db_ioinfo = - (int (*) __P((const char *, int, off_t *, off_t *)))func; + __db_jump.db_ioinfo = (int (*) __P((const char *, + int, u_int32_t *, u_int32_t *, u_int32_t *)))func; break; case DB_FUNC_MALLOC: __db_jump.db_malloc = (void *(*) __P((size_t)))func; @@ -178,55 +193,3 @@ db_value_set(value, which) } return (0); } - -/* - * XXX - * Correct for systems that return NULL when you allocate 0 bytes of memory. - * There are several places in DB where we allocate the number of bytes held - * by the key/data item, and it can be 0. Correct here so that malloc never - * returns a NULL for that reason. - */ -/* - * __db_calloc -- - * The calloc(3) function for DB. - * - * PUBLIC: void *__db_calloc __P((size_t, size_t)); - */ -void * -__db_calloc(num, size) - size_t num, size; -{ - void *p; - - size *= num; - if ((p = __db_jump.db_malloc(size == 0 ? 1 : size)) != NULL) - memset(p, 0, size); - return (p); -} - -/* - * __db_malloc -- - * The malloc(3) function for DB. - * - * PUBLIC: void *__db_malloc __P((size_t)); - */ -void * -__db_malloc(size) - size_t size; -{ - return (__db_jump.db_malloc(size == 0 ? 1 : size)); -} - -/* - * __db_realloc -- - * The realloc(3) function for DB. - * - * PUBLIC: void *__db_realloc __P((void *, size_t)); - */ -void * -__db_realloc(ptr, size) - void *ptr; - size_t size; -{ - return (__db_jump.db_realloc(ptr, size == 0 ? 1 : size)); -} diff --git a/db2/os/os_stat.c b/db2/os/os_stat.c index ee84ab0588..73600b6336 100644 --- a/db2/os/os_stat.c +++ b/db2/os/os_stat.c @@ -8,7 +8,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)os_stat.c 10.8 (Sleepycat) 10/25/97"; +static const char sccsid[] = "@(#)os_stat.c 10.11 (Sleepycat) 1/8/98"; #endif /* not lint */ #ifndef NO_SYSTEM_INCLUDES @@ -47,34 +47,35 @@ __os_exists(path, isdirp) * Return file size and I/O size; abstracted to make it easier * to replace. * - * PUBLIC: int __os_ioinfo __P((const char *, int, off_t *, off_t *)); + * PUBLIC: int __os_ioinfo + * PUBLIC: __P((const char *, int, u_int32_t *, u_int32_t *, u_int32_t *)); */ int -__os_ioinfo(path, fd, sizep, iop) +__os_ioinfo(path, fd, mbytesp, bytesp, iosizep) const char *path; int fd; - off_t *sizep, *iop; + u_int32_t *mbytesp, *bytesp, *iosizep; { struct stat sb; + COMPQUIET(path, NULL); + if (fstat(fd, &sb) == -1) return (errno); /* Return the size of the file. */ - if (sizep != NULL) - *sizep = sb.st_size; + if (mbytesp != NULL) + *mbytesp = sb.st_size / MEGABYTE; + if (bytesp != NULL) + *bytesp = sb.st_size % MEGABYTE; - /* - * Return the underlying filesystem blocksize, if available. Default - * to 8K on the grounds that most OS's use less than 8K as their VM - * page size. - */ + /* Return the underlying filesystem blocksize, if available. */ #ifdef HAVE_ST_BLKSIZE - if (iop != NULL) - *iop = sb.st_blksize; + if (iosizep != NULL) + *iosizep = sb.st_blksize; #else - if (iop != NULL) - *iop = 8 * 1024; + if (iosizep != NULL) + *iosizep = DB_DEF_IOSIZE; #endif return (0); } |