From cc3fa755128c70f8afc2d604936f33e4d7d652d8 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 12 Nov 1997 00:06:02 +0000 Subject: Update. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1997-11-11 21:30 Ulrich Drepper * include/sys/stat.h: Define stat, fstat, lstat and *64 variants as macros so the the library compiles correctly even without optimization. * io/fstat.c: Undef fstat. * io/fstat64.c: Undef fstat64 * io/lstat.c: Undef lstat. * io/lstat64.c: Undef lstat64 * io/stat.c: Undef stat. * io/stat64.c: Undef stat64 * io/fts.c: Include to get macro definitions. * io/ftw.c: Likewise. * io/getdirname.c: Likewise. * Makefile (install): Run test-installation.pl if possible. * db2/Makefile: Update from db-2.3.12. * db2/db.h: Likewise. * db2/db_int.h: Likewise. * db2/btree/bt_cursor.c: Likewise. * db2/btree/bt_delete.c: Likewise. * db2/btree/bt_open.c: Likewise. * db2/btree/bt_put.c: Likewise. * db2/btree/bt_rec.c: Likewise. * db2/btree/bt_recno.c: Likewise. * db2/btree/bt_search.c: Likewise. * db2/btree/bt_split.c: Likewise. * db2/btree/bt_stat.c: Likewise. * db2/btree/btree.src: Likewise. * db2/btree/btree_auto.c: Likewise. * db2/btree/bt_cursor.c: Likewise. * db2/btree/bt_delete.c: Likewise. * db2/btree/bt_open.c: Likewise. * db2/btree/bt_put.c: Likewise. * db2/btree/bt_rec.c: Likewise. * db2/btree/bt_recno.c: Likewise. * db2/btree/bt_search.c: Likewise. * db2/btree/bt_split.c: Likewise. * db2/btree/bt_stat.c: Likewise. * db2/btree/btree.src: Likewise. * db2/btree/btree_auto.c: Likewise. * db2/common/db_appinit.c: Likewise. * db2/common/db_apprec.c: Likewise. * db2/common/db_byteorder.c: Likewise. * db2/common/db_region.c: Likewise. * db2/db/db.c: Likewise * db2/db/db.src: Likewise * db2/db/db_auto.c: Likewise * db2/db/db_dispatch.c: Likewise * db2/db/db_dup.c: Likewise * db2/db/db_overflow.c: Likewise * db2/db/db_pr.c: Likewise * db2/db/db_rec.c: Likewise * db2/db/db_ret.c: Likewise * db2/db/db_thread.c: Likewise * db2/db185/db185.c: Likewise. * db2/hash/hash.c: Likewise. * db2/hash/hash.src: Likewise. * db2/hash/hash_auto.c: Likewise. * db2/hash/hash_dup.c: Likewise. * db2/hash/hash_page.c: Likewise. * db2/hash/hash_rec.c: Likewise. * db2/include/btree_auto.h: Likewise. * db2/include/btree_ext.h: Likewise. * db2/include/clib_ext.h: Likewise. * db2/include/common_ext.h: Likewise. * db2/include/db.h.src: Likewise. * db2/include/db_am.h: Likewise. * db2/include/db_auto.h: Likewise. * db2/include/db_cxx.h: Likewise. * db2/include/db_ext.h: Likewise. * db2/include/db_int.h.src: Likewise. * db2/include/hash.h: Likewise. * db2/include/hash_auto.h: Likewise. * db2/include/hash_ext.h: Likewise. * db2/include/lock.h: Likewise. * db2/include/lock_ext.h: Likewise. * db2/include/log.h: Likewise. * db2/include/log_ext.h: Likewise. * db2/include/mp.h: Likewise. * db2/include/mp_ext.h: Likewise. * db2/include/mutex_ext.h: Likewise. * db2/include/os_ext.h: Likewise. * db2/include/os_func.h: Likewise. * db2/include/txn.h: Likewise. * db2/include/txn_ext.h: Likewise. * db2/lock/lock.c: Likewise. * db2/lock/lock_deadlock.c: Likewise. * db2/log/log.c: Likewise. * db2/log/log_archive.c: Likewise. * db2/log/log_auto.c: Likewise. * db2/log/log_findckp.c: Likewise. * db2/log/log_get.c: Likewise. * db2/log/log_put.c: Likewise. * db2/log/log_rec.c: Likewise. * db2/log/log_register.c: Likewise. * db2/mp/mp_bh.c: Likewise. * db2/mp/mp_fget.c: Likewise. * db2/mp/mp_fopen.c: Likewise. * db2/mp/mp_fput.c: Likewise. * db2/mp/mp_fset.c: Likewise. * db2/mp/mp_open.c: Likewise. * db2/mp/mp_pr.c: Likewise. * db2/mp/mp_region.c: Likewise. * db2/mp/mp_sync.c: Likewise. * db2/mutex/mutex.c: Likewise. * db2/os/os_abs.c: Likewise. * db2/os/os_dir.c: Likewise. * db2/os/os_fid.c: Likewise. * db2/os/os_fsync.c: Likewise. * db2/os/os_func.c: Likewise. * db2/os/os_map.c: Likewise. * db2/os/os_oflags.c: Likewise. * db2/os/os_open.c: Likewise. * db2/os/os_rpath.c: Likewise. * db2/os/os_rw.c: Likewise. * db2/os/os_seek.c: Likewise. * db2/os/os_sleep.c: Likewise. * db2/os/os_stat.c: Likewise. * db2/os/os_unlink.c: Likewise. * db2/progs/db_deadlock/db_deadlock.c: Likewise. * db2/progs/db_dump/db_dump.c: Likewise. * db2/progs/db_load/db_load.c: Likewise. * db2/progs/db_recover/db_recover.c: Likewise. * db2/progs/db_stat/db_stat.c: Likewise. * db2/txn/txn.c: Likewise. * db2/txn/txn_auto.c: Likewise. * db2/txn/txn_rec.c: Likewise. * db2/os/db_os_abs.c: Removed. * db2/os/db_os_dir.c: Removed. * db2/os/db_os_fid.c: Removed. * db2/os/db_os_lseek.c: Removed. * db2/os/db_os_mmap.c: Removed. * db2/os/db_os_open.c: Removed. * db2/os/db_os_rw.c: Removed. * db2/os/db_os_sleep.c: Removed. * db2/os/db_os_stat.c: Removed. * db2/os/db_os_unlink.c: Removed. * libio/stdio.h (fopen): Add __restrict to parameters. * manual/process.texi (system): Describe behaviour for NULL argument. * stdio-common/printf-parse.h: Parse hh modifier. * stdio-common/vfprintf.c: Handle hh modifier. * stdio-common/vfscanf.c: Likewise. * manual/stdio.texi: Describe hh modifier for scanf/printf. * math/complex.h: Don't define _Imaginary_I, but instead _Complex_I. gcc does no yet know the `imaginary' keyword. * math/test-math.c: Add little test for know gcc bug. * math/tgmath.h: Make complex versions of log10() only available if __USE_GNU. * stdlib/test-canon.c: Fix typo. * sysdeps/generic/setenv.c: Avoid compilation warnings. Reported by Jim Meyering. * sysdeps/generic/bits/errno.h: EILSEQ is an ISO C error number. * sysdeps/mach/hurd/bits/errno.h: Likewise. * sysdeps/standalone/bits/errno.h: Likewise. * sysdeps/unix/sysv/linux/bits/errno.h: Likewise. * sysdeps/i386/i586/memcpy.S: New file. * sysdeps/i386/i586/mempcpy.S: New file. * sysdeps/i386/i586/memset.S: Fix typo. * sysdeps/posix/getcwd.c: Define HAVE_MEMPCPY for _LIBC. Add casts. * sysdeps/posix/system.c: Add comment to explain code. * sysdeps/wordsize-32/inttypes.h: Include for wchar_t. Define PTRDIFF_{MIN,MAX}, SIG_ATOMIC_{MIN,MAX}, SIZE_MAX, WCHAR_{MIN,MAX}, WINT_{MIN,MAX}. Define wcstoimax, wcstoumax. * sysdeps/wordsize-64/inttypes.h: Likewise. * wcsmbs/wchar.h: Define WCHAR_{MIN,MAX} if not already defined. Declare __wcsto{l,ul,ll,ull}_internal only if not already done. * time/Makefile (routines): Add strfxtime. * time/strftime.c: Implement %F and %f format. * time/strfxtime.c: New file. * time/time.h: Define new types and symbols from ISO C 9X. * time/mktime.c: Little comment correction. 1997-11-10 Andreas Jaeger * sysdeps/libm-ieee754/s_sincosl.c: Fix typo. * sysdeps/libm-ieee754/s_tanl.c: Fix typo. * sysdeps/libm-ieee754/s_floorl.c: Correct typos. * sysdeps/libm-ieee754/e_remainderl.c: Replace EXTRACT_LDOUBLE_WORDS by GET_LDOUBLE_WORDS. * sysdeps/libm-ieee754/e_atan2l.c: Replace EXTRACT_LDOUBLE_WORDS by GET_LDOUBLE_WORDS. * sysdeps/libm-ieee754/s_scalbnl.c: Replace ";" by "," for correct variable declaration. * sysdeps/libm-ieee754/s_scalblnl.c: Likewise. * sysdeps/libm-ieee754/s_lrint.c (__lrint): Correct function. * math/libm-test.c (sqrt_test): Add test for sqrt (0.25). (asin_test): Add more test. 1997-11-10 23:34 Ulrich Drepper * sysdeps/libm-ieee754/e_asin.c: Add braces to make code clearer and to not confuse the poor compiler. * sysdeps/libm-ieee754/e_asinf.c: Likewise. Reported by vertex@cagent.com. 1997-11-09 Andreas Schwab * elf/dl-lookup.c (do_lookup): Don't accept the base version if we require a specific one. * libio/oldfreopen.c: Bind old symbols to version GLIBC_2.0. * libio/oldiofopen.c: Likewise. * libio/oldstdfiles.c: Likewise. * libc.map: Export them. 1997-11-10 07:40 H.J. Lu * stdlib/exit.c (exit): Handle recursive calls to exit (). 1997-11-09 Andreas Schwab * sysdeps/m68k/fpu/s_llrint.c: Fixed to take double argument instead of long double. * sysdeps/m68k/fpu/s_llrintf.c: New file. * sysdeps/m68k/fpu/s_llrintl.c: New file. * sysdeps/libm-ieee754/s_llrint.c: Make compilable and fix overflow condition. * sysdeps/libm-ieee754/s_llrintf.c: Fix overflow condition. * sysdeps/libm-ieee754/s_llrintl.c: Likewise. * sysdeps/libm-ieee754/s_llround.c: Likewise. * sysdeps/libm-ieee754/s_llroundf.c: Likewise. * sysdeps/libm-ieee754/s_llroundl.c: Likewise. * sysdeps/libm-ieee754/s_lrint.c: Likewise. * sysdeps/libm-ieee754/s_lrintf.c: Likewise. * sysdeps/libm-ieee754/s_lrintl.c: Likewise. * sysdeps/libm-ieee754/s_lround.c: Likewise. * sysdeps/libm-ieee754/s_lroundf.c: Likewise. * sysdeps/libm-ieee754/s_lroundl.c: Likewise. * math/libm-test.c: Test all three variants of lrint and llrint. Fix typos in lround and llround tests. Add tests for boundary cases for lrint and llround. 1997-11-08 Andreas Schwab * manual/arith.texi: Misc doc fixes. * manual/ctype.texi: Likewise. * manual/pattern.texi: Likewise. * manual/terminal.texi: Likewise. 1997-11-08 Andreas Schwab * sysdeps/unix/sysv/linux/xstatconv.c: Use struct assignment instead of memcpy to let the compiler use whatever it regards as optimal. * sysdeps/unix/sysv/linux/alpha/xstatconv.c: Likewise. 1997-11-08 Andreas Schwab * sysdeps/unix/sysv/linux/Makefile (sysdep_headers) [$(subdir)=misc]: Add sys/prctl.h. * sysdeps/unix/sysv/linux/Dist: Distribute it. 1997-11-08 Andreas Schwab * io/ftwtest-sh: Don't use the unknown which command, instead try pwd as /bin/pwd and /usr/bin/pwd. 1997-11-08 Andreas Schwab * manual/maint.texi (Tools for Installation): Don't recommend broken version 3.76.1 of make. (Porting): Fix wording. 1997-11-06 06:13 H.J. Lu * config.make.in (build-pic-default): New, defined with pic_default. * configure.in (pic_default): New, set to yes if PIC is default. * Makeconfig (CPPFLAGS-.o, CPPFLAGS-.op, CPPFLAGS-.og, CPPFLAGS-.ob): Add -DPIC if $(build-pic-default) is yes. 1997-11-09 18:15 Ulrich Drepper * Makerules (libc.so): Fix typo. * csu/Makefile (CFLAGS-initfini.s): Correctly fix moving function definition. Patch by Zack Weinberg . * stdlib/strtod.c: Handle numbers like 0.0e10000 correctly which produce ±0.0. Reported by Joe Keane . * sysdeps/libm-ieee754/s_ceill.c: Fix typos. * sysdeps/libm-ieee754/s_llrint.c: Correct code, it never worked. 1997-11-06 07:00 H.J. Lu * sysdeps/unix/sysv/i386/i686/time.S: Removed. 1997-11-08 14:07 Thorsten Kukuk * nis/libnsl.map: Add __do_niscall2 for nis_cachemgr. * nis/nis_call.c: Set UDP resend timeout correct. * nis/nss_compat/compat-grp.c: Rewritten to make it faster. * nis/nss_compat/compat-pwd.c: Likewise. * nis/nss_compat/compat-spwd.c: Likewise. * nis/ypclnt.c: Fix UDP resend timeout, fix yp_bind/do_ypcall interaction. * inet/protocols/routed.h: Include sys/socket.h. * inet/protocols/talkd.h: Likewise. * inet/protocols/timed.h: Include rpc/types.h. * sunrpc/rpc/pmap_clnt.h: Include rpc/clnt.h. 1997-11-06 01:39 Ulrich Drepper * Makerules (libc.so): Add missing closing brace. 1997-11-05 Brendan Kehoe * libio.h (__P): Name its arg `p' instead of `params'. This was added solely to work around problems with the definition of __P in the Solaris math.h header. --- db2/os/db_os_abs.c | 82 --------------------------- db2/os/db_os_dir.c | 138 --------------------------------------------- db2/os/db_os_fid.c | 126 ----------------------------------------- db2/os/db_os_lseek.c | 60 -------------------- db2/os/db_os_mmap.c | 106 ---------------------------------- db2/os/db_os_open.c | 147 ------------------------------------------------ db2/os/db_os_rw.c | 75 ------------------------- db2/os/db_os_sleep.c | 62 -------------------- db2/os/db_os_stat.c | 84 --------------------------- db2/os/db_os_unlink.c | 35 ------------ db2/os/os_abs.c | 31 ++++++++++ db2/os/os_dir.c | 100 +++++++++++++++++++++++++++++++++ db2/os/os_fid.c | 77 +++++++++++++++++++++++++ db2/os/os_fsync.c | 34 +++++++++++ db2/os/os_func.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++ db2/os/os_map.c | 71 +++++++++++++++++++++++ db2/os/os_oflags.c | 48 ++++++++++++++++ db2/os/os_open.c | 105 ++++++++++++++++++++++++++++++++++ db2/os/os_rpath.c | 42 ++++++++++++++ db2/os/os_rw.c | 74 ++++++++++++++++++++++++ db2/os/os_seek.c | 42 ++++++++++++++ db2/os/os_sleep.c | 54 ++++++++++++++++++ db2/os/os_stat.c | 80 ++++++++++++++++++++++++++ db2/os/os_unlink.c | 34 +++++++++++ 24 files changed, 945 insertions(+), 915 deletions(-) delete mode 100644 db2/os/db_os_abs.c delete mode 100644 db2/os/db_os_dir.c delete mode 100644 db2/os/db_os_fid.c delete mode 100644 db2/os/db_os_lseek.c delete mode 100644 db2/os/db_os_mmap.c delete mode 100644 db2/os/db_os_open.c delete mode 100644 db2/os/db_os_rw.c delete mode 100644 db2/os/db_os_sleep.c delete mode 100644 db2/os/db_os_stat.c delete mode 100644 db2/os/db_os_unlink.c create mode 100644 db2/os/os_abs.c create mode 100644 db2/os/os_dir.c create mode 100644 db2/os/os_fid.c create mode 100644 db2/os/os_fsync.c create mode 100644 db2/os/os_func.c create mode 100644 db2/os/os_map.c create mode 100644 db2/os/os_oflags.c create mode 100644 db2/os/os_open.c create mode 100644 db2/os/os_rpath.c create mode 100644 db2/os/os_rw.c create mode 100644 db2/os/os_seek.c create mode 100644 db2/os/os_sleep.c create mode 100644 db2/os/os_stat.c create mode 100644 db2/os/os_unlink.c (limited to 'db2/os') diff --git a/db2/os/db_os_abs.c b/db2/os/db_os_abs.c deleted file mode 100644 index 8795205839..0000000000 --- a/db2/os/db_os_abs.c +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_abs.c 10.5 (Sleepycat) 7/5/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include -#endif - -#include "db_int.h" -#include "os_ext.h" - -/* - * __db_abspath -- - * Return if a path is an absolute path. - * - * PUBLIC: int __db_abspath __P((const char *)); - */ -int -__db_abspath(path) - const char *path; -{ -#ifdef _WIN32 - /* - * !!! - * Check for drive specifications, e.g., "C:". In addition, the path - * separator used by the win32 DB (PATH_SEPARATOR) is \; look for both - * / and \ since these are user-input paths. - */ - if (isalpha(path[0]) && path[1] == ':') - path += 2; - return (path[0] == '/' || path[0] == '\\'); -#else -#ifdef macintosh - /* - * !!! - * Absolute pathnames always start with a volume name, which must be - * followed by a colon, thus they are of the form: - * volume: or volume:dir1:dir2:file - * - * Relative pathnames are either a single name without colons or a - * path starting with a colon, thus of the form: - * file or :file or :dir1:dir2:file - */ - return (strchr(path, ':') != NULL && path[0] != ':'); -#else - return (path[0] == '/'); -#endif -#endif -} - -/* - * __db_rpath -- - * Return the last path separator in the path or NULL if none found. - * - * PUBLIC: char *__db_rpath __P((const char *)); - */ -char * -__db_rpath(path) - const char *path; -{ - const char *s, *last; - - last = NULL; - if (PATH_SEPARATOR[1] != '\0') { - for (s = path; s[0] != '\0'; ++s) - if (strchr(PATH_SEPARATOR, s[0]) != NULL) - last = s; - } else - for (s = path; s[0] != '\0'; ++s) - if (s[0] == PATH_SEPARATOR[0]) - last = s; - return ((char *)last); -} diff --git a/db2/os/db_os_dir.c b/db2/os/db_os_dir.c deleted file mode 100644 index 1206e3faa7..0000000000 --- a/db2/os/db_os_dir.c +++ /dev/null @@ -1,138 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_dir.c 10.10 (Sleepycat) 9/17/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include - -#if HAVE_DIRENT_H -# include -# define NAMLEN(dirent) strlen((dirent)->d_name) -#else -# define dirent direct -# define NAMLEN(dirent) (dirent)->d_namlen -# if HAVE_SYS_NDIR_H -# include -# endif -# if HAVE_SYS_DIR_H -# include -# endif -# if HAVE_NDIR_H -# include -# endif -#endif - -#include -#include -#include -#include -#endif - -#include "db_int.h" -#include "os_ext.h" -#include "common_ext.h" - -/* - * __db_dir -- - * Return a list of the files in a directory. - * - * PUBLIC: int __db_dir __P((DB_ENV *, const char *, char ***, int *)); - */ -int -__db_dir(dbenv, dir, namesp, cntp) - DB_ENV *dbenv; - const char *dir; - char ***namesp; - int *cntp; -{ - int arraysz, cnt; - char **names; -#ifdef _WIN32 - struct _finddata_t fdata; - long dirhandle; - int finished; - char filespec[MAX_PATH]; - - (void)snprintf(filespec, sizeof(filespec), "%s/*", dir); - if ((dirhandle = _findfirst(filespec, &fdata)) == -1) { - __db_err(dbenv, "%s: %s", filespec, strerror(errno)); - return (errno); - } - - names = NULL; - finished = 0; - for (arraysz = cnt = 0; finished != 1; ++cnt) { - if (cnt >= arraysz) { - arraysz += 100; - names = (char **)(names == NULL ? - malloc(arraysz * sizeof(names[0])) : - realloc(names, arraysz * sizeof(names[0]))); - if (names == NULL) - goto nomem; - } - if ((names[cnt] = (char *)strdup(fdata.name)) == NULL) - goto nomem; - if (_findnext(dirhandle,&fdata) != 0) - finished = 1; - } - _findclose(dirhandle); -#else /* !_WIN32 */ - struct dirent *dp; - DIR *dirp; - - if ((dirp = opendir(dir)) == NULL) { - __db_err(dbenv, "%s: %s", dir, strerror(errno)); - return (errno); - } - names = NULL; - for (arraysz = cnt = 0; (dp = readdir(dirp)) != NULL; ++cnt) { - if (cnt >= arraysz) { - arraysz += 100; - names = (char **)(names == NULL ? - malloc(arraysz * sizeof(names[0])) : - realloc(names, arraysz * sizeof(names[0]))); - if (names == NULL) - goto nomem; - } - if ((names[cnt] = (char *)strdup(dp->d_name)) == NULL) - goto nomem; - } - (void)closedir(dirp); -#endif /* !_WIN32 */ - - *namesp = names; - *cntp = cnt; - return (0); - -nomem: if (names != NULL) - __db_dirf(dbenv, names, cnt); - __db_err(dbenv, "%s", strerror(ENOMEM)); - return (ENOMEM); -} - -/* - * __db_dirf -- - * Free the list of files. - * - * PUBLIC: void __db_dirf __P((DB_ENV *, char **, int)); - */ -void -__db_dirf(dbenv, names, cnt) - DB_ENV *dbenv; - char **names; - int cnt; -{ - dbenv = dbenv; /* XXX: Shut the compiler up. */ - while (cnt > 0) - free(names[--cnt]); - free (names); -} diff --git a/db2/os/db_os_fid.c b/db2/os/db_os_fid.c deleted file mode 100644 index 960d580bad..0000000000 --- a/db2/os/db_os_fid.c +++ /dev/null @@ -1,126 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_fid.c 10.8 (Sleepycat) 8/27/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include -#include - -#include -#include -#include -#include -#endif - -#include "db_int.h" -#include "db_page.h" -#include "os_ext.h" -#include "common_ext.h" - -/* - * __db_fileid -- - * Return a unique identifier for a file. - * - * PUBLIC: int __db_fileid __P((DB_ENV *, const char *, int, u_int8_t *)); - */ -int -__db_fileid(dbenv, fname, timestamp, fidp) - DB_ENV *dbenv; - const char *fname; - int timestamp; - u_int8_t *fidp; -{ - size_t i; - time_t now; - u_int8_t *p; - -#ifdef _WIN32 - /* - * The documentation for GetFileInformationByHandle() states that the - * inode-type numbers are not constant between processes. Actually, - * they are, they're the NTFS MFT indexes. So, this works on NTFS, - * but perhaps not on other platforms, and perhaps not over a network. - * Can't think of a better solution right now. - */ - int fd = 0; - HANDLE fh = 0; - BY_HANDLE_FILE_INFORMATION fi; - BOOL retval = FALSE; - - /* Clear the buffer. */ - memset(fidp, 0, DB_FILE_ID_LEN); - - /* first we open the file, because we're not given a handle to it */ - fd = open(fname,_O_RDONLY,_S_IREAD); - if (-1 == fd) { - /* If we can't open it, we're in trouble */ - return (errno); - } - - /* File open, get its info */ - fh = (HANDLE)_get_osfhandle(fd); - if ((HANDLE)(-1) != fh) { - retval = GetFileInformationByHandle(fh,&fi); - } - close(fd); - - /* - * We want the three 32-bit words which tell us the volume ID and - * the file ID. We make a crude attempt to copy the bytes over to - * the callers buffer. - * - * DBDB: really we should ensure that the bytes get packed the same - * way on all compilers, platforms etc. - */ - if ( ((HANDLE)(-1) != fh) && (TRUE == retval) ) { - memcpy(fidp, &fi.nFileIndexLow, sizeof(u_int32_t)); - fidp += sizeof(u_int32_t); - memcpy(fidp, &fi.nFileIndexHigh, sizeof(u_int32_t)); - fidp += sizeof(u_int32_t); - memcpy(fidp, &fi.dwVolumeSerialNumber, sizeof(u_int32_t)); - } -#else - struct stat sb; - - /* Clear the buffer. */ - memset(fidp, 0, DB_FILE_ID_LEN); - - /* Check for the unthinkable. */ - if (sizeof(sb.st_ino) + - sizeof(sb.st_dev) + sizeof(time_t) > DB_FILE_ID_LEN) - return (EINVAL); - - /* On UNIX, use a dev/inode pair. */ - if (stat(fname, &sb)) { - __db_err(dbenv, "%s: %s", fname, strerror(errno)); - return (errno); - } - - /* - * Use the inode first and in reverse order, hopefully putting the - * distinguishing information early in the string. - */ - for (p = (u_int8_t *)&sb.st_ino + - sizeof(sb.st_ino), i = 0; i < sizeof(sb.st_ino); ++i) - *fidp++ = *--p; - for (p = (u_int8_t *)&sb.st_dev + - sizeof(sb.st_dev), i = 0; i < sizeof(sb.st_dev); ++i) - *fidp++ = *--p; -#endif - if (timestamp) { - (void)time(&now); - for (p = (u_int8_t *)&now + - sizeof(now), i = 0; i < sizeof(now); ++i) - *fidp++ = *--p; - } - return (0); -} diff --git a/db2/os/db_os_lseek.c b/db2/os/db_os_lseek.c deleted file mode 100644 index cecf0e156b..0000000000 --- a/db2/os/db_os_lseek.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_lseek.c 10.3 (Sleepycat) 6/28/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#endif - -#include "db_int.h" -#include "os_ext.h" - -/* - * __db_lseek -- - * Seek to a page/byte offset in the file. - * - * PUBLIC: int __db_lseek __P((int, size_t, db_pgno_t, u_long, int)); - */ -int -__db_lseek(fd, pgsize, pageno, relative, whence) - int fd; - size_t pgsize; - db_pgno_t pageno; - u_long relative; - int whence; -{ - /* 64-bit offsets are done differently by different vendors. */ -#undef __LSEEK_SET -#ifdef HAVE_LLSEEK -#define __LSEEK_SET - offset_t offset; /* Solaris. */ - - offset = pgsize * pageno + relative; - return (llseek(fd, offset, whence) == -1 ? errno : 0); -#endif -#ifdef HAVE_LSEEKI -#define __LSEEK_SET - __int64 offset; /* WNT */ - - offset = pgsize * pageno + relative; - return (_lseeki64(fd, offset, whence) == -1 ? errno : 0); -#endif -#ifndef __LSEEK_SET - off_t offset; /* Default. */ - - offset = pgsize * pageno + relative; - return (lseek(fd, offset, whence) == -1 ? errno : 0); -#endif -} diff --git a/db2/os/db_os_mmap.c b/db2/os/db_os_mmap.c deleted file mode 100644 index 0cd8fad0b0..0000000000 --- a/db2/os/db_os_mmap.c +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_mmap.c 10.4 (Sleepycat) 6/28/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include -#include - -#include -#endif - -#include "db_int.h" -#include "os_ext.h" - -/* - * __db_mmap -- - * Map in some shared memory backed by a file descriptor. - * - * PUBLIC: int __db_mmap __P((int, size_t, int, int, void *)); - */ -int -__db_mmap(fd, len, is_private, rdonly, addr) - int fd, is_private, rdonly; - size_t len; - void *addr; -{ -#ifdef _WIN32 - /* We have not implemented copy-on-write here */ - void * pMemory = 0; - HANDLE hFile = (HANDLE)_get_osfhandle(fd); - HANDLE hMemory = CreateFileMapping( - hFile, - 0, - (rdonly ? PAGE_READONLY : PAGE_READWRITE), - 0, - len, /* This code fails if the library is ever compiled on a 64-bit machine */ - 0 - ); - if (NULL == hMemory) - { - return errno; - } - pMemory = MapViewOfFile( - hMemory, - (rdonly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS), - 0, - 0, - len - ); - CloseHandle(hMemory); - *(void **)addr = pMemory; - return 0; - -#else /* !_WIN32 */ - - void *p; - int flags, prot; - - flags = is_private ? MAP_PRIVATE : MAP_SHARED; -#ifdef MAP_HASSEMAPHORE - flags += MAP_HASSEMAPHORE; -#endif - prot = PROT_READ | (rdonly ? 0 : PROT_WRITE); - -#ifndef MAP_FAILED /* XXX: Mmap(2) failure return. */ -#define MAP_FAILED -1 -#endif - if ((p = - mmap(NULL, len, prot, flags, fd, (off_t)0)) == (void *)MAP_FAILED) - return (errno); - - *(void **)addr = p; - return (0); -#endif /* _WIN32 */ -} - -/* - * __db_unmap -- - * Release the specified shared memory. - * - * PUBLIC: int __db_munmap __P((void *, size_t)); - */ -int -__db_munmap(addr, len) - void *addr; - size_t len; -{ - /* - * !!! - * The argument len is always the same length as was mapped. - */ -#ifdef _WIN32 - return (!UnmapViewOfFile(addr) ? errno : 0); -#else - return (munmap(addr, len) ? errno : 0); -#endif -} diff --git a/db2/os/db_os_open.c b/db2/os/db_os_open.c deleted file mode 100644 index 1d67ef9508..0000000000 --- a/db2/os/db_os_open.c +++ /dev/null @@ -1,147 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_open.c 10.14 (Sleepycat) 7/5/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#include -#endif - -#include "db_int.h" -#include "os_ext.h" - -/* - * __db_oflags -- - * Convert open(2) flags to DB flags. - * - * PUBLIC: int __db_oflags __P((int)); - */ -int -__db_oflags(oflags) - int oflags; -{ - int dbflags; - - /* - * XXX - * Convert POSIX 1003.1 open(2) flags to DB flags. Not an exact - * science as most POSIX implementations don't have a flag value - * for O_RDONLY, it's simply the lack of a write flag. - */ - dbflags = 0; - if (oflags & O_CREAT) - dbflags |= DB_CREATE; - if (!(oflags & (O_RDWR | O_WRONLY)) || oflags & O_RDONLY) - dbflags |= DB_RDONLY; - if (oflags & O_TRUNC) - dbflags |= DB_TRUNCATE; - return (dbflags); -} - -/* - * __db_fdopen -- - * Open a file descriptor. - * - * PUBLIC: int __db_fdopen __P((const char *, int, int, int, int *)); - */ -int -__db_fdopen(name, arg_flags, ok_flags, mode, fdp) - const char *name; - int arg_flags, ok_flags, mode, *fdp; -{ - int fd, flags; - - if (arg_flags & ~ok_flags) - return (EINVAL); - - flags = 0; - if (arg_flags & DB_CREATE) - flags |= O_CREAT; - - if (arg_flags & DB_EXCL) - flags |= O_EXCL; - - if (arg_flags & DB_RDONLY) - flags |= O_RDONLY; - else - flags |= O_RDWR; - -#ifdef _WIN32 -#ifdef _MSC_VER - if (arg_flags & DB_SEQUENTIAL) - flags |= _O_SEQUENTIAL; - else - flags |= _O_RANDOM; - - if (arg_flags & DB_TEMPORARY) - flags |= _O_TEMPORARY; -#endif - flags |= O_BINARY | O_NOINHERIT; -#endif - - if (arg_flags & DB_TRUNCATE) - flags |= O_TRUNC; - - /* Open the file. */ - if ((fd = open(name, flags, mode)) == -1) - return (errno); - -#ifndef _WIN32 - /* Delete any temporary file; done for Win32 by _O_TEMPORARY. */ - if (arg_flags & DB_TEMPORARY) - (void)unlink(name); -#endif - -#if !defined(_WIN32) && !defined(macintosh) - /* - * Deny access to any child process; done for Win32 by O_NOINHERIT, - * MacOS has neither child processes nor fd inheritance. - */ - if (fcntl(fd, F_SETFD, 1) == -1) { - int ret = errno; - - (void)__db_close(fd); - return (ret); - } -#endif - *fdp = fd; - return (0); -} - -/* - * __db_fsync -- - * Flush a file descriptor. - * - * PUBLIC: int __db_fsync __P((int)); - */ -int -__db_fsync(fd) - int fd; -{ - return (fsync(fd) ? errno : 0); -} - -/* - * __db_close -- - * Close a file descriptor. - * - * PUBLIC: int __db_close __P((int)); - */ -int -__db_close(fd) - int fd; -{ - return (close(fd) ? errno : 0); -} diff --git a/db2/os/db_os_rw.c b/db2/os/db_os_rw.c deleted file mode 100644 index 5a6c2196fd..0000000000 --- a/db2/os/db_os_rw.c +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_rw.c 10.4 (Sleepycat) 6/28/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#endif - -#include "db_int.h" -#include "os_ext.h" - -/* - * __db_read -- - * Read from a file handle. - * - * PUBLIC: int __db_read __P((int, void *, size_t, ssize_t *)); - */ -int -__db_read(fd, addr, len, nrp) - int fd; - void *addr; - size_t len; - ssize_t *nrp; -{ - size_t offset; - ssize_t nr; - u_int8_t *taddr; - - for (taddr = addr, - offset = 0; offset < len; taddr += nr, offset += nr) { - if ((nr = read(fd, taddr, len - offset)) < 0) - return (errno); - if (nr == 0) - break; - } - *nrp = taddr - (u_int8_t *)addr; - return (0); -} - -/* - * __db_write -- - * Write to a file handle. - * - * PUBLIC: int __db_write __P((int, void *, size_t, ssize_t *)); - */ -int -__db_write(fd, addr, len, nwp) - int fd; - void *addr; - size_t len; - ssize_t *nwp; -{ - size_t offset; - ssize_t nw; - u_int8_t *taddr; - - for (taddr = addr, - offset = 0; offset < len; taddr += nw, offset += nw) - if ((nw = write(fd, taddr, len - offset)) < 0) - return (errno); - *nwp = len; - return (0); -} diff --git a/db2/os/db_os_sleep.c b/db2/os/db_os_sleep.c deleted file mode 100644 index 5591789f51..0000000000 --- a/db2/os/db_os_sleep.c +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_sleep.c 10.6 (Sleepycat) 6/28/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include -#ifdef HAVE_SYS_TIME_H -#include -#endif -#ifdef HAVE_SYS_SELECT_H -#include -#endif - -#include -#ifndef HAVE_SYS_TIME_H -#include -#endif -#include -#endif - -#include "db_int.h" -#include "os_ext.h" - -/* - * __db_sleep -- - * Yield the processor for a period of time. - * - * PUBLIC: int __db_sleep __P((u_long, u_long)); - */ -int -__db_sleep(secs, usecs) - u_long secs, usecs; /* Seconds and microseconds. */ -{ -#ifndef _WIN32 - struct timeval t; -#endif - - /* Don't require that the values be normalized. */ - for (; usecs >= 1000000; ++secs, usecs -= 1000000); - - /* - * It's important that we yield the processor here so that other - * processes or threads are permitted to run. - */ -#ifdef _WIN32 - Sleep(secs * 1000 + usecs / 1000); - return (0); -#else - t.tv_sec = secs; - t.tv_usec = usecs; - return (select(0, NULL, NULL, NULL, &t) == -1 ? errno : 0); -#endif -} diff --git a/db2/os/db_os_stat.c b/db2/os/db_os_stat.c deleted file mode 100644 index 7929b6b754..0000000000 --- a/db2/os/db_os_stat.c +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_stat.c 10.6 (Sleepycat) 7/2/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include -#include - -#include -#include -#endif - -#include "db_int.h" -#include "os_ext.h" -#include "common_ext.h" - -/* - * __db_exists -- - * Return if the file exists. - * - * PUBLIC: int __db_exists __P((const char *, int *)); - */ -int -__db_exists(path, isdirp) - const char *path; - int *isdirp; -{ - struct stat sb; - - if (stat(path, &sb) != 0) - return (errno); - if (isdirp != NULL) - *isdirp = S_ISDIR(sb.st_mode); - return (0); -} - -/* - * __db_stat -- - * Return file size and I/O size; abstracted to make it easier - * to replace. - * - * PUBLIC: int __db_stat __P((DB_ENV *, const char *, int, off_t *, off_t *)); - */ -int -__db_stat(dbenv, path, fd, sizep, iop) - DB_ENV *dbenv; - const char *path; - int fd; - off_t *sizep, *iop; -{ - struct stat sb; - - if (fstat(fd, &sb) == -1) { - __db_err(dbenv, "%s: fstat: %s", path, strerror(errno)); - return (errno); - } - - /* Return the size of the file. */ - if (sizep != NULL) - *sizep = sb.st_size; - - /* - * 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. - */ -#ifdef HAVE_ST_BLKSIZE - if (iop != NULL) - *iop = sb.st_blksize; -#else - if (iop != NULL) - *iop = 8 * 1024; -#endif - return (0); -} diff --git a/db2/os/db_os_unlink.c b/db2/os/db_os_unlink.c deleted file mode 100644 index 872beba3cf..0000000000 --- a/db2/os/db_os_unlink.c +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1997 - * Sleepycat Software. All rights reserved. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)db_os_unlink.c 10.2 (Sleepycat) 6/28/97"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include - -#include -#include -#endif - -#include "db_int.h" -#include "os_ext.h" - -/* - * __db_unlink -- - * Remove a file. - * - * PUBLIC: int __db_unlink __P((const char *)); - */ -int -__db_unlink(path) - const char *path; -{ - return (unlink(path) == -1 ? errno : 0); -} diff --git a/db2/os/os_abs.c b/db2/os/os_abs.c new file mode 100644 index 0000000000..872e46d058 --- /dev/null +++ b/db2/os/os_abs.c @@ -0,0 +1,31 @@ +/*- + * 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_abs.c 10.7 (Sleepycat) 10/24/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include +#endif + +#include "db_int.h" + +/* + * __db_abspath -- + * Return if a path is an absolute path. + * + * PUBLIC: int __db_abspath __P((const char *)); + */ +int +__db_abspath(path) + const char *path; +{ + return (path[0] == '/'); +} diff --git a/db2/os/os_dir.c b/db2/os/os_dir.c new file mode 100644 index 0000000000..10fb8b6739 --- /dev/null +++ b/db2/os/os_dir.c @@ -0,0 +1,100 @@ +/*- + * 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_dir.c 10.13 (Sleepycat) 10/28/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include + +#if HAVE_DIRENT_H +# include +# define NAMLEN(dirent) strlen((dirent)->d_name) +#else +# define dirent direct +# define NAMLEN(dirent) (dirent)->d_namlen +# if HAVE_SYS_NDIR_H +# include +# endif +# if HAVE_SYS_DIR_H +# include +# endif +# if HAVE_NDIR_H +# include +# endif +#endif + +#include +#include +#include +#include +#endif + +#include "db_int.h" +#include "common_ext.h" + +/* + * __os_dirlist -- + * Return a list of the files in a directory. + * + * PUBLIC: int __os_dirlist __P((const char *, char ***, int *)); + */ +int +__os_dirlist(dir, namesp, cntp) + const char *dir; + char ***namesp; + int *cntp; +{ + struct dirent *dp; + DIR *dirp; + int arraysz, cnt; + char **names; + + if ((dirp = opendir(dir)) == NULL) + return (errno); + names = NULL; + for (arraysz = cnt = 0; (dp = readdir(dirp)) != NULL; ++cnt) { + if (cnt >= arraysz) { + arraysz += 100; + names = (char **)(names == NULL ? + __db_malloc(arraysz * sizeof(names[0])) : + __db_realloc(names, arraysz * sizeof(names[0]))); + if (names == NULL) + goto nomem; + } + if ((names[cnt] = (char *)__db_strdup(dp->d_name)) == NULL) + goto nomem; + } + (void)closedir(dirp); + + *namesp = names; + *cntp = cnt; + return (0); + +nomem: if (names != NULL) + __os_dirfree(names, cnt); + return (ENOMEM); +} + +/* + * __os_dirfree -- + * Free the list of files. + * + * PUBLIC: void __os_dirfree __P((char **, int)); + */ +void +__os_dirfree(names, cnt) + char **names; + int cnt; +{ + while (cnt > 0) + __db_free(names[--cnt]); + __db_free(names); +} diff --git a/db2/os/os_fid.c b/db2/os/os_fid.c new file mode 100644 index 0000000000..6820b88786 --- /dev/null +++ b/db2/os/os_fid.c @@ -0,0 +1,77 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1996, 1997 + * Sleepycat Software. All rights reserved. + */ + +#include "config.h" + +#ifndef lint +static const char sccsid[] = "@(#)os_fid.c 10.9 (Sleepycat) 10/24/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include +#include + +#include +#include +#include +#include +#endif + +#include "db_int.h" +#include "common_ext.h" + +/* + * __db_fileid -- + * Return a unique identifier for a file. + * + * PUBLIC: int __db_fileid __P((DB_ENV *, const char *, int, u_int8_t *)); + */ +int +__db_fileid(dbenv, fname, timestamp, fidp) + DB_ENV *dbenv; + const char *fname; + int timestamp; + u_int8_t *fidp; +{ + struct stat sb; + size_t i; + time_t now; + u_int8_t *p; + + /* Clear the buffer. */ + memset(fidp, 0, DB_FILE_ID_LEN); + + /* Check for the unthinkable. */ + if (sizeof(sb.st_ino) + + sizeof(sb.st_dev) + sizeof(time_t) > DB_FILE_ID_LEN) + return (EINVAL); + + /* On UNIX, use a dev/inode pair. */ + if (stat(fname, &sb)) { + __db_err(dbenv, "%s: %s", fname, strerror(errno)); + return (errno); + } + + /* + * Use the inode first and in reverse order, hopefully putting the + * distinguishing information early in the string. + */ + for (p = (u_int8_t *)&sb.st_ino + + sizeof(sb.st_ino), i = 0; i < sizeof(sb.st_ino); ++i) + *fidp++ = *--p; + for (p = (u_int8_t *)&sb.st_dev + + sizeof(sb.st_dev), i = 0; i < sizeof(sb.st_dev); ++i) + *fidp++ = *--p; + + if (timestamp) { + (void)time(&now); + for (p = (u_int8_t *)&now + + sizeof(now), i = 0; i < sizeof(now); ++i) + *fidp++ = *--p; + } + return (0); +} diff --git a/db2/os/os_fsync.c b/db2/os/os_fsync.c new file mode 100644 index 0000000000..7b001ceeb0 --- /dev/null +++ b/db2/os/os_fsync.c @@ -0,0 +1,34 @@ +/*- + * 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_fsync.c 10.3 (Sleepycat) 10/25/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include + +#include +#include +#endif + +#include "db_int.h" + +/* + * __db_fsync -- + * Flush a file descriptor. + * + * PUBLIC: int __db_fsync __P((int)); + */ +int +__db_fsync(fd) + int fd; +{ + return (__os_fsync(fd) ? errno : 0); +} diff --git a/db2/os/os_func.c b/db2/os/os_func.c new file mode 100644 index 0000000000..afd40f4624 --- /dev/null +++ b/db2/os/os_func.c @@ -0,0 +1,153 @@ +/*- + * 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_func.c 10.4 (Sleepycat) 10/28/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include + +#include +#endif + +#include "db_int.h" + +/* + * XXX + * We provide our own extern declarations so that we don't collide with + * systems that get them wrong, e.g., SunOS. + */ +#ifdef _WIN32 +#define fsync _commit +#define imported __declspec(dllimport) +#else +#define imported +#endif + +imported extern void *calloc __P((size_t, size_t)); +imported extern int close __P((int)); +imported extern void free __P((void *)); +imported extern int fsync __P((int)); +imported extern void *malloc __P((size_t)); +imported extern int open __P((const char *, int, ...)); +imported extern ssize_t read __P((int, void *, size_t)); +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)); + +/* + * __db_jump -- + * This list of interfaces that applications can replace. In some + * cases, the user is permitted to replace the standard ANSI C or + * POSIX 1003.1 call, e.g., calloc or read. In others, we provide + * a local interface to the functionality, e.g., __os_map. + */ +struct __db_jumptab __db_jump = { + calloc, /* DB_FUNC_CALLOC */ + close, /* DB_FUNC_CLOSE */ + __os_dirfree, /* DB_FUNC_DIRFREE */ + __os_dirlist, /* DB_FUNC_DIRLIST */ + __os_exists, /* DB_FUNC_EXISTS */ + free, /* DB_FUNC_FREE */ + fsync, /* DB_FUNC_FSYNC */ + __os_ioinfo, /* DB_FUNC_IOINFO */ + malloc, /* DB_FUNC_MALLOC */ + __os_map, /* DB_FUNC_MAP */ + open, /* DB_FUNC_OPEN */ + read, /* DB_FUNC_READ */ + realloc, /* DB_FUNC_REALLOC */ + __os_seek, /* DB_FUNC_SEEK */ + __os_sleep, /* DB_FUNC_SLEEP */ + strdup, /* DB_FUNC_STRDUP */ + unlink, /* DB_FUNC_UNLINK */ + __os_unmap, /* DB_FUNC_UNMAP */ + write, /* DB_FUNC_WRITE */ + NULL /* DB_FUNC_YIELD */ +}; + +/* + * db_jump_set -- + * Replace an interface. + */ +int +db_jump_set(func, which) + void *func; + int which; +{ + switch (which) { + case DB_FUNC_CALLOC: + __db_calloc = (void *(*) __P((size_t, size_t)))func; + break; + case DB_FUNC_CLOSE: + __os_close = (int (*) __P((int)))func; + break; + case DB_FUNC_DIRFREE: + __db_dirfree = (void (*) __P((char **, int)))func; + break; + case DB_FUNC_DIRLIST: + __db_dirlist = + (int (*) __P((const char *, char ***, int *)))func; + break; + case DB_FUNC_EXISTS: + __db_exists = (int (*) __P((const char *, int *)))func; + break; + case DB_FUNC_FREE: + __db_free = (void (*) __P((void *)))func; + break; + case DB_FUNC_FSYNC: + __os_fsync = (int (*) __P((int)))func; + break; + case DB_FUNC_IOINFO: + __db_ioinfo = + (int (*) __P((const char *, int, off_t *, off_t *)))func; + break; + case DB_FUNC_MALLOC: + __db_malloc = (void *(*) __P((size_t)))func; + break; + case DB_FUNC_MAP: + __db_map = (int (*) __P((int, size_t, int, int, void **)))func; + break; + case DB_FUNC_OPEN: + __os_open = (int (*) __P((const char *, int, ...)))func; + break; + case DB_FUNC_READ: + __os_read = (ssize_t (*) __P((int, void *, size_t)))func; + break; + case DB_FUNC_REALLOC: + __db_realloc = (void *(*) __P((void *, size_t)))func; + break; + case DB_FUNC_SEEK: + __db_seek = + (int (*) __P((int, size_t, db_pgno_t, u_long, int)))func; + break; + case DB_FUNC_SLEEP: + __db_sleep = (int (*) __P((u_long, u_long)))func; + break; + case DB_FUNC_STRDUP: + __db_strdup = (char *(*) __P((const char *)))func; + break; + case DB_FUNC_UNLINK: + __os_unlink = (int (*) __P((const char *)))func; + break; + case DB_FUNC_UNMAP: + __db_unmap = (int (*) __P((void *, size_t)))func; + break; + case DB_FUNC_WRITE: + __os_write = (ssize_t (*) __P((int, const void *, size_t)))func; + break; + case DB_FUNC_YIELD: + __db_yield = (int (*) __P((void)))func; + break; + default: + return (EINVAL); + } + return (0); +} diff --git a/db2/os/os_map.c b/db2/os/os_map.c new file mode 100644 index 0000000000..b1553188dc --- /dev/null +++ b/db2/os/os_map.c @@ -0,0 +1,71 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1996, 1997 + * Sleepycat Software. All rights reserved. + */ + +#include "config.h" + +#ifndef lint +static const char sccsid[] = "@(#)os_map.c 10.7 (Sleepycat) 10/25/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include +#include + +#include +#endif + +#include "db_int.h" + +/* + * __os_map -- + * Map in some shared memory backed by a file descriptor. + * + * PUBLIC: int __os_map __P((int, size_t, int, int, void **)); + */ +int +__os_map(fd, len, is_private, is_rdonly, addr) + int fd, is_private, is_rdonly; + size_t len; + void **addr; +{ + void *p; + int flags, prot; + + flags = is_private ? MAP_PRIVATE : MAP_SHARED; +#ifdef MAP_HASSEMAPHORE + flags |= MAP_HASSEMAPHORE; +#endif + prot = PROT_READ | (is_rdonly ? 0 : PROT_WRITE); + +#ifndef MAP_FAILED /* XXX: Mmap(2) failure return. */ +#define MAP_FAILED -1 +#endif + if ((p = + mmap(NULL, len, prot, flags, fd, (off_t)0)) == (void *)MAP_FAILED) + return (errno); + + *addr = p; + return (0); +} + +/* + * __os_unmap -- + * Release the specified shared memory. + * + * PUBLIC: int __os_unmap __P((void *, size_t)); + */ +int +__os_unmap(addr, len) + void *addr; + size_t len; +{ + /* + * !!! + * The argument len is always the same length as was mapped. + */ + return (munmap(addr, len) ? errno : 0); +} diff --git a/db2/os/os_oflags.c b/db2/os/os_oflags.c new file mode 100644 index 0000000000..3656eef1c4 --- /dev/null +++ b/db2/os/os_oflags.c @@ -0,0 +1,48 @@ +/*- + * 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_oflags.c 10.2 (Sleepycat) 10/24/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include + +#include +#endif + +#include "db_int.h" + +/* + * __db_oflags -- + * Convert open(2) flags to DB flags. + * + * PUBLIC: int __db_oflags __P((int)); + */ +int +__db_oflags(oflags) + int oflags; +{ + int dbflags; + + /* + * XXX + * Convert POSIX 1003.1 open(2) flags to DB flags. Not an exact + * science as most POSIX implementations don't have a flag value + * for O_RDONLY, it's simply the lack of a write flag. + */ + dbflags = 0; + if (oflags & O_CREAT) + dbflags |= DB_CREATE; + if (!(oflags & (O_RDWR | O_WRONLY)) || oflags & O_RDONLY) + dbflags |= DB_RDONLY; + if (oflags & O_TRUNC) + dbflags |= DB_TRUNCATE; + return (dbflags); +} diff --git a/db2/os/os_open.c b/db2/os/os_open.c new file mode 100644 index 0000000000..05784e4810 --- /dev/null +++ b/db2/os/os_open.c @@ -0,0 +1,105 @@ +/*- + * 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_open.c 10.19 (Sleepycat) 10/28/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include + +#include +#include +#include +#endif + +#include "db_int.h" + +/* + * __db_open -- + * Open a file descriptor. + * + * PUBLIC: int __db_open __P((const char *, int, int, int, int *)); + */ +int +__db_open(name, arg_flags, ok_flags, mode, fdp) + const char *name; + int arg_flags, ok_flags, mode, *fdp; +{ + int fd, flags; + + if (arg_flags & ~ok_flags) + return (EINVAL); + + flags = 0; + if (arg_flags & DB_CREATE) + flags |= O_CREAT; + + if (arg_flags & DB_EXCL) + flags |= O_EXCL; + + if (arg_flags & DB_RDONLY) + flags |= O_RDONLY; + else + flags |= O_RDWR; + +#ifdef _WIN32 +#ifdef _MSC_VER + if (arg_flags & DB_SEQUENTIAL) + flags |= _O_SEQUENTIAL; + else + flags |= _O_RANDOM; + + if (arg_flags & DB_TEMPORARY) + flags |= _O_TEMPORARY; +#endif + flags |= O_BINARY | O_NOINHERIT; +#endif + + if (arg_flags & DB_TRUNCATE) + flags |= O_TRUNC; + + /* Open the file. */ + if ((fd = __os_open(name, flags, mode)) == -1) + return (errno); + +#ifndef _WIN32 + /* Delete any temporary file; done for Win32 by _O_TEMPORARY. */ + if (arg_flags & DB_TEMPORARY) + (void)__os_unlink(name); +#endif + +#if !defined(_WIN32) && !defined(macintosh) + /* + * Deny access to any child process; done for Win32 by O_NOINHERIT, + * MacOS has neither child processes nor fd inheritance. + */ + if (fcntl(fd, F_SETFD, 1) == -1) { + int ret = errno; + + (void)__os_close(fd); + return (ret); + } +#endif + *fdp = fd; + return (0); +} + +/* + * __db_close -- + * Close a file descriptor. + * + * PUBLIC: int __db_close __P((int)); + */ +int +__db_close(fd) + int fd; +{ + return (__os_close(fd) ? errno : 0); +} diff --git a/db2/os/os_rpath.c b/db2/os/os_rpath.c new file mode 100644 index 0000000000..44fd4ec9f4 --- /dev/null +++ b/db2/os/os_rpath.c @@ -0,0 +1,42 @@ +/*- + * 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_rpath.c 10.2 (Sleepycat) 10/24/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include +#endif + +#include "db_int.h" + +/* + * __db_rpath -- + * Return the last path separator in the path or NULL if none found. + * + * PUBLIC: char *__db_rpath __P((const char *)); + */ +char * +__db_rpath(path) + const char *path; +{ + const char *s, *last; + + last = NULL; + if (PATH_SEPARATOR[1] != '\0') { + for (s = path; s[0] != '\0'; ++s) + if (strchr(PATH_SEPARATOR, s[0]) != NULL) + last = s; + } else + for (s = path; s[0] != '\0'; ++s) + if (s[0] == PATH_SEPARATOR[0]) + last = s; + return ((char *)last); +} diff --git a/db2/os/os_rw.c b/db2/os/os_rw.c new file mode 100644 index 0000000000..48f7fdc5b1 --- /dev/null +++ b/db2/os/os_rw.c @@ -0,0 +1,74 @@ +/*- + * 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_rw.c 10.6 (Sleepycat) 10/25/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include + +#include +#include +#endif + +#include "db_int.h" + +/* + * __db_read -- + * Read from a file handle. + * + * PUBLIC: int __db_read __P((int, void *, size_t, ssize_t *)); + */ +int +__db_read(fd, addr, len, nrp) + int fd; + void *addr; + size_t len; + ssize_t *nrp; +{ + size_t offset; + ssize_t nr; + u_int8_t *taddr; + + for (taddr = addr, + offset = 0; offset < len; taddr += nr, offset += nr) { + if ((nr = __os_read(fd, taddr, len - offset)) < 0) + return (errno); + if (nr == 0) + break; + } + *nrp = taddr - (u_int8_t *)addr; + return (0); +} + +/* + * __db_write -- + * Write to a file handle. + * + * PUBLIC: int __db_write __P((int, void *, size_t, ssize_t *)); + */ +int +__db_write(fd, addr, len, nwp) + int fd; + void *addr; + size_t len; + ssize_t *nwp; +{ + size_t offset; + ssize_t nw; + u_int8_t *taddr; + + for (taddr = addr, + offset = 0; offset < len; taddr += nw, offset += nw) + if ((nw = __os_write(fd, taddr, len - offset)) < 0) + return (errno); + *nwp = len; + return (0); +} diff --git a/db2/os/os_seek.c b/db2/os/os_seek.c new file mode 100644 index 0000000000..e27044b626 --- /dev/null +++ b/db2/os/os_seek.c @@ -0,0 +1,42 @@ +/*- + * 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_seek.c 10.6 (Sleepycat) 10/25/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include + +#include +#include +#endif + +#include "db_int.h" + +/* + * __os_seek -- + * Seek to a page/byte offset in the file. + * + * PUBLIC: int __os_seek __P((int, size_t, db_pgno_t, u_long, int)); + */ +int +__os_seek(fd, pgsize, pageno, relative, whence) + int fd; + size_t pgsize; + db_pgno_t pageno; + u_long relative; + int whence; +{ + off_t offset; + + offset = pgsize * pageno + relative; + + return (lseek(fd, offset, whence) == -1 ? errno : 0); +} diff --git a/db2/os/os_sleep.c b/db2/os/os_sleep.c new file mode 100644 index 0000000000..2d2cb71f6d --- /dev/null +++ b/db2/os/os_sleep.c @@ -0,0 +1,54 @@ +/*- + * 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_sleep.c 10.8 (Sleepycat) 10/25/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_SELECT_H +#include +#endif + +#include +#ifndef HAVE_SYS_TIME_H +#include +#endif +#include +#endif + +#include "db_int.h" + +/* + * __os_sleep -- + * Yield the processor for a period of time. + * + * PUBLIC: int __os_sleep __P((u_long, u_long)); + */ +int +__os_sleep(secs, usecs) + u_long secs, usecs; /* Seconds and microseconds. */ +{ + struct timeval t; + + /* Don't require that the values be normalized. */ + for (; usecs >= 1000000; ++secs, usecs -= 1000000); + + /* + * It's important that we yield the processor here so that other + * processes or threads are permitted to run. + */ + t.tv_sec = secs; + t.tv_usec = usecs; + return (select(0, NULL, NULL, NULL, &t) == -1 ? errno : 0); +} diff --git a/db2/os/os_stat.c b/db2/os/os_stat.c new file mode 100644 index 0000000000..ee84ab0588 --- /dev/null +++ b/db2/os/os_stat.c @@ -0,0 +1,80 @@ +/*- + * 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_stat.c 10.8 (Sleepycat) 10/25/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include +#include + +#include +#include +#endif + +#include "db_int.h" +#include "common_ext.h" + +/* + * __os_exists -- + * Return if the file exists. + * + * PUBLIC: int __os_exists __P((const char *, int *)); + */ +int +__os_exists(path, isdirp) + const char *path; + int *isdirp; +{ + struct stat sb; + + if (stat(path, &sb) != 0) + return (errno); + if (isdirp != NULL) + *isdirp = S_ISDIR(sb.st_mode); + return (0); +} + +/* + * __os_ioinfo -- + * 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 *)); + */ +int +__os_ioinfo(path, fd, sizep, iop) + const char *path; + int fd; + off_t *sizep, *iop; +{ + struct stat sb; + + if (fstat(fd, &sb) == -1) + return (errno); + + /* Return the size of the file. */ + if (sizep != NULL) + *sizep = sb.st_size; + + /* + * 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. + */ +#ifdef HAVE_ST_BLKSIZE + if (iop != NULL) + *iop = sb.st_blksize; +#else + if (iop != NULL) + *iop = 8 * 1024; +#endif + return (0); +} diff --git a/db2/os/os_unlink.c b/db2/os/os_unlink.c new file mode 100644 index 0000000000..473ce77d39 --- /dev/null +++ b/db2/os/os_unlink.c @@ -0,0 +1,34 @@ +/*- + * 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_unlink.c 10.4 (Sleepycat) 10/28/97"; +#endif /* not lint */ + +#ifndef NO_SYSTEM_INCLUDES +#include + +#include +#include +#endif + +#include "db_int.h" + +/* + * __db_unlink -- + * Remove a file. + * + * PUBLIC: int __db_unlink __P((const char *)); + */ +int +__db_unlink(path) + const char *path; +{ + return (__os_unlink(path) == -1 ? errno : 0); +} -- cgit v1.2.3