You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/16 08:48:56 UTC
svn commit: r815633 - in /commons/sandbox/runtime/trunk/src/main/native:
Makefile.msc.in include/acr.h include/arch/windows/acr_arch_private.h
os/win32/posix.c os/win32/wutil.c
Author: mturk
Date: Wed Sep 16 06:48:56 2009
New Revision: 815633
URL: http://svn.apache.org/viewvc?rev=815633&view=rev
Log:
Add some handy POSIX functions missing from MSVCRT like getppid()
Added:
commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/include/acr.h
commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=815633&r1=815632&r2=815633&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Wed Sep 16 06:48:56 2009
@@ -117,6 +117,7 @@
$(SRCDIR)/os/win32/ios.$(OBJ) \
$(SRCDIR)/os/win32/mmap.$(OBJ) \
$(SRCDIR)/os/win32/mutex.$(OBJ) \
+ $(SRCDIR)/os/win32/posix.$(OBJ) \
$(SRCDIR)/os/win32/registry.$(OBJ) \
$(SRCDIR)/os/win32/sema.$(OBJ) \
$(SRCDIR)/os/win32/service.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=815633&r1=815632&r2=815633&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Wed Sep 16 06:48:56 2009
@@ -18,7 +18,7 @@
#define _ACR_H
#include "acr_config.h"
-#if HAVE_WINDOWS_H
+#if defined(WIN32) && HAVE_WINDOWS_H
#if !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN
#endif
@@ -167,6 +167,14 @@
#define ACR_ASSERT(x) (void)0
#endif
+#if defined(WIN32)
+/* Add MSVCRT specific includes
+ */
+#include <io.h>
+#include <process.h> /* getpid() */
+#include <sys/stat.h>
+#endif
+
/* JNI header */
#include <jni.h>
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=815633&r1=815632&r2=815633&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Wed Sep 16 06:48:56 2009
@@ -203,6 +203,7 @@
char *x_strdup_utf8(const wchar_t *);
LPWSTR MbsToWcs(DWORD, LPCSTR, LPWSTR, DWORD);
LPSTR WcsToMbs(DWORD, LPCWSTR, LPSTR, DWORD);
+int getppid(void);
/**
* Wide char envvar functions from env.c
Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c?rev=815633&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c Wed Sep 16 06:48:56 2009
@@ -0,0 +1,62 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_error.h"
+#include "acr_memory.h"
+#include "acr_string.h"
+
+
+/* Something that is missing from CRT
+ */
+int getppid()
+{
+ static int ppid = -1;
+ HANDLE snap;
+ PROCESSENTRY32W e;
+
+ if (ppid >= 0) {
+ /* Use the cached value since the parent
+ * cannot change during process lifetime
+ */
+ return ppid;
+ }
+ snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,
+ GetCurrentProcessId());
+ if (IS_INVALID_HANDLE(snap))
+ return -1;
+
+ CloseHandle(snap);
+ e.dwSize = (DWORD)sizeof(PROCESSENTRY32W);
+ if (!Process32FirstW(snap, &e)) {
+ CloseHandle(snap);
+ return -1;
+ }
+ do {
+ if (e.th32ProcessID == GetCurrentProcessId()) {
+ /* We found ourself :)
+ */
+ ppid = e.th32ParentProcessID;
+ break;
+ }
+
+ } while (Process32NextW(snap, &e));
+ CloseHandle(snap);
+
+ return ppid;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c?rev=815633&r1=815632&r2=815633&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wutil.c Wed Sep 16 06:48:56 2009
@@ -388,3 +388,4 @@
return NULL;
}
+