harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [186/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfile.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfile.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfile.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfile.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,936 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+#define CDEV_CURRENT_FUNCTION _comment_
+/**
+ * @file 
+ * @ingroup Port
+ * @brief file
+ */
+#undef CDEV_CURRENT_FUNCTION
+
+#include <windows.h>
+#include <sys/stat.h>
+#include <time.h>
+#include "hyport.h"
+#include "portpriv.h"
+#include "hystdarg.h"
+#include "portnls.h"
+#include "ut_hyprt.h"
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+
+static I_32 findError (I_32 errorCode);
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION findError
+/**
+ * @internal
+ * Determines the proper portable error code to return given a native error code
+ *
+ * @param[in] errorCode The error code reported by the OS
+ *
+ * @return	the (negative) portable error code
+ */
+static I_32
+findError (I_32 errorCode)
+{
+  switch (errorCode)
+    {
+    case ERROR_FILENAME_EXCED_RANGE:
+      return HYPORT_ERROR_FILE_NAMETOOLONG;
+    case ERROR_ACCESS_DENIED:
+      return HYPORT_ERROR_FILE_NOPERMISSION;
+    case ERROR_FILE_NOT_FOUND:
+      return HYPORT_ERROR_FILE_NOTFOUND;
+    case ERROR_DISK_FULL:
+      return HYPORT_ERROR_FILE_DISKFULL;
+    case ERROR_FILE_EXISTS:
+    case ERROR_ALREADY_EXISTS:
+      return HYPORT_ERROR_FILE_EXIST;
+    case ERROR_NOT_ENOUGH_MEMORY:
+      return HYPORT_ERROR_FILE_SYSTEMFULL;
+    default:
+      return HYPORT_ERROR_FILE_OPFAILED;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_attr
+/**
+ * Determine whether path is a file or directory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name being queried.
+ *
+ * @return EslsFile if a file, EslsDir if a directory, negative portable error code on failure.
+ */
+I_32 VMCALL
+hyfile_attr (struct HyPortLibrary * portLibrary, const char *path)
+{
+  DWORD result;
+  result = GetFileAttributes ((LPCTSTR) path);
+  if (result == 0xFFFFFFFF)
+    {
+      result = GetLastError ();
+      return portLibrary->error_set_last_error (portLibrary, result,
+						findError (result));
+    }
+
+  if (result & FILE_ATTRIBUTE_DIRECTORY)
+    {
+      return HyIsDir;
+    }
+
+  /* otherwise assume it's a normal file */
+  return HyIsFile;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_close
+/**
+ * Closes a file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_close (struct HyPortLibrary * portLibrary, IDATA fd)
+{
+  if (CloseHandle ((HANDLE) fd))
+    {
+      return 0;
+    }
+  else
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_error_message
+/**
+ * Return an error message describing the last OS error that occurred.  The last
+ * error returned is not thread safe, it may not be related to the operation that
+ * failed for this thread.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return	error message describing the last OS error, may return NULL.
+ *
+ * @internal
+ * @note  This function gets the last error code from the OS and then returns
+ * the corresponding string.  It is here as a helper function for JCL.  Once hyerror
+ * is integrated into the port library this function should probably disappear.
+ */
+const char *VMCALL
+hyfile_error_message (struct HyPortLibrary *portLibrary)
+{
+  return portLibrary->error_last_error_message (portLibrary);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_findclose
+/**
+ * Close the handle returned from @ref hyfile_findfirst.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] findhandle  Handle returned from @ref hyfile_findfirst.
+ */
+void VMCALL
+hyfile_findclose (struct HyPortLibrary *portLibrary, UDATA findhandle)
+{
+  if (0 == FindClose ((HANDLE) findhandle))
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_findfirst
+/**
+ * Find the first occurrence of a file identified by path.  Answers a handle
+ * to be used in subsequent calls to @ref hyfile_findnext and @ref hyfile_findclose. 
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name being queried.
+ * @param[out] resultbuf filename and path matching path.
+ *
+ * @return valid handle on success, -1 on failure.
+ */
+UDATA VMCALL
+hyfile_findfirst (struct HyPortLibrary *portLibrary, const char *path,
+		  char *resultbuf)
+{
+  WIN32_FIND_DATA lpFindFileData;
+  char newPath[HyMaxPath];
+  HANDLE result;
+
+  strcpy (newPath, path);
+  strcat (newPath, "*");
+
+  result = FindFirstFile ((LPCTSTR) newPath, &lpFindFileData);
+  if (result == INVALID_HANDLE_VALUE)
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return (UDATA) - 1;
+    }
+
+  lstrcpy (resultbuf, lpFindFileData.cFileName);
+  return (UDATA) result;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_findnext
+/**
+ * Find the next filename and path matching a given handle.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] findhandle handle returned from @ref hyfile_findfirst.
+ * @param[out] resultbuf next filename and path matching findhandle.
+ *
+ * @return 0 on success, -1 on failure or if no matching entries.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_findnext (struct HyPortLibrary * portLibrary, UDATA findhandle,
+		 char *resultbuf)
+{
+  WIN32_FIND_DATA lpFindFileData;
+  if (!FindNextFile ((HANDLE) findhandle, &lpFindFileData))
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+
+  lstrcpy (resultbuf, lpFindFileData.cFileName);
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_lastmod
+/**
+ *  Return the last modification time of the file path in seconds.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name being queried.
+ *
+ * @return last modification time on success, -1 on failure.
+ */
+I_64 VMCALL
+hyfile_lastmod (struct HyPortLibrary * portLibrary, const char *path)
+{
+  WIN32_FIND_DATA myStat;
+  HANDLE newHandle;
+  I_64 result, tempResult;
+  I_32 error;
+
+  newHandle = FindFirstFile (path, &myStat);
+  if (newHandle == INVALID_HANDLE_VALUE)
+    {
+      error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+
+  /*
+   * Search MSDN for 'Converting a time_t Value to a File Time' for following implementation.
+   */
+  tempResult =
+    ((I_64) myStat.ftLastWriteTime.
+     dwHighDateTime << (I_64) 32) | (I_64) myStat.ftLastWriteTime.
+    dwLowDateTime;
+
+  result = (tempResult - 116444736000000000) / 10000000;
+
+  if (0 == FindClose (newHandle))
+    {
+      error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error, findError (error));	/* continue */
+    }
+
+  return result;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_length
+/**
+ * Answer the length in bytes of the file.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name being queried.
+ *
+ * @return Length in bytes of the file on success, negative portable error code on failure
+ */
+I_64 VMCALL
+hyfile_length (struct HyPortLibrary * portLibrary, const char *path)
+{
+  WIN32_FIND_DATA myStat;
+  HANDLE newHandle;
+  I_64 result;
+  I_32 error;
+
+  newHandle = FindFirstFile (path, &myStat);
+  if (newHandle == INVALID_HANDLE_VALUE)
+    {
+      error = GetLastError ();
+      return portLibrary->error_set_last_error (portLibrary, error,
+						findError (error));
+    }
+
+  result = ((I_64) myStat.nFileSizeHigh) << 32;
+  result += (I_64) myStat.nFileSizeLow;
+  if (0 == FindClose (newHandle))
+    {
+      error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error, findError (error));	/* continue */
+    }
+
+  return result;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_mkdir
+/**
+ * Create a directory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path Directory to be created.
+ *
+ * @return 0 on success, -1 on failure.
+ * @note Assumes all components of path up to the last directory already exist. 
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_mkdir (struct HyPortLibrary * portLibrary, const char *path)
+{
+  if (CreateDirectory (path, 0))
+    {
+      return 0;
+    }
+  else
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_move
+/**
+ * Move the file pathExist to a new name pathNew.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] pathExist The existing file name.
+ * @param[in] pathNew The new file name.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_move (struct HyPortLibrary * portLibrary, const char *pathExist,
+	     const char *pathNew)
+{
+  if (MoveFile (pathExist, pathNew))
+    {
+      return 0;
+    }
+  else
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_open
+/**
+ * Convert a pathname into a file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path Name of the file to be opened.
+ * @param[in] flags Portable file read/write attributes.
+ * @param[in] mode Platform file permissions.
+ *
+ * @return The file descriptor of the newly opened file, -1 on failure.
+ */
+IDATA VMCALL
+hyfile_open (struct HyPortLibrary * portLibrary, const char *path, I_32 flags,
+	     I_32 mode)
+{
+  DWORD accessMode, shareMode, createMode;
+  HANDLE aHandle;
+  I_32 error;
+
+  Trc_PRT_file_open_Entry (path, flags, mode);
+
+  accessMode = 0;
+  if (flags & HyOpenRead)
+    {
+      accessMode |= GENERIC_READ;
+    }
+  if (flags & HyOpenWrite)
+    {
+      accessMode |= GENERIC_WRITE;
+    }
+
+  shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
+
+  if ((flags & HyOpenCreate) == HyOpenCreate)
+    {
+      createMode = OPEN_ALWAYS;
+    }
+  else if ((flags & HyOpenCreateNew) == HyOpenCreateNew)
+    {
+      createMode = CREATE_NEW;
+    }
+  else
+    {
+      createMode = OPEN_EXISTING;
+    }
+
+  aHandle =
+    CreateFile (path, accessMode, shareMode, NULL, createMode,
+		FILE_ATTRIBUTE_NORMAL, NULL);
+  if (aHandle == INVALID_HANDLE_VALUE)
+    {
+      error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      Trc_PRT_file_open_Exit2 (error, findError (error));
+      return -1;
+    }
+
+  if ((flags & HyOpenTruncate) == HyOpenTruncate)
+    {
+      if (0 == CloseHandle (aHandle))
+	{
+	  error = GetLastError ();
+	  portLibrary->error_set_last_error (portLibrary, error, findError (error));	/* continue */
+	}
+
+      aHandle =
+	CreateFile (path, accessMode, shareMode, NULL, TRUNCATE_EXISTING,
+		    FILE_ATTRIBUTE_NORMAL, NULL);
+      if (aHandle == INVALID_HANDLE_VALUE)
+	{
+	  error = GetLastError ();
+	  portLibrary->error_set_last_error (portLibrary, error,
+					     findError (error));
+	  Trc_PRT_file_open_Exit3 (error, findError (error));
+	  return -1;
+	}
+    }
+
+  if (flags & HyOpenAppend)
+    {
+      portLibrary->file_seek (portLibrary, (IDATA) aHandle, 0, HySeekEnd);
+    }
+
+  Trc_PRT_file_open_Exit (aHandle);
+  return ((IDATA) aHandle);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_read
+/**
+ * Read bytes from a file descriptor into a user provided buffer.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ * @param[in,out] buf Buffer to read into.
+ * @param[in] nbytes Size of buffer.
+ *
+ * @return The number of bytes read, or -1 on failure.
+ */
+IDATA VMCALL
+hyfile_read (struct HyPortLibrary * portLibrary, IDATA fd, void *buf,
+	     IDATA nbytes)
+{
+  DWORD bytesRead;
+
+  if (nbytes == 0)
+    {
+      return 0;
+    }
+
+  if (!ReadFile ((HANDLE) fd, buf, nbytes, &bytesRead, NULL))
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+  if (bytesRead == 0)
+    {
+      return -1;
+    }
+
+  return bytesRead;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_seek
+/**
+ * Repositions the offset of the file descriptor to a given offset as per directive whence.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ * @param[in] offset The offset in the file to position to.
+ * @param[in] whence Portable constant describing how to apply the offset.
+ *
+ * @return The resulting offset on success, -1 on failure.
+ * @note whence is one of HySeekSet (seek from beginning of file), 
+ * HySeekCur (seek from current file pointer) or HySeekEnd (seek backwards from
+ * end of file).
+ * @internal @note seek operations return -1 on failure.  Negative offsets
+ * can be returned when seeking beyond end of file.
+ */
+I_64 VMCALL
+hyfile_seek (struct HyPortLibrary * portLibrary, IDATA fd, I_64 offset,
+	     I_32 whence)
+{
+  DWORD moveMethod, moveResult;
+  DWORD lowerOffset, upperOffset;
+  I_64 result;
+  I_32 error;
+
+  lowerOffset = (DWORD) (offset & 0xFFFFFFFF);
+  upperOffset = (DWORD) (offset >> 32);
+
+  if ((whence < HySeekSet) || (whence > HySeekEnd))
+    {
+      return -1;
+    }
+  if (whence == HySeekSet)
+    {
+      moveMethod = FILE_BEGIN;
+    }
+  if (whence == HySeekEnd)
+    {
+      moveMethod = FILE_END;
+    }
+  if (whence == HySeekCur)
+    {
+      moveMethod = FILE_CURRENT;
+    }
+  moveResult =
+    SetFilePointer ((HANDLE) fd, lowerOffset, &upperOffset, moveMethod);
+  if (-1 == moveResult)
+    {
+      error = GetLastError ();
+      if (error != NO_ERROR)
+	{
+	  portLibrary->error_set_last_error (portLibrary, error,
+					     findError (error));
+	  return -1;
+	}
+    }
+
+  result = (I_64) upperOffset << 32;
+  result |= moveResult;
+
+  return result;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hyfile_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hyfile_shutdown (struct HyPortLibrary *portLibrary)
+{
+  /* empty */
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_startup
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the file operations may be created here.  All resources created here should be destroyed
+ * in @ref hyfile_shutdown.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are
+ * \arg HYPORT_ERROR_STARTUP_FILE
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hyfile_startup (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_sync
+/**
+ * Synchronize a file's state with the state on disk.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_sync (struct HyPortLibrary * portLibrary, IDATA fd)
+{
+  if (FlushFileBuffers ((HANDLE) fd))
+    {
+      return 0;
+    }
+  else
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_unlink
+/**
+ * Remove a file from the file system.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path file/path name to remove.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+I_32 VMCALL
+hyfile_unlink (struct HyPortLibrary * portLibrary, const char *path)
+{
+  /* should be able to delete read-only dirs, so we set the file attribute back to normal */
+  if (0 == SetFileAttributes (path, FILE_ATTRIBUTE_NORMAL))
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error, findError (error));	/* continue */
+    }
+
+  if (DeleteFile (path))
+    {
+      return 0;
+    }
+  else
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_unlinkdir
+/**
+ * Remove the trailing directory of the path. If the path is a symbolic link to a directory, remove
+ * the symbolic link.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path directory name being removed.
+ *
+ * @return 0 on success, -1 on failure.
+ * @internal @todo return negative portable return code on failure..
+ */
+I_32 VMCALL
+hyfile_unlinkdir (struct HyPortLibrary * portLibrary, const char *path)
+{
+  /* should be able to delete read-only dirs, so we set the file attribute back to normal */
+  if (0 == SetFileAttributes (path, FILE_ATTRIBUTE_NORMAL))
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error, findError (error));	/* continue */
+    }
+
+  if (RemoveDirectory (path))
+    {
+      return 0;
+    }
+  else
+    {
+      I_32 error = GetLastError ();
+      portLibrary->error_set_last_error (portLibrary, error,
+					 findError (error));
+      return -1;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_vprintf
+/**
+ * Write to a file.
+ *
+ * Writes formatted output  to the file referenced by the file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd File descriptor to write.
+ * @param[in] format The format String.
+ * @param[in] args Variable argument list.
+ */
+void VMCALL
+hyfile_vprintf (struct HyPortLibrary *portLibrary, IDATA fd,
+		const char *format, va_list args)
+{
+  char outputBuffer[256];
+
+  char *allocatedBuffer;
+  U_32 numberWritten;
+  va_list copyOfArgs;
+
+  /* Attempt to write output to stack buffer */
+  COPY_VA_LIST (copyOfArgs, args);
+  numberWritten =
+    portLibrary->str_vprintf (portLibrary, outputBuffer,
+			      sizeof (outputBuffer), format, copyOfArgs);
+
+  /* str_vprintf always null terminates, returns number characters written excluding the null terminator */
+  if (sizeof (outputBuffer) > (numberWritten + 1))
+    {
+      /* write out the buffer */
+      portLibrary->file_write_text (portLibrary, fd, outputBuffer,
+				    numberWritten);
+      return;
+    }
+
+  /* Either the buffer was too small, or it was the exact size.  Unfortunately can't tell the difference,
+   * need to determine the size of the buffer (another call to str_vprintf) then print to the buffer,
+   * a third call to str_vprintf
+   */
+  COPY_VA_LIST (copyOfArgs, args);
+
+  /* What is size of buffer required ? Does not include the \0 */
+  numberWritten =
+    portLibrary->str_vprintf (portLibrary, NULL, (U_32) (-1), format,
+			      copyOfArgs);
+  numberWritten += 1;
+
+  allocatedBuffer =
+    portLibrary->mem_allocate_memory (portLibrary, numberWritten);
+  if (NULL == allocatedBuffer)
+    {
+      portLibrary->nls_printf (portLibrary, HYNLS_ERROR,
+			       HYNLS_PORT_FILE_MEMORY_ALLOCATE_FAILURE);
+      return;
+    }
+
+  numberWritten =
+    portLibrary->str_vprintf (portLibrary, allocatedBuffer, numberWritten,
+			      format, args);
+  portLibrary->file_write_text (portLibrary, fd, allocatedBuffer,
+				numberWritten);
+  portLibrary->mem_free_memory (portLibrary, allocatedBuffer);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_write
+/**
+ * Write to a file.
+ *
+ * Writes up to nbytes from the provided buffer  to the file referenced by the file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd File descriptor to write.
+ * @param[in] buf Buffer to be written.
+ * @param[in] nbytes Size of buffer.
+ *
+ * @return Number of bytes written on success,  -1 on failure.
+ * @internal @todo return negative portable return code on failure.
+ */
+IDATA VMCALL
+hyfile_write (struct HyPortLibrary * portLibrary, IDATA fd, void *buf,
+	      IDATA nbytes)
+{
+  DWORD nCharsWritten;
+  IDATA toWrite, offset = 0;
+  I_32 errorCode;
+  HANDLE handle;
+
+  if (fd == HYPORT_TTY_OUT)
+    {
+      handle = PPG_tty_consoleOutputHd;
+    }
+  else if (fd == HYPORT_TTY_ERR)
+    {
+      handle = PPG_tty_consoleErrorHd;
+    }
+  else
+    {
+      handle = (HANDLE) fd;
+    }
+
+  toWrite = nbytes;
+  while (nbytes > 0)
+    {
+      if (toWrite > nbytes)
+	{
+	  toWrite = nbytes;
+	}
+      if (!WriteFile
+	  (handle, (char *) buf + offset, toWrite, &nCharsWritten, NULL))
+	{
+	  errorCode = GetLastError ();
+	  if (errorCode == ERROR_NOT_ENOUGH_MEMORY)
+	    {
+	      /* Use 48K chunks to get around out of memory problem */
+	      if (toWrite > (48 * 1024))
+		{
+		  toWrite = 48 * 1024;
+		}
+	      else
+		{
+		  toWrite /= 2;
+		}
+	      /* If we can't write 128 bytes, just return */
+	      if (toWrite >= 128)
+		{
+		  continue;
+		}
+	    }
+	  return portLibrary->error_set_last_error (portLibrary, errorCode,
+						    findError (errorCode));
+	}
+      offset += nCharsWritten;
+      nbytes -= nCharsWritten;
+    }
+
+  return (IDATA) offset;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_printf
+/** 
+ * Write to a file.
+ *
+ * Writes formatted output  to the file referenced by the file descriptor.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd File descriptor to write to
+ * @param[in] format The format string to be output.
+ * @param[in] ... arguments for format.
+ */
+void VMCALL
+hyfile_printf (struct HyPortLibrary *portLibrary, IDATA fd,
+	       const char *format, ...)
+{
+  va_list args;
+
+  va_start (args, format);
+  portLibrary->file_vprintf (portLibrary, fd, format, args);
+  va_end (args);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_set_length
+/**
+ * Set the length of a file to a specified value.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd The file descriptor.
+ * @param[in] newLength Length to be set
+ *
+ * @return 0 on success, negative portable error code on failure
+ */
+I_32 VMCALL
+hyfile_set_length (struct HyPortLibrary *portLibrary, IDATA fd,
+		   I_64 newLength)
+{
+  I_32 result, error;
+  I_32 lowValue, highValue;
+
+  lowValue = (I_32) (newLength & 0xFFFFFFFF);
+  highValue = (I_32) (newLength >> 32);
+
+  result = SetFilePointer ((HANDLE) fd, lowValue, &highValue, FILE_BEGIN);
+  error = GetLastError ();
+  if ((result == -1) && (error != NO_ERROR))
+    {
+      return portLibrary->error_set_last_error (portLibrary, error,
+						findError (error));
+    }
+  else
+    {
+      if (0 == SetEndOfFile ((HANDLE) fd))
+	{
+	  error = GetLastError ();
+	  return portLibrary->error_set_last_error (portLibrary, error,
+						    findError (error));
+	}
+      /* Put pointer back to where it started */
+      result = SetFilePointer ((HANDLE) fd, result, &highValue, FILE_BEGIN);
+      error = GetLastError ();
+      if ((result == -1) && (error != NO_ERROR))
+	{
+	  return portLibrary->error_set_last_error (portLibrary, error,
+						    findError (error));
+	}
+    }
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfiletext.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfiletext.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfiletext.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfiletext.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,259 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+#define CDEV_CURRENT_FUNCTION _comment_
+/**
+ * @file
+ * @ingroup Port
+ * @brief file
+ */
+#undef CDEV_CURRENT_FUNCTION
+
+#include <windows.h>
+#include "hyport.h"
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+U_32 decodeUTF8CharN (const U_8 * input, U_16 * result, U_32 bytesRemaining);
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_read_text
+/**
+ * Read a line of text from the file into buf.  Text is converted from the platform file encoding to UTF8.
+ * This is mostly equivalent to fgets in standard C.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd File descriptor.
+ * @param[in,out] buf Buffer for read in text.
+ * @param[in] nbytes Size of buffer.
+ *
+ * @return buf on success, NULL on failure.
+ */
+char *VMCALL
+hyfile_read_text (struct HyPortLibrary *portLibrary, IDATA fd, char *buf,
+		  IDATA nbytes)
+{
+  char temp[64];
+  IDATA count, i;
+  char *cursor = buf;
+
+  if (nbytes <= 0)
+    {
+      return 0;
+    }
+
+  /* discount 1 for the trailing NUL */
+  nbytes -= 1;
+
+  while (nbytes)
+    {
+      count = sizeof (temp) > nbytes ? nbytes : sizeof (temp);
+      count = portLibrary->file_read (portLibrary, fd, temp, count);
+
+      /* ignore translation for now */
+      if (count < 0)
+	{
+	  if (cursor == buf)
+	    {
+	      return NULL;
+	    }
+	  else
+	    {
+	      break;
+	    }
+	}
+
+      for (i = 0; i < count; i++)
+	{
+	  char c = temp[i];
+
+	  if (c == '\r')
+	    {			/* EOL */
+	      /* is this a bare CR, or part of a CRLF pair? */
+	      portLibrary->file_seek (portLibrary, fd, i - count + 1,
+				      HySeekCur);
+	      count = portLibrary->file_read (portLibrary, fd, temp, 1);
+	      if (count && temp[0] == '\n')
+		{
+		  /* matched CRLF pair */
+		  *cursor++ = '\n';
+		}
+	      else
+		{
+		  /* this was a bare CR -- back up */
+		  *cursor++ = '\r';
+		  portLibrary->file_seek (portLibrary, fd, -1, HySeekCur);
+		}
+	      *cursor = '\0';
+	      return buf;
+	    }
+	  else if (c == '\n')
+	    {			/* this can only be a bare LF */
+	      portLibrary->file_seek (portLibrary, fd, i - count + 1,
+				      HySeekCur);
+	      *cursor++ = '\n';
+	      *cursor = '\0';
+	      return buf;
+	    }
+	  else
+	    {
+	      *cursor++ = c;
+	    }
+
+	}
+      nbytes -= count;
+    }
+
+  *cursor = '\0';
+  return buf;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyfile_write_text
+/**
+ * Output the buffer onto the stream as text. The buffer is a UTF8-encoded array of chars.
+ * It is converted to the appropriate platform encoding.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fd the file descriptor.
+ * @param[in] buf buffer of text to be output.
+ * @param[in] nbytes size of buffer of text to be output.
+ *
+ * @return 0 on success, negative error code on failure.
+ */
+IDATA VMCALL
+hyfile_write_text (struct HyPortLibrary * portLibrary, IDATA fd,
+		   const char *buf, IDATA nbytes)
+{
+  IDATA result;
+  IDATA i;
+  int newlines = 0, highchars = 0;
+  char stackBuf[512];
+  char *newBuf = stackBuf;
+  IDATA newLen;
+
+  /* scan the buffer for any characters which need to be converted */
+  for (i = 0; i < nbytes; i++)
+    {
+      if (buf[i] == '\n')
+	{
+	  newlines += 1;
+	}
+      else if ((U_8) buf[i] & 0x80)
+	{
+	  highchars += 1;
+	}
+    }
+
+  /* if there are any non-ASCII chars, convert to Unicode and then to the local code page */
+  if (highchars)
+    {
+      U_16 wStackBuf[512];
+      U_16 *wBuf = wStackBuf;
+      newLen = (nbytes + newlines) * 2;
+      if (newLen > sizeof (wStackBuf))
+	{
+	  wBuf = portLibrary->mem_allocate_memory (portLibrary, newLen);
+	}
+      if (wBuf)
+	{
+	  U_8 *in = (U_8 *) buf;
+	  U_8 *end = in + nbytes;
+	  U_16 *out = wBuf;
+
+	  while (in < end)
+	    {
+	      if (*in == '\n')
+		{
+		  *out++ = (U_16) '\r';
+		  *out++ = (U_16) '\n';
+		  in += 1;
+		}
+	      else
+		{
+		  U_32 numberU8Consumed =
+		    decodeUTF8CharN (in, out++, end - in);
+		  if (numberU8Consumed == 0)
+		    {
+		      break;
+		    }
+		  in += numberU8Consumed;
+		}
+	    }
+	  /* in will be NULL if an error occurred */
+	  if (in)
+	    {
+	      UINT codePage = GetConsoleOutputCP ();
+	      IDATA wLen = out - wBuf;
+	      IDATA mbLen =
+		WideCharToMultiByte (codePage, 0, wBuf, wLen, NULL, 0, NULL,
+				     NULL);
+	      if (mbLen > 0)
+		{
+		  if (mbLen > sizeof (stackBuf))
+		    {
+		      newBuf =
+			portLibrary->mem_allocate_memory (portLibrary, mbLen);
+		      /* if we couldn't allocate the buffer, just output the data the way it was */
+		    }
+		  if (newBuf)
+		    {
+		      WideCharToMultiByte (codePage, 0, wBuf, wLen, newBuf,
+					   mbLen, NULL, NULL);
+		      buf = newBuf;
+		      nbytes = mbLen;
+		    }
+		}
+	    }
+	  if (wBuf != wStackBuf)
+	    {
+	      portLibrary->mem_free_memory (portLibrary, wBuf);
+	    }
+	}
+    }
+  else if (newlines)
+    {
+      /* change any LFs to CRLFs */
+      newLen = nbytes + newlines;
+      if (newLen > sizeof (stackBuf))
+	{
+	  newBuf = portLibrary->mem_allocate_memory (portLibrary, newLen);
+	  /* if we couldn't allocate the buffer, just output the data the way it was */
+	}
+      if (newBuf)
+	{
+	  char *cursor = newBuf;
+	  for (i = 0; i < nbytes; i++)
+	    {
+	      if (buf[i] == '\n')
+		*cursor++ = '\r';
+	      *cursor++ = buf[i];
+	    }
+	  buf = newBuf;
+	  nbytes = newLen;
+	}
+    }
+
+  result = portLibrary->file_write (portLibrary, fd, (void *) buf, nbytes);
+
+  if (newBuf != stackBuf && newBuf != NULL)
+    {
+      portLibrary->mem_free_memory (portLibrary, newBuf);
+    }
+
+  return (result == nbytes) ? 0 : result;
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfpu.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfpu.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfpu.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyfpu.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,25 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+#if !defined(hyfpu_h)
+#define hyfpu_h
+
+#if defined(_X86_)
+#define 	HYPORT_SETUP_FPU_STATE() helperInitializeFPU()
+#else
+#define 	HYPORT_SETUP_FPU_STATE()
+#endif
+
+#endif /* hyfpu_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hygp.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hygp.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hygp.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hygp.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,161 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+/**
+ * @ingroup Port
+ * @file
+ * Provides platform-neutral signal handling functions.  
+ * The @ref hygp_register_handler function is partially dependent on internal
+ * VM structures, and must be called with NULL as a third (userData) parameter.
+ * <br><br>
+ */
+
+#include "hyport.h"
+#include "hycomp.h"
+#include "gp.h"
+
+/**
+ * Kicks off the new thread by calling the function provided in protected_fn fn.
+ *
+ * All threads spawned by the vm start here and all OS signals that will be handled
+ *  by fn must be registered to the OS here. 
+ * Upon receiving a signal from the OS, fn is responsible for calling the function
+ * specified in @ref hygp_register_handler if it is determined that a shutdown is required.
+ * 
+ * @param[in] portLibrary The port library
+ * @param[in] fn the function that will be used to kick off the thread
+ * @param[in] arg arguments to protected_fn fn
+ *
+ * @return the return value of the function provided in fn
+ * 
+ * @note it is a good idea to save the portLibrary in case a registered exception handler cannot be found
+ */
+UDATA VMCALL
+hygp_protect (struct HyPortLibrary * portLibrary, protected_fn fn, void *arg)
+{
+  /* sorry!  No way to protect it generically.  Just run it. */
+  return fn (arg);
+}
+
+/**
+ * Sets the function that is responsible for preserving/outputting the state of the vm
+ * and initiating a graceful shutdown resulting from a gp.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] fn function responsible for preserving/outputting the state of the vm and
+ * initiating a graceful shutdown resulting from a gp.
+ * @param[in] aUserData The HyJavaVM or NULL for non-HY consumers.
+ *
+ * @note vmGPHandler in gphandle.c is currently the only function used for handling gps. 
+ * @note  fn is not called by the OS but by the gp handler function specified in the call
+ * to @ref hygp_protect gp module
+ * @note above occurs after the OS has passed a signal along to us and it is determined
+ * that a shutdown is required.
+ */
+void VMCALL
+hygp_register_handler (struct HyPortLibrary *portLibrary, handler_fn fn,
+		       void *aUserData)
+{
+  /* empty */
+}
+
+/**
+ * Provides the name and value, specified by category/index of the gp information in info. 
+ * Returns the kind of information found at category/index specified, or undefined 
+ * if the category/index are invalid.  The number of items in the category specified must 
+ * equal the count @ref hygp_info_count returns for that category. 
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] info struct containing all available signal information. Normally includes
+ *            register values, name of module where crash occured and its base address.
+ * @param[in] category the category of signal information that you are querying. 
+ * @param[in] index the index of the item in the specified category. The number of items
+ *            for each category are defined in the sourceTemplate.
+ * @param[out] name the name of the item at the specified index.  
+ * @param[out] value the value of the item at the specified index
+ *
+ * @return the kind of info at the specified index. For example, this allows the caller to
+ *         determine whether the item placed in **value corresponds to a 32/64-bit integer
+ *         or a pointer to a string. 
+ *
+ * @note The program counter and module name also have negative indexes as defined by
+ *       HYGP_CONTROL_PC and HYGP_MODULE_NAME respectively.
+ * @note Above allows the handler function registered in @ref hygp_register_handler to
+ *       distinguish (and use) them from the other gp items.
+ * @note The caller is responsible for allocating and freeing any buffers used by **name, **value.
+ */
+U_32 VMCALL
+hygp_info (struct HyPortLibrary *portLibrary, void *info, U_32 category,
+	   I_32 index, const char **name, void **value)
+{
+  /* default implementation can't do anything */
+  return 0;
+}
+
+/**
+ * Returns the number of items that exist in the category specified, or zero if the category
+ * is undefined.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] info struct containing all available signal information. Normally includes register
+ *            values, name of module where crash occured and its base address. 
+ * @param[in] category the category in which we want to find the number of items that exist.
+ *
+ * @note Return value must agree with the number of items that @ref hygp_info makes available for
+ *       the category specified. 
+*/
+U_32 VMCALL
+hygp_info_count (struct HyPortLibrary * portLibrary, void *info,
+		 U_32 category)
+{
+  /* default implementation can't do anything */
+  return 0;
+}
+
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created 
+ * by @ref hygp_startup should be destroyed here.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hygp_shutdown (struct HyPortLibrary *portLibrary)
+{
+  /* empty */
+}
+
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the shared library operation may be created here.  All resources created here should be destroyed
+ * in @ref hygp_shutdown.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are
+ * \arg HYPORT_ERROR_STARTUP_GP
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hygp_startup (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hygp.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hygp.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hygp.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hygp.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,31 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+#if !defined(hygp_h)
+#define hygp_h
+
+void VMCALL hygp_register_handler (struct HyPortLibrary *portLibrary,
+				   handler_fn fn, void *aUserData);
+I_32 VMCALL hygp_startup (struct HyPortLibrary *portLibrary);
+void VMCALL hygp_shutdown (struct HyPortLibrary *portLibrary);
+UDATA VMCALL hygp_protect (struct HyPortLibrary *portLibrary, protected_fn fn,
+			   void *arg);
+U_32 VMCALL hygp_info_count (struct HyPortLibrary *portLibrary, void *info,
+			     U_32 category);
+U_32 VMCALL hygp_info (struct HyPortLibrary *portLibrary, void *info,
+		       U_32 category, I_32 index, const char **name,
+		       void **value);
+
+#endif /* hygp_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyipcmutex.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyipcmutex.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyipcmutex.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hyipcmutex.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,185 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+#define CDEV_CURRENT_FUNCTION _comment_
+/**
+ * @file
+ * @ingroup Port
+ * @brief Shared Resource Mutex
+ *
+ * The HYIPCMutex is used to protect a shared resource from simultaneous access by processes
+ * or threads executing in the same or different VMs.
+ * Each process/thread must request and wait for the ownership of the shared resource before
+ * it can use that resource. It must also release the ownership of the resource as soon as it
+ * has finished using it so that other processes competing for the same resource are not delayed.
+ */
+#undef CDEV_CURRENT_FUNCTION
+
+#include <windows.h>
+#include "hyport.h"
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+/* no prototypes */
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyipcmutex_acquire
+/**
+ * Acquires a named mutex for the calling process.
+ *
+ * If a Mutex with the same Name already exists, the function opens the existing Mutex and tries
+ * to lock it. If another process already has the Mutex locked, the function will block indefinetely. 
+ * If there is no Mutex with the same Name, the function will create it and lock it for the calling
+ * process of this function.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] name Mutex to be acquired
+ *
+ * @return 0 on success, -1 on error.
+ *
+ * @note The Mutex must be explicitly released by calling the @ref hyipcmutex_release function as 
+ * soon as the lock is no longer required.
+ */
+I_32 VMCALL
+hyipcmutex_acquire (struct HyPortLibrary * portLibrary, const char *name)
+{
+  HANDLE hMutex;
+  DWORD dwResult;
+
+  /* check length of name */
+  if (strlen (name) > MAX_PATH)
+    {
+      return -1;
+    }
+
+  /* Create a named mutex or get its handle if it already exists */
+  hMutex = CreateMutex (NULL, FALSE,	/* Not owned on creation */
+			(LPCTSTR) name);	/* Mutex name */
+
+  if (hMutex == NULL)
+    {
+      return -1;
+    }
+  else
+    {
+      /* Wait until mutex is released by other process */
+      dwResult = WaitForSingleObject (hMutex,	/* Handle to mutex */
+				      INFINITE);	/* Block indefinetely */
+
+      /* if state of mutex was signaled within wait interval or mutex was abandoned, return true */
+      /* otherwise function timeout, so return false */
+      if (dwResult == WAIT_OBJECT_0 || dwResult == WAIT_ABANDONED)
+	{
+	  return 0;
+	}
+      else
+	{
+	  return -1;
+	}
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyipcmutex_release
+/**
+ * Releases a named Mutex from the calling process.
+ *
+ * If a Mutex with the same Name already exists, the function opens the existing Mutex
+ * and tries to unlock it.
+ * This function will fail if a Mutex with the given Name is not found or if the Mutex
+ * cannot be unlocked.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] name Mutex to be released.
+ *
+ * @return 0 on success, -1 on error.
+ *
+ * @note Callers of this function must have called the function @ref hyipcmutex_acquire
+ * prior to calling this function.
+ */
+I_32 VMCALL
+hyipcmutex_release (struct HyPortLibrary * portLibrary, const char *name)
+{
+  HANDLE hMutex;
+
+  /* check length of name */
+  if (strlen (name) > MAX_PATH)
+    {
+      return -1;
+    }
+
+  /* Open handle to mutex */
+  hMutex = OpenMutex (MUTEX_ALL_ACCESS, FALSE,	/* Will be ignored for existing mutex */
+		      (LPCTSTR) name);	/* Mutex name */
+
+  if (hMutex == NULL)
+    {
+      return -1;
+    }
+
+  /* release mutex */
+  if (ReleaseMutex (hMutex) == 0)
+    {
+      return -1;
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyipcmutex_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created
+ * by @ref hyipcmutex_startup should be destroyed here.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hyipcmutex_shutdown (struct HyPortLibrary *portLibrary)
+{
+  /* empty */
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hyipcmutex_startup
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the IPC mutex operations may be created here.  All resources created here should be destroyed
+ * in @ref hyipcmutex_shutdown.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are
+ * \arg HYPORT_ERROR_STARTUP_IPCMUTEX
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hyipcmutex_startup (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hymem.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hymem.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hymem.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hymem.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,238 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+#define CDEV_CURRENT_FUNCTION _comment_
+/**
+ * @file
+ * @ingroup Port
+ * @brief Memory Utilities
+ */
+#undef CDEV_CURRENT_FUNCTION
+
+/* 
+ * This file contains code for the portability library memory management.
+ */
+
+#include <windows.h>
+#include "hyport.h"
+#include "portpriv.h"
+#include "hyportpg.h"
+#include "ut_hyprt.h"
+
+#define ROUND_TO(granularity, number) ((number) + \
+                                       (((number) % (granularity)) ? ((granularity) - ((number) % (granularity))) : 0))
+
+#define CDEV_CURRENT_FUNCTION hymem_allocate_memory
+/**
+ * Allocate memory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] byteAmount Number of bytes to allocate.
+ *
+ * @return pointer to memory on success, NULL on error.
+ * @return Memory is not guaranteed to be zeroed as part of this call
+ *
+ * @internal @warning Do not call error handling code @ref hyerror upon error as 
+ * the error handling code uses per thread buffers to store the last error.  If memory
+ * can not be allocated the result would be an infinite loop.
+ */
+void *VMCALL
+hymem_allocate_memory (struct HyPortLibrary *portLibrary, UDATA byteAmount)
+{
+  void *pointer = NULL;
+
+  Trc_PRT_mem_hymem_allocate_memory_Entry (byteAmount);
+  if (byteAmount == 0)
+    {				/* prevent GlobalLock from failing causing allocate to return null */
+      byteAmount = 1;
+    }
+  pointer = HeapAlloc (PPG_mem_heap, 0, byteAmount);
+  Trc_PRT_mem_hymem_allocate_memory_Exit (pointer);
+  return pointer;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymem_free_memory
+/**
+ * Deallocate memory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] memoryPointer Base address of memory to be deallocated.
+ */
+void VMCALL
+hymem_free_memory (struct HyPortLibrary *portLibrary, void *memoryPointer)
+{
+  Trc_PRT_mem_hymem_free_memory_Entry (memoryPointer);
+  HeapFree (PPG_mem_heap, 0, memoryPointer);
+  Trc_PRT_mem_hymem_free_memory_Exit ();
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymem_reallocate_memory
+/**
+ * Re-allocate memory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] memoryPointer Base address of memory to be re-allocated.
+ * @param[in] byteAmount Number of bytes to re-allocated.
+ *
+ * @return pointer to memory on success, NULL on error.
+ *
+ * @internal @warning Do not call error handling code @ref hyerror upon error as 
+ * the error handling code uses per thread buffers to store the last error.  If memory
+ * can not be allocated the result would be an infinite loop.
+ */
+void *VMCALL
+hymem_reallocate_memory (struct HyPortLibrary *portLibrary,
+			 void *memoryPointer, UDATA byteAmount)
+{
+  void *ptr = NULL;
+
+  Trc_PRT_mem_hymem_reallocate_memory_Entry (memoryPointer, byteAmount);
+  ptr = HeapReAlloc (PPG_mem_heap, 0, memoryPointer, byteAmount);
+  Trc_PRT_mem_hymem_reallocate_memory_Exit (ptr);
+  return ptr;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymem_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that
+ * were created by @ref hymem_startup should be destroyed here.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @note Must deallocate portGlobals.
+ * @note Most implementations will just deallocate portGlobals.
+ */
+void VMCALL
+hymem_shutdown (struct HyPortLibrary *portLibrary)
+{
+  if (NULL != portLibrary->portGlobals)
+    {
+      HANDLE memHeap = GetProcessHeap ();
+
+      /* has to be cleaned up with HeapFree since hymem_startup allocated it with HeapAlloc */
+      HeapFree (memHeap, 0, portLibrary->portGlobals);
+      portLibrary->portGlobals = NULL;
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymem_startup
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the memory operations may be created here.  All resources created here should be destroyed
+ * in @ref hymem_shutdown.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] portGlobalSize Size of the global data structure to allocate
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are \arg HYPORT_ERROR_STARTUP_MEM
+ *
+ * @note Must allocate portGlobals.
+ * @note Most implementations will just allocate portGlobals.
+ *
+ * @internal @note portLibrary->portGlobals must point to an aligned structure
+ */
+I_32 VMCALL
+hymem_startup (struct HyPortLibrary *portLibrary, UDATA portGlobalSize)
+{
+  HANDLE memHeap = GetProcessHeap ();
+  /* done as a HeapAlloc because hymem_allocate_memory requires portGlobals to be initialized */
+  portLibrary->portGlobals = HeapAlloc (memHeap, 0, portGlobalSize);
+  if (!portLibrary->portGlobals)
+    {
+      return HYPORT_ERROR_STARTUP_MEM;
+    }
+  memset (portLibrary->portGlobals, 0, portGlobalSize);
+
+  PPG_mem_heap = memHeap;
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymem_allocate_memory_callSite
+/**
+ * Allocate memory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] byteAmount Number of bytes to allocate.
+ * @param[in] callSite String describing callsite, usually file and line number.
+ *
+ * @return pointer to memory on success, NULL on error.
+ *
+ * @internal @warning Do not call error handling code @ref hyerror upon error as 
+ * the error handling code uses per thread buffers to store the last error.  If memory
+ * can not be allocated the result would be an infinite loop.
+ */
+void *VMCALL
+hymem_allocate_memory_callSite (struct HyPortLibrary *portLibrary,
+				UDATA byteAmount, char *callSite)
+{
+  void *ptr = NULL;
+
+  Trc_PRT_mem_hymem_allocate_memory_callSite_Entry (byteAmount, callSite);
+  ptr = portLibrary->mem_allocate_memory (portLibrary, byteAmount);
+  Trc_PRT_mem_hymem_allocate_memory_callSite_Exit (ptr);
+  return ptr;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymem_allocate_portLibrary
+/**
+ * @internal Allocate memory for a portLibrary.
+ *
+ * @param[in] byteAmount Number of bytes to allocate.
+ *
+ * @return pointer to memory on success, NULL on error.
+ * @note This function is called prior to the portLibrary being initialized
+ * @note Must be implemented for all platforms.
+ */
+void *VMCALL
+hymem_allocate_portLibrary (UDATA byteAmount)
+{
+  HANDLE memHeap = GetProcessHeap ();
+  return HeapAlloc (memHeap, 0, byteAmount);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymem_deallocate_portLibrary
+/**
+ * @internal Free memory for a portLibrary.
+ *
+ * @param[in] memoryPointer Base address to be deallocated.
+ *
+ * @note Must be implemented for all platforms.
+ */
+void VMCALL
+hymem_deallocate_portLibrary (void *memoryPointer)
+{
+  HANDLE memHeap = GetProcessHeap ();
+  HeapFree (memHeap, 0, memoryPointer);
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hymmap.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hymmap.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hymmap.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hymmap.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,159 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+#define CDEV_CURRENT_FUNCTION _comment_
+/**
+ * @file
+ * @ingroup Port
+ * @brief Memory map
+ *
+ * This module provides memory mapping facilities that allow a user to map files
+ * into the virtual address space of the process.  There are various options that
+ * can be used when mapping a file into memory, such as copy on write.  Not all 
+ * of these options are available on all platforms, @ref hymmap_capabilities 
+ * provides the list of supported options.  Note also that on some platforms 
+ * memory mapping facilites do not exist at all. On these platforms the API will
+ * still be available, but will simply read the file into allocated memory.
+ */
+#undef CDEV_CURRENT_FUNCTION
+
+#include <windows.h>
+
+#include "hyport.h"
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+/* no prototypes */
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymmap_map_file
+/**
+ * Map a file into memory.
+ *
+ * @param[in] portLibrary The port library
+ * @param[in] path - the path of the file to mapped into memory.
+ * @param[out] handle - updates *handle with the memory map handle, this handle is
+ *             later passed to unmap.
+ *
+ * @return pointer to newly mapped memory on success, NULL on error.
+ */
+void *VMCALL
+hymmap_map_file (struct HyPortLibrary *portLibrary, const char *path,
+		 void **handle)
+{
+  HANDLE file;
+  HANDLE mapping;
+  void *pointer;
+
+  file =
+    CreateFile (path, (GENERIC_READ | GENERIC_WRITE),
+		(FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_ALWAYS,
+		FILE_ATTRIBUTE_NORMAL, NULL);
+  if (file == INVALID_HANDLE_VALUE)
+    {
+      return NULL;
+    }
+  mapping = CreateFileMapping (file, NULL, PAGE_WRITECOPY, 0, 0, NULL);
+  if (mapping == NULL)
+    {
+      CloseHandle (file);
+      return NULL;
+    }
+  pointer = MapViewOfFile (mapping, FILE_MAP_COPY, 0, 0, 0);
+  CloseHandle (mapping);
+  CloseHandle (file);
+
+  *handle = pointer;
+  return pointer;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymmap_unmap_file
+/**
+ * UnMap previously mapped memory.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @param[in] handle - the handle from the mmap_map_file.
+ */
+void VMCALL
+hymmap_unmap_file (struct HyPortLibrary *portLibrary, void *handle)
+{
+  UnmapViewOfFile (handle);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymmap_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that
+ * were created by @ref hymmap_startup should be destroyed here.
+ *
+ */
+void VMCALL
+hymmap_shutdown (struct HyPortLibrary *portLibrary)
+{
+  /* empty */
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymmap_startup
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the memory mapping operations may be created here.  All resources created here should be destroyed
+ * in @ref hymmap_shutdown.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are
+ * \arg HYPORT_ERROR_STARTUP_MMAP
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hymmap_startup (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hymmap_capabilities
+/**
+ * Check the capabilities available for HYMMAP at runtime for the current platform.
+ *
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return a bit map containing the capabilites supported by the hymmap sub component
+ *         of the port library.
+ * Possible bit values:
+ *   HYPORT_MMAP_CAPABILITY_COPYONWRITE - if not present, platform is not capable of "copy on write" memory mapping.
+ *
+ */
+I_32 VMCALL
+hymmap_capabilities (struct HyPortLibrary * portLibrary)
+{
+  return HYPORT_MMAP_CAPABILITY_COPYONWRITE;
+}
+
+#undef CDEV_CURRENT_FUNCTION



Mime
View raw message