aboutsummaryrefslogtreecommitdiff
path: root/db2/os
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-08-27 20:26:10 +0000
committerUlrich Drepper <drepper@redhat.com>1997-08-27 20:26:10 +0000
commit92f1da4da04a7a86ddee91be5eaf0b10c333ac64 (patch)
tree2a10ce9e4e407e7e5b5ca092ca0947d234b5ff60 /db2/os
parent22be878ecbc66606371bd33258f56e6711e6ba7a (diff)
downloadglibc-92f1da4da04a7a86ddee91be5eaf0b10c333ac64.zip
glibc-92f1da4da04a7a86ddee91be5eaf0b10c333ac64.tar.gz
glibc-92f1da4da04a7a86ddee91be5eaf0b10c333ac64.tar.bz2
1997-08-10 19:17 Philip Blundell <Philip.Blundell@pobox.com> * nss/nss_db/db-XXX.c: Include <db_185.h> not <db.h>. Somebody should update this to use the new db API. * nss/nss_db/db-netgrp.c: Likewise. * nss/nss_db/db-alias.c: Likewise. * db2/Makefile: Makefile for db-2.x in glibc. 1997-08-27 21:20 Ulrich Drepper <drepper@cygnus.com> * csu/Makefile (before-compile): New goal. Make sure abi-tag.h is generated. [$(elf)=yes] (asm-CPPFLAGS): Make sure abi-tag.h file can be found. * Makeconfig [$(build-omitfp)=yes] (CFLAGS-.o): Add -D__USE_STRING_INLINES. * string/string.f: Move strnlen optimization after inclusion of <bits/string.h>. Include <bits/string.h> only if __USE_STRING_INLINES is defined. * sysdeps/generic/memcpy.c: Undef memcpy to allow macro of this name in <bits/string.h>. * sysdeps/generic/memset.c: Likewise. * sysdeps/i386/string.h: i386 optimized string functions. * sysdeps/i386/i486string.h: i486+ optimized string functions. * Makefile (subdirs): Change db to db2. * shlib-versions: Bump libdb verion number to 3. * include/db.h: Include from db2 directory. * include/db_185.h: New file. * sysdeps/i386/Makefile [$(subdirs)=db2] (CPPFLAGS): Add macros to provide spinlock information for db2. * sysdeps/m68k/m68020/Makefile: New file. Likewise. * sysdeps/sparc/Makefile: New file. Likewise. * sysdeps/unix/sysv/linux/Makefile [$(subdirs)=db2] (CPPFLAGS): Add -DHAVE_LLSEEK. * db2/config.h: Hand-edited config file for db2 in glibc. * db2/compat.h: New file from db-2.3.4. * db2/db.h: Likewise. * db2/db_185.h: Likewise. * db2/db_int.h: Likewise. * db2/makedb.c: Likewise. * db2/btree/bt_close.c: Likewise. * db2/btree/bt_compare.c: Likewise. * db2/btree/bt_conv.c: Likewise. * db2/btree/bt_cursor.c: Likewise. * db2/btree/bt_delete.c: Likewise. * db2/btree/bt_open.c: Likewise. * db2/btree/bt_page.c: Likewise. * db2/btree/bt_put.c: Likewise. * db2/btree/bt_rec.c: Likewise. * db2/btree/bt_recno.c: Likewise. * db2/btree/btree_auto.c: Likewise. * db2/btree/bt_rsearch.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/common/db_appinit.c: Likewise. * db2/common/db_err.c: Likewise. * db2/common/db_byteorder.c: Likewise. * db2/common/db_apprec.c: Likewise. * db2/common/db_salloc.c: Likewise. * db2/common/db_log2.c: Likewise. * db2/common/db_region.c: Likewise. * db2/common/db_shash.c: Likewise. * db2/db/db.c: Likewise. * db2/db/db.src: Likewise. * db2/db/db_conv.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/db/db_auto.c: Likewise. * db2/db185/db185.c: Likewise. * db2/db185/db185_int.h: Likewise. * db2/dbm/dbm.c: Likewise. * db2/hash/hash.c: Likewise. * db2/hash/hash.src: Likewise. * db2/hash/hash_page.c: Likewise. * db2/hash/hash_conv.c: Likewise. * db2/hash/hash_debug.c: Likewise. * db2/hash/hash_stat.c: Likewise. * db2/hash/hash_rec.c: Likewise. * db2/hash/hash_dup.c: Likewise. * db2/hash/hash_func.c: Likewise. * db2/hash/hash_auto.c: Likewise. * db2/include/mp.h: Likewise. * db2/include/btree.h: Likewise. * db2/include/db.h.src: Likewise. * db2/include/db_int.h.src: Likewise. * db2/include/db_shash.h: Likewise. * db2/include/db_swap.h: Likewise. * db2/include/db_185.h.src: Likewise. * db2/include/txn.h: Likewise. * db2/include/db_am.h: Likewise. * db2/include/shqueue.h: Likewise. * db2/include/hash.h: Likewise. * db2/include/db_dispatch.h: Likewise. * db2/include/lock.h: Likewise. * db2/include/db_page.h: Likewise. * db2/include/log.h: Likewise. * db2/include/db_auto.h: Likewise. * db2/include/btree_auto.h: Likewise. * db2/include/hash_auto.h: Likewise. * db2/include/log_auto.h: Likewise. * db2/include/txn_auto.h: Likewise. * db2/include/db_ext.h: Likewise. * db2/include/btree_ext.h: Likewise. * db2/include/clib_ext.h: Likewise. * db2/include/common_ext.h: Likewise. * db2/include/hash_ext.h: Likewise. * db2/include/lock_ext.h: Likewise. * db2/include/log_ext.h: Likewise. * db2/include/mp_ext.h: Likewise. * db2/include/mutex_ext.h: Likewise. * db2/include/os_ext.h: Likewise. * db2/include/txn_ext.h: Likewise. * db2/include/cxx_int.h: Likewise. * db2/include/db_cxx.h: Likewise. * db2/include/queue.h: Likewise. * db2/lock/lock.c: Likewise. * db2/lock/lock_conflict.c: Likewise. * db2/lock/lock_util.c: Likewise. * db2/lock/lock_deadlock.c: Likewise. * db2/log/log.c: Likewise. * db2/log/log_get.c: Likewise. * db2/log/log.src: Likewise. * db2/log/log_compare.c: Likewise. * db2/log/log_put.c: Likewise. * db2/log/log_rec.c: Likewise. * db2/log/log_archive.c: Likewise. * db2/log/log_register.c: Likewise. * db2/log/log_auto.c: Likewise. * db2/log/log_findckp.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_region.c: Likewise. * db2/mp/mp_pr.c: Likewise. * db2/mp/mp_sync.c: Likewise. * db2/mutex/68020.gcc: Likewise. * db2/mutex/mutex.c: Likewise. * db2/mutex/README: Likewise. * db2/mutex/x86.gcc: Likewise. * db2/mutex/sparc.gcc: Likewise. * db2/mutex/uts4.cc.s: Likewise. * db2/mutex/alpha.dec: Likewise. * db2/mutex/alpha.gcc: Likewise. * db2/mutex/parisc.gcc: Likewise. * db2/mutex/parisc.hp: Likewise. * db2/os/db_os_abs.c: Likewise. * db2/os/db_os_dir.c: Likewise. * db2/os/db_os_fid.c: Likewise. * db2/os/db_os_lseek.c: Likewise. * db2/os/db_os_mmap.c: Likewise. * db2/os/db_os_open.c: Likewise. * db2/os/db_os_rw.c: Likewise. * db2/os/db_os_sleep.c: Likewise. * db2/os/db_os_stat.c: Likewise. * db2/os/db_os_unlink.c: Likewise. * db2/txn/txn.c: Likewise. * db2/txn/txn.src: Likewise. * db2/txn/txn_rec.c: Likewise. * db2/txn/txn_auto.c: Likewise. * db2/clib/getlong.c: Likewise. * db2/progs/db_archive/db_archive.c: Likewise. * db2/progs/db_checkpoint/db_checkpoint.c: Likewise. * db2/progs/db_deadlock/db_deadlock.c: Likewise. * db2/progs/db_dump/db_dump.c: Likewise. * db2/progs/db_dump185/db_dump185.c: Likewise. * db2/progs/db_load/db_load.c: Likewise. * db2/progs/db_printlog/db_printlog.c: Likewise. * db2/progs/db_recover/db_recover.c: Likewise. * db2/progs/db_stat/db_stat.c: Likewise. * libio/stdio.h [__cplusplus] (__STDIO_INLINE): Define as inline. * po/de.po, po/sv.po: Update from 2.0.5 translations. * sysdeps/unix/sysv/linux/netinet/tcp.h: Pretty print. * sunrpc/rpc/xdr.h (XDR): Don't define argument of x_destroy callback as const. * sunrpc/xdr_mem.c (xdrmem_destroy): Don't define argument as const. * sunrpx/xdr_rec.c (xdrrec_destroy): Likewise. * sunrpx/xdr_stdio.c (xdrstdio_destroy): Likewise. 1997-08-27 18:47 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/if_index.c: Include <errno.h>. Reported by Benjamin Kosnik <bkoz@cygnus.com>. 1997-08-27 02:27 Roland McGrath <roland@baalperazim.frob.com> * abi-tags: New file. * csu/Makefile (distribute): Remove abi-tag.h. ($(objpfx)abi-tag.h): New target. * Makefile (distribute): Add abi-tags. * sysdeps/unix/sysv/linux/abi-tag.h: File removed. * sysdeps/mach/hurd/abi-tag.h: File removed. * sysdeps/stub/abi-tag.h: File removed. 1997-08-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * sysdeps/unix/make-syscalls.sh: Change output so that it generates compilation rules only for the currently selected object suffixes. 1997-08-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * sysdeps/m68k/dl-machine.h (RTLD_START): Switch back to previous section to avoid confusing the compiler. * sysdeps/alpha/dl-machine.h (RTLD_START): Likewise. * sysdeps/i386/dl-machine.h (RTLD_START): Likewise. * sysdeps/mips/dl-machine.h (RTLD_START): Likewise. * sysdeps/mips/mips64/dl-machine.h (RTLD_START): Likewise. * sysdeps/sparc/sparc32/dl-machine.h (RTLD_START): Likewise. * sysdeps/m68k/dl-machine.h (elf_machine_load_address): Use a GOT relocation instead of a constant to avoid text relocation. (ELF_MACHINE_BEFORE_RTLD_RELOC): Removed. (RTLD_START): Declare global labels as functions and add size directive. 1997-08-25 17:01 Ulrich Drepper <drepper@cygnus.com> * sysdeps/i386/bits/select.h: Correct assembler versions to work even for descriptors >= 32. * stdlib/alloca.h: Don't define alloca to __alloca since if gcc is used __alloca is not defined to __builtin_alloca and so might not be available. Reported by Uwe Ohse <uwe@ohse.de>. * sysdeps/unix/sysv/linux/sys/sysmacros.h: Define macros in a special way if gcc is not used and so dev_t is an array. Reported by Uwe Ohse <uwe@ohse.de>. 1997-08-23 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * manual/libc.texinfo: Reorder chapters to match logical order. 1997-08-25 12:22 Ulrich Drepper <drepper@cygnus.com> * sunrpc/rpc/xdr.h: Change name of parameters in prototypes of xdr_reference, xdrmem_create, and xdrstdio_create because of clash with g++ internal symbols. Patch by Sudish Joseph <sj@eng.mindspring.net>. * elf/dl-deps.c: Implement handling of DT_FILTER.
Diffstat (limited to 'db2/os')
-rw-r--r--db2/os/db_os_abs.c82
-rw-r--r--db2/os/db_os_dir.c136
-rw-r--r--db2/os/db_os_fid.c126
-rw-r--r--db2/os/db_os_lseek.c60
-rw-r--r--db2/os/db_os_mmap.c106
-rw-r--r--db2/os/db_os_open.c147
-rw-r--r--db2/os/db_os_rw.c75
-rw-r--r--db2/os/db_os_sleep.c62
-rw-r--r--db2/os/db_os_stat.c84
-rw-r--r--db2/os/db_os_unlink.c35
10 files changed, 913 insertions, 0 deletions
diff --git a/db2/os/db_os_abs.c b/db2/os/db_os_abs.c
new file mode 100644
index 0000000..8795205
--- /dev/null
+++ b/db2/os/db_os_abs.c
@@ -0,0 +1,82 @@
+/*-
+ * 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 <string.h>
+#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
new file mode 100644
index 0000000..23a6a45
--- /dev/null
+++ b/db2/os/db_os_dir.c
@@ -0,0 +1,136 @@
+/*-
+ * 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.7 (Sleepycat) 8/23/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+# include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+# include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+# include <ndir.h>
+# endif
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#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 *, 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;
+
+ if ((dirhandle = _findfirst(dir,&fdata)) == -1) {
+ __db_err(dbenv, "%s: %s", dir, 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
new file mode 100644
index 0000000..8fa55fa
--- /dev/null
+++ b/db2/os/db_os_fid.c
@@ -0,0 +1,126 @@
+/*-
+ * 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.7 (Sleepycat) 8/21/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#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;
+{
+ time_t now;
+ u_int8_t *p;
+ unsigned int i;
+
+#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
new file mode 100644
index 0000000..cecf0e1
--- /dev/null
+++ b/db2/os/db_os_lseek.c
@@ -0,0 +1,60 @@
+/*-
+ * 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 <sys/types.h>
+
+#include <errno.h>
+#include <unistd.h>
+#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
new file mode 100644
index 0000000..0cd8fad
--- /dev/null
+++ b/db2/os/db_os_mmap.c
@@ -0,0 +1,106 @@
+/*-
+ * 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 <sys/types.h>
+#include <sys/mman.h>
+
+#include <errno.h>
+#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
new file mode 100644
index 0000000..1d67ef9
--- /dev/null
+++ b/db2/os/db_os_open.c
@@ -0,0 +1,147 @@
+/*-
+ * 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 <sys/types.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#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
new file mode 100644
index 0000000..5a6c219
--- /dev/null
+++ b/db2/os/db_os_rw.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[] = "@(#)db_os_rw.c 10.4 (Sleepycat) 6/28/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <errno.h>
+#include <unistd.h>
+#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
new file mode 100644
index 0000000..5591789
--- /dev/null
+++ b/db2/os/db_os_sleep.c
@@ -0,0 +1,62 @@
+/*-
+ * 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 <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+#include <errno.h>
+#ifndef HAVE_SYS_TIME_H
+#include <time.h>
+#endif
+#include <unistd.h>
+#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
new file mode 100644
index 0000000..7929b6b
--- /dev/null
+++ b/db2/os/db_os_stat.c
@@ -0,0 +1,84 @@
+/*-
+ * 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 <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <string.h>
+#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
new file mode 100644
index 0000000..872beba
--- /dev/null
+++ b/db2/os/db_os_unlink.c
@@ -0,0 +1,35 @@
+/*-
+ * 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 <sys/types.h>
+
+#include <errno.h>
+#include <unistd.h>
+#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);
+}