Changeset: 2805aaa31ef8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2805aaa31ef8
Modified Files:
NT/monetdb_config.h.in
common/Makefile.ag
common/utils/Makefile.ag
common/utils/mutils.c
common/utils/mutils.h
gdk/Makefile.ag
gdk/gdk.mx
gdk/gdk_bbp.mx
gdk/gdk_posix.mx
gdk/gdk_storage.mx
gdk/gdk_utils.mx
monetdb4/monet/Makefile.ag
monetdb4/monet/monet_tbl.mx
monetdb5/mal/Makefile.ag
monetdb5/mal/mal_linker.mx
monetdb5/misc/Makefile.ag
monetdb5/misc/msabaoth.c
monetdb5/modules/mal/Makefile.ag
monetdb5/modules/mal/mdb.mx
monetdb5/modules/mal/remote.mx
monetdb5/modules/mal/replication.mx
pathfinder/runtime/Makefile.ag
pathfinder/runtime/pf_support.mx
pathfinder/runtime/shttpd.c
sql/backends/monet5/merovingian/client/Makefile.ag
sql/backends/monet5/merovingian/daemon/Makefile.ag
sql/backends/monet5/merovingian/utils/Makefile.ag
sql/backends/monet5/merovingian/utils/database.c
sql/backends/monet5/vaults/Makefile.ag
sql/backends/monet5/vaults/fits.mx
Branch: default
Log Message:
Created NOINST library with some useful stuff.
Revert back to having only a single instance of MT_lockf in this new
library that is used both by GDK and merovingian (through msabaoth).
Also put the Windows-specific implementation of opendir and friends
here.
diffs (truncated from 1068 to 300 lines):
diff --git a/NT/monetdb_config.h.in b/NT/monetdb_config.h.in
--- a/NT/monetdb_config.h.in
+++ b/NT/monetdb_config.h.in
@@ -19,13 +19,14 @@
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
+#include <malloc.h> /* we need malloc.h for alloca() */
+
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
/* In this case, malloc and friends are redefined in crtdbg.h to debug
versions. We need to include stdlib.h and malloc.h first or else
we get conflicting declarations.
*/
#include <stdlib.h>
-#include <malloc.h>
#include <crtdbg.h>
#endif
diff --git a/common/Makefile.ag b/common/Makefile.ag
--- a/common/Makefile.ag
+++ b/common/Makefile.ag
@@ -15,4 +15,4 @@
# Copyright August 2008-2011 MonetDB B.V.
# All Rights Reserved.
-SUBDIRS = stream options
+SUBDIRS = stream options utils
diff --git a/common/utils/Makefile.ag b/common/utils/Makefile.ag
new file mode 100644
--- /dev/null
+++ b/common/utils/Makefile.ag
@@ -0,0 +1,27 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2011 MonetDB B.V.
+# All Rights Reserved.
+
+## Process this file with automake to produce Makefile.in
+
+MTSAFE
+
+EXTRA_DIST = mutils.h
+
+lib_mutils = {
+ NOINST
+ SOURCES = mutils.c
+}
diff --git a/common/utils/mutils.c b/common/utils/mutils.c
new file mode 100644
--- /dev/null
+++ b/common/utils/mutils.c
@@ -0,0 +1,266 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2011 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#include "monetdb_config.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "mutils.h"
+
+#ifdef NATIVE_WIN32
+
+#include <stdio.h>
+
+DIR *
+opendir(const char *dirname)
+{
+ DIR *result = NULL;
+ char *mask;
+ size_t k;
+
+ if (dirname == NULL)
+ return NULL;
+
+ result = (DIR *) malloc(sizeof(DIR));
+ result->find_file_data = malloc(sizeof(WIN32_FIND_DATA));
+ result->dir_name = strdup(dirname);
+
+ k = strlen(result->dir_name);
+ if (k && result->dir_name[k - 1] == '\\') {
+ result->dir_name[k - 1] = '\0';
+ k--;
+ }
+ mask = malloc(strlen(result->dir_name) + 3);
+ sprintf(mask, "%s\\*", result->dir_name);
+
+ result->find_file_handle = FindFirstFile(mask, (LPWIN32_FIND_DATA)
result->find_file_data);
+ free(mask);
+
+ if (result->find_file_handle == INVALID_HANDLE_VALUE) {
+ free(result->dir_name);
+ free(result->find_file_data);
+ free(result);
+ SetLastError(ERROR_OPEN_FAILED); /* enforce EIO */
+ return NULL;
+ }
+ result->just_opened = TRUE;
+
+ return result;
+}
+
+static char *
+basename(const char *file_name)
+{
+ register char *base;
+
+ if (file_name == NULL)
+ return NULL;
+
+ base = strrchr(file_name, '\\');
+ if (base)
+ return base + 1;
+
+ if (isalpha((int) (unsigned char) file_name[0]) && file_name[1] == ':')
+ return (char *) file_name + 2;
+
+ return (char *) file_name;
+}
+
+struct dirent *
+readdir(DIR *dir)
+{
+ static struct dirent result;
+
+ if (dir == NULL)
+ return NULL;
+
+ if (dir->just_opened)
+ dir->just_opened = FALSE;
+ else {
+ if (!FindNextFile(dir->find_file_handle, (LPWIN32_FIND_DATA)
dir->find_file_data)) {
+ int error = GetLastError();
+
+ if (error) {
+ if (error != ERROR_NO_MORE_FILES)
+ SetLastError(ERROR_OPEN_FAILED);
/* enforce EIO */
+ return NULL;
+ }
+ }
+ }
+ strncpy(result.d_name, basename(((LPWIN32_FIND_DATA)
dir->find_file_data)->cFileName), sizeof(result.d_name));
+ result.d_name[sizeof(result.d_name) - 1] = '\0';
+ result.d_namelen = (int) strlen(result.d_name);
+
+ return &result;
+}
+
+void
+rewinddir(DIR *dir)
+{
+ char *mask;
+
+ if (dir == NULL)
+ return;
+
+ if (!FindClose(dir->find_file_handle))
+ fprintf(stderr, "#rewinddir(): FindClose() failed\n");
+
+ mask = malloc(strlen(dir->dir_name) + 3);
+ sprintf(mask, "%s\\*", dir->dir_name);
+ dir->find_file_handle = FindFirstFile(mask, (LPWIN32_FIND_DATA)
dir->find_file_data);
+ free(mask);
+
+ if (dir->find_file_handle == INVALID_HANDLE_VALUE) {
+ SetLastError(ERROR_OPEN_FAILED); /* enforce EIO */
+ return;
+ }
+ dir->just_opened = TRUE;
+}
+
+int
+closedir(DIR *dir)
+{
+ if (dir == NULL)
+ return -1;
+
+ if (!FindClose(dir->find_file_handle)) {
+ SetLastError(ERROR_OPEN_FAILED); /* enforce EIO */
+ return -1;
+ }
+
+ free(dir->dir_name);
+ free(dir->find_file_data);
+ free(dir);
+
+ return 0;
+}
+
+/* see contract of unix MT_lockf */
+int
+MT_lockf(char *filename, int mode, off_t off, off_t len)
+{
+ int ret = 1, illegalmode = 0, fd = -1;
+ OVERLAPPED ov;
+ OSVERSIONINFO os;
+ HANDLE fh = CreateFile(filename,
+ GENERIC_READ | GENERIC_WRITE, 0,
+ NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+
+ os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&os);
+ memset(&ov, 0, sizeof(ov));
+#if defined(DUMMYSTRUCTNAME) && (defined(NONAMELESSUNION) ||
!defined(_MSC_EXTENSIONS)) /* Windows SDK v7.0 */
+ ov.u.s.Offset = (unsigned int) off;
+#if 0
+ ov.u.s.OffsetHigh = off >> 32;
+#else
+ ov.u.s.OffsetHigh = 0; /* sizeof(off) == 4, i.e. off >> 32 is not
possible */
+#endif
+#else
+ ov.Offset = (unsigned int) off;
+#if 0
+ ov.OffsetHigh = off >> 32;
+#else
+ ov.OffsetHigh = 0; /* sizeof(off) == 4, i.e. off >> 32 is not
possible */
+#endif
+#endif
+
+ if (fh == NULL) {
+ return -2;
+ }
+ if (mode == F_ULOCK) {
+ if (os.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
+ ret = UnlockFileEx(fh, 0, 0, len, &ov);
+ } else if (mode == F_TLOCK) {
+ if (os.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
+ ret = LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY |
LOCKFILE_EXCLUSIVE_LOCK, 0, 0, len, &ov);
+ } else if (mode == F_LOCK) {
+ if (os.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
+ ret = LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, 0,
len, &ov);
+ } else {
+ illegalmode = 1;
+ }
+ CloseHandle(fh);
+ if (illegalmode) {
+ SetLastError(ERROR_INVALID_DATA);
+ }
+ if (ret != 0) {
+ fd = open(filename, O_CREAT | O_RDWR, MONETDB_MODE);
+ if (fd < 0) {
+ /* this is nasty, but I "trust" windows that it in this
case
+ * also cannot open the file into a filehandle any
more, so
+ * unlocking is in vain. */
+ return -2;
+ } else {
+ return fd;
+ }
+ } else {
+ return -1;
+ }
+}
+
+#else
+
+#if defined(HAVE_LOCKF) && defined(__MACH__)
+/* lockf() seems to be there, but I didn't find any header file that
+ declares the prototype ... */
+extern int lockf(int fd, int cmd, off_t len);
+#endif
+
+#ifndef HAVE_LOCKF
+/* Cygwin implementation: struct flock is there, but lockf() is
+ missing.
+ */
+static int
+lockf(int fd, int cmd, off_t len)
+{
+ struct flock l;
+
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list