You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by dl...@apache.org on 2005/10/19 10:01:19 UTC

svn commit: r326443 - in /incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src: portable.h portable_jmp_buf.c portable_libc.c portable_libm.c

Author: dlydick
Date: Wed Oct 19 01:00:59 2005
New Revision: 326443

URL: http://svn.apache.org/viewcvs?rev=326443&view=rev
Log:
New files containing portable version of all section 2 system calls
such as stat(2) and section 3 library calls such as strlen(3).
Invoked from body of the code using application typedefs, then cast
to required interface types (such as 'int' or 'double', never used
in body of code), and invoke the related 'libc' or 'libm' function,
passing back the return value as an application typedef.

Due to their peculiar definition and operation, setjmp(3) and
longjmp(3) are given special treatment as macros, with a portable
definition of the 'jmp_buf' structure, including its own source file.

Added:
    incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable.h
    incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_jmp_buf.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libc.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libm.c

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable.h?rev=326443&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable.h Wed Oct 19 01:00:59 2005
@@ -0,0 +1,349 @@
+#ifndef _portable_h_defined_
+#define _portable_h_defined_
+
+/*!
+ * @file portable.h
+ *
+ * @brief External definitions for portable version of
+ * @b system(2) calls and @b library(3) utility functions for
+ * @link jvm/src/portable_libc.c portable_libc.c@endlink,
+ * @link jvm/src/portable_libm.c portable_libm.c@endlink, and
+ * @link jvm/src/portable_jmp_buf.c portable_jmp_buf.c@endlink.
+ *
+ * @attention  See note in @link jvm/src/portable_jmp_buf.c
+               portable_jmp_buf.c@endlink about use and redefinition
+ *             of @c @b setjmp(3)/longjmp(3) and why there is no
+ *             function remapping done here.
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/portable.h $
+ *
+ * \$Id: portable.h 0 09/28/2005 dlydick $
+ *
+ * Copyright 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.
+ *
+ * @version \$LastChangedRevision: 0 $
+ *
+ * @date \$LastChangedDate: 09/28/2005 $
+ *
+ * @author \$LastChangedBy: dlydick $
+ *
+ *         Original code contributed by Daniel Lydick on 09/28/2005.
+ *
+ * @section Reference
+ *
+ */
+
+#include "arch.h"
+ARCH_HEADER_COPYRIGHT_APACHE(portable, h,
+"$URL: https://svn.apache.org/path/name/portable.h $",
+"$Id: portable.h 0 09/28/2005 dlydick $");
+
+/*!
+ * @name Remap portable calls to generate error
+ *
+ * By disallowing the old calls, any time a normal invocation is
+ * made, the compiler will inform of the need to use the portability
+ * library version.  This will help compensate for oversights.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+#ifndef I_AM_PORTABLE_C
+
+/* remappings for portable_libc.c */
+#define mkdir PLEASE_USE_portable_mkdir /**< @c @b mkdir(2) has been
+                                           remapped into the
+                                           portability library. */
+
+#define rmdir PLEASE_USE_portable_rmdir /**< @c @b rmdir(2) has been
+                                           remapped into the
+                                           portability library. */
+
+#define stat PLEASE_USE_portable_stat   /**< @c @b stat(2) has been
+                                           remapped into the
+                                           portability library. */
+
+#define open PLEASE_USE_portable_open   /**< @c @b open(2) has been
+                                           remapped into the
+                                           portability library. */
+
+#define read PLEASE_USE_portable_read   /**< @c @b read(2) has been
+                                           remapped into the
+                                           portability library. */
+
+#define close PLEASE_USE_portable_close /**< @c @b close(2) has been
+                                           remapped into the
+                                           portability library. */
+
+#define fopen PLEASE_USE_portable_fopen /**< @c @b fopen(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define fgets PLEASE_USE_portable_fgets /**< @c @b fgets(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define fclose PLEASE_USE_portable_fclose /**< @c @b fclose(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define getwd  PLEASE_USE_portable_getwd /**< @c @b getwd(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define getenv PLEASE_USE_portable_getenv /**< @c @b getenv(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define getpid PLEASE_USE_portable_getpid /**< @c @b getpid(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define sleep PLEASE_USE_portable_sleep /**< @c @b sleep(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define system PLEASE_USE_portable_system /**< @c @b system(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define strchr PLEASE_USE_portable_strchr /**< @c @b strchr(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define strrchr PLEASE_USE_portable_strrchr /**< @c @b strrchr(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define strcmp PLEASE_USE_portable_strcmp /**< @c @b strcmp(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define strncmp PLEASE_USE_portable_strncmp /**< @c @b strncmp(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define strlen PLEASE_USE_portable_strlen /**< @c @b strlen(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define strcat PLEASE_USE_portable_strcat /**< @c @b strcat(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define strcpy PLEASE_USE_portable_strcpy /**< @c @b strcpy(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define memcpy PLEASE_USE_portable_memcpy /**< @c @b memcpy(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define atol PLEASE_USE_portable_atol   /**< @c @b atol(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define isspace PLEASE_USE_portable_isspace /**< @c @b isspace(3) has
+                                           been remapped into the
+                                           portability library. */
+
+#define malloc PLEASE_USE_portable_malloc /**< @c @b malloc(3) has been
+                                           remapped into the
+                                           portability library. */
+
+#define free PLEASE_USE_portable_free   /**< @c @b free(3) has been
+                                           remapped into the
+                                           portability library. */
+
+/* remappings for portable_libm.c */
+#define fmod PLEASE_USE_portable_jPRECISION_fmod
+                                        /**< @c @b fmod(3) has been
+                                           remapped into the
+                                           portability library.  It
+                                           has a version for both
+                                           single- and double-precision
+                                           values */
+#endif /* I_AM_PORTABLE_C */
+
+/*@} */ /* End of grouped definitions */
+
+
+/* remappings for portable_libc.c */
+ 
+/* Level 1 file access */
+extern rint   portable_mkdir(const rchar *path, rint oflag);
+extern rint   portable_rmdir(const rchar *path);
+extern rvoid *portable_stat(const rchar *path
+                            /* struct stat *  impl w/in */);
+extern rlong  portable_stat_get_st_size(rvoid *statbfr);
+extern rint   portable_open(const rchar *path,
+                            rint oflag /* , ... not impl/not needed */);
+extern rlong  portable_read(rint fildes, rvoid *buf, rlong nbyte);
+extern rint   portable_close(rint fildes);
+
+/* Level 2 file access */
+extern rvoid *portable_fopen(const rchar *filename, const rchar *mode);
+extern rchar *portable_fgets(rchar *s, rint n, rvoid *stream);
+extern rint   portable_fclose(rvoid *stream);
+
+/* Shell and process control */
+extern rchar *portable_getwd(rchar *path_name);
+extern rchar *portable_getenv(const rchar *name);
+extern rlong  portable_getpid(rvoid);
+extern rint   portable_system(const rchar *string);
+extern ruint  portable_sleep(ruint seconds);
+
+/* String manipulation */
+extern rchar *portable_strchr(const rchar *s, rint c);
+extern rchar *portable_strrchr(const rchar *s, rint c);
+extern rint   portable_strcmp(const rchar *s1, const rchar *s2);
+extern rint   portable_strncmp(const rchar *s1,const rchar *s2,rlong n);
+extern rlong  portable_strlen(const rchar *s);
+extern rchar *portable_strcat(rchar *s1, const rchar *s2);
+extern rchar *portable_strcpy(rchar *s1, const rchar *s2);
+
+/* Memory manipulation */
+extern rvoid *portable_memcpy(rvoid *s1, const rvoid *s2, rlong n);
+
+/* C type library */
+extern rlong  portable_atol(const rchar *str);
+extern rint   portable_isspace(rint c);
+
+/* Memory allocation */
+extern rvoid *portable_malloc(rlong size);
+extern rvoid  portable_free(rvoid *ptr);
+
+
+#ifdef PORTABLE_JMP_BUF_VISIBLE
+
+/* Include this file only in the source files that need it: */
+#include <setjmp.h>
+
+/*!
+ * @brief Portable edition of @c @b jmp_buf structure.
+ *
+ * @attention Early on in the project, two @c @b jmp_buf structures were
+ *            part of a source file along with other global and
+ *            @c @b static variables.  Sometimes the @c @b longjmp(3)
+ *            would return the correct return code, but sometimes, for
+ *            reasons unknown then, it would return zero as if
+ *            @c @b setjmp(3) had been called instead!  It is
+ *            speculated that there was a structure packing issue
+ *            at hand, where one of the last members was the
+ *            @c @b longjmp(3) return code that got stomped on
+ *            because the source file declaring the @c @b jmp_buf
+ *            had a shorter idea of the structure size than did the
+ *            library function such that the return code got set to
+ *            zero by the declaring file using structure packing
+ *            when it thought it was updating an adjacent variable.
+ *            When the library routine @c @b longjmp(3) ran, using
+ *            an unpacked structure, it read what should have been
+ *            the return code and returned zero instead of what had
+ *            originally been there.  Or something along those lines.
+ *            The solution?  Use the same structure packing everywhere,
+ *            which cannot be guaranteed.  The workaround?  Declare
+ *            some padding following the @c @b jmp_buf to protect the
+ *            end of the structure from corruption.  How much storage?
+ *            Who knows?  Therefore, simply guess and add a duplicate
+ *            @c @b jmp_buf adjacent to the first, which @e should
+ *            supply more than enough padding to do the job.
+ *
+ * @internal This structure is @e horrible.  It is @e ugly.
+ *           But it @e guarantees that absolutely no structure
+ *           packing or lack thereof will compromise the integrity
+ *           of an initialized @c @b jmp_buf.  There really is
+ *           no other way to do it except add a third member here
+ *           for more padding (which is probably not necessary),
+ *           or to perform heap allocation, as is done in
+ *           @link jvm/src/thread.c thread.c@endlink.  However,
+ *           due to the non-local return nature of the structure
+ *           any way, and since there are other non-local handlers
+ *           active at the same time for other conditions, it is
+ *           better to be ugly and correct than simple and pretty,
+ *           yet vulnerable to failures.
+ */
+typedef struct
+{
+    jmp_buf real_member1; /**< Main part of definition */
+    jmp_buf pad_member2;  /**< Add a subsequent one to force padding */
+ /* jmp_buf pad_member3;  If more padding is needed, add another one */
+
+} portable_jmp_buf;
+
+extern portable_jmp_buf portable_exit_general_failure;
+extern portable_jmp_buf portable_exit_LinkageError;
+
+extern rint portable_sizeof_portable_jmp_buf();
+
+/*!
+ * @brief Portable macro version of @c @b setjmp(3)
+ *
+ * @c @b setjmp(3) cannot be called from a subroutine from the
+ * protected context, but it @e can be embedded in a macro.
+ * This expression of portability makes use of
+ * @link #portable_jmp_buf portable_jmp_buf@endlink, but otherwise
+ * looks just like a @c @b setjmp(3) call.
+ *
+ *
+ * @param penv   Pointer to portable edition of @c @b jmp_buf structure.
+ *
+ *
+ * @returns 0 from setup, else return coded passed to @c @b longjmp(3)
+ *          for this buffer.
+ *
+ */
+#define PORTABLE_SETJMP(penv) setjmp((penv)->real_member1)
+
+
+/*!
+ * @brief Portable macro version of @c @b longjmp(3)
+ *
+ * @c @b longjmp(3) @e can be called from a subroutine from the
+ * protected context, in fact typically often is, even though
+ * @c @b setjmp(3) @e cannot be called from such a subroutine.
+ * This expression of portability makes use of
+ * @link #portable_jmp_buf portable_jmp_buf@endlink, but otherwise
+ * looks just like a @c @b longjmp(3) call.
+ *
+ *
+ * @param penv   Pointer to portable edition of @c @b jmp_buf structure.
+ *
+ * @param val    Return code to pass back to protected context.
+ *
+ *
+ * @returns @c @b val parameter, via @c @b setjmp(3), into protected
+ *          context.  There is no local return.
+ *
+ */
+#define PORTABLE_LONGJMP(penv, val) longjmp((penv)->real_member1, \
+                                            (int) (val))
+
+#endif /* PORTABLE_JMP_BUF_VISIBLE */
+
+
+/* remappings for portable_libm.c */
+extern jfloat portable_jfloat_fmod(jfloat x, jfloat y);
+extern jfloat portable_jdouble_fmod(jdouble x, jdouble y);
+
+#endif /* _portable_h_defined_ */
+
+
+/* EOF */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_jmp_buf.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_jmp_buf.c?rev=326443&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_jmp_buf.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_jmp_buf.c Wed Oct 19 01:00:59 2005
@@ -0,0 +1,159 @@
+/*!
+ * @file portable_jmp_buf.c
+ *
+ * @brief Portable version of @b jmp_buf structures.
+ *
+ * Isolate all @c @b jmp_buf declarations from the normal compilation
+ * environment so as to eliminate all questions about @b libc
+ * compilation modes, especially use of structure packing.  For GCC,
+ * this means how the compile option <b>-fpack-struct</b> was or was
+ * not used.
+ *
+ *
+ * @attention A word about @c @b setjmp(3)/longjmp(3) and portability:
+ *            The non-intuitive mechanism used by these functions to
+ *            implement non-local returns is complemented on some
+ *            systems by an equally non-intuitive definition of these
+ *            functions and of the @c @b jmp_buf structure.  Since
+ *            members of @c @b jmp_buf variables are @e never
+ *            referenced at the API level, but @e only internally to
+ *            these functions, and since some systems can generate
+ *            really strange compile errors when attempting either,
+ *            no attempt will be made to enforce the portability
+ *            reminder mechanism on the lot.
+ *
+ * @attention A word about placement of @c @b setjmp(3):  Due to the
+ *            non-local nature of @c @b longjmp(3), there can @e never
+ *            be such as thing as a @c @b portable_setjmp() function
+ *            that invokes @c @b setjmp(3) in a manner similar
+ *            to more normal library calls such as those found in
+ *            @link jvm/src/portable_libc.c portable_libc.c@endlink.
+ *            The reason for this is non-intuitive, yet simple:
+ *            Invocations of @c @b setjmp(3) use the stack state
+ *            at the time of the @c @b setjmp(3) itself.  When that
+ *            function returns from the initial setup, it passes
+ *            back its return value, which in turn would hypothetically
+ *            be passed back to the caller of the portable routine.
+ *            This part works, fine, but when @c @b longjmp(3) tries
+ *            to return to that stack state, it @e also will try to
+ *            pass back @e its return code, which will @e also be to
+ *            the portable routine.  The stack state will be @e exactly
+ *            as the @c @b setjmp(3) call defined it, namely, to
+ *            return into the portable routine, but
+ *            <b>not to the @e caller of the portable routine!</b>
+ *            So the portable routine returns from this condition,
+ *            it will be popping potentially random garbage off of
+ *            the stack from other stack usage following the
+ *            @c @b setjmp(3).  Thus it is highly unlikely to pass
+ *            the proper return code back through @c @b setjmp(3)
+ *            into the invoking runtime environment.  It might even
+ *            return to a wild pointer address.
+ *
+ *            The bottom line:  Although @c @b longjmp(3) is designed
+ *            like any other function in how it may be invoked, its
+ *            companion @c @b setjmp(3) must @e never be invoked from
+ *            a subroutine.  It must be invoked @e directly by the
+ *            runtime stack frame that is to be re-entered in the
+ *            non-local location set up in the @c @b jmp_buf.
+ *
+ * For other comments on portability issues, please refer to
+ * @link jvm/src/portable_libc.c portable_libc.c@endlink and
+ * @link jvm/src/portable_libm.c portable_libm.c@endlink.
+ *
+ *
+ *
+ * @see @link jvm/src/portable_libc.c portable_libc.c@endlink
+ *
+ * @see @link jvm/src/portable_libm.c portable_libm.c@endlink
+ *
+ * @see @link jvm/src/portable.h portable.h@endlink
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/portable_jmp_buf.c $
+ *
+ * \$Id: portable_jmp_buf.c 0 09/28/2005 dlydick $
+ *
+ * Copyright 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.
+ *
+ * @version \$LastChangedRevision: 0 $
+ *
+ * @date \$LastChangedDate: 09/28/2005 $
+ *
+ * @author \$LastChangedBy: dlydick $
+ *
+ *         Original code contributed by Daniel Lydick on 09/28/2005.
+ *
+ * @section Reference
+ *
+ */
+
+#include "arch.h"
+ARCH_SOURCE_COPYRIGHT_APACHE(portable_jmp_buf, c,
+"$URL: https://svn.apache.org/path/name/portable_jmp_buf.c $",
+"$Id: portable_jmp_buf.c 0 09/28/2005 dlydick $");
+
+#define PORTABLE_JMP_BUF_VISIBLE
+#include "jvmcfg.h"
+
+
+/*!
+ * @name static jmp_buf declarations gathered from around the code.
+ *
+ * All @c @b jmp_buf variables, typically defined previously as
+ * @c @b static in their source files (thus file scope) are gathered
+ * here into the portability library.
+ *
+ * References to these variables is typically through
+ * @link #PORTABLE_SETJMP() PORTABLE_SETJMP()@endlink and
+ * @link #PORTABLE_LONGJMP() PORTABLE_LONGJMP()@endlink.
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+portable_jmp_buf portable_exit_general_failure;
+
+portable_jmp_buf portable_exit_LinkageError;
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @brief Report the correct size of @c @b sizeof(jmp_buf) for use
+ * by memory allocations of buffers not statically defined here in
+ * this source file.
+ *
+ *
+ * @b Parameters: @link #rvoid rvoid@endlink
+ *
+ *
+ * @returns number of bytes required by @c @b jmp_buf structures
+ *
+ */
+rint portable_sizeof_portable_jmp_buf()
+{
+    ARCH_FUNCTION_NAME(portable_sizeof_portable_jmp_buf);
+
+    return(sizeof(portable_jmp_buf));
+
+} /* END of portable_sizeof_portable_jmp_buf() */
+
+
+/* EOF */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libc.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libc.c?rev=326443&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libc.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libc.c Wed Oct 19 01:00:59 2005
@@ -0,0 +1,912 @@
+/*!
+ * @file portable_libc.c
+ *
+ * @brief Portable version of @b system(2) calls and @b library(3)
+ * utility functions.
+ *
+ * Isolate all section 2 system calls and section 3 library functions
+ * from the normal compilation environment so as to eliminate all
+ * questions about @b libc compilation modes, especially use of
+ * structure packing.  For GCC, this means how the compile option
+ * <b>-fpack-struct</b> was or was not used.
+ *
+ * Operands are passed in using the type definitions as applicable to
+ * the application code.  They are then cast into the types required
+ * for library calls.  For example, a @link #jfloat jfloat@endlink
+ * will be cast into a @c @b float .  This is so that the system calls
+ * and library functions will see the @e exact type that they require
+ * in their definition.  All casting is done explicitly.
+ *
+ * In order to reduce visibility of data structures that might have
+ * packing issues, all structure references have been abstracted
+ * to passing (@link #rvoid rvoid@endlink *) pointers in and out.
+ * This is applicable @e only to functions that do not already
+ * pass back a pointer.
+ *
+ * These abstracted pointers will point to blocks allocated with
+ * @link #HEAP_GET_DATA() HEAP_GET_DATA@endlink and must be
+ * freed with @link #HEAP_FREE_DATA() HEAP_FREE_DATA()@endlink
+ * when they are no longer needed.  For this reason, this portability
+ * library is @e not an exact, drop-in replacement for the library
+ * functions that it impliments.
+ *
+ * As example of this abstraction, @c @b stat(2) is passed a structure
+ * pointer for an area to fill.  In order to avoid packing errors, the
+ * portable version @link #portable_stat() portable_stat()@endlink
+ * implements this abstraction.  On the other hand, @c @b fopen(3)
+ * passes back a pointer in its current definition and does not need
+ * the abstraction beyond changing the pointer type to
+ * (@link #rvoid rvoid@endlink *).  Simply pass the pointer to
+ * all related function.
+ *
+ *
+ * @todo HARMONY-6-jvm-portable_libc.c-1 In order to present a
+ *       systematic and regular implementation across all external
+ *       library references, the standard I/O entry points
+ *       @c @b portable_fprintf() and so forth should
+ *       probably be written to point over to the existing
+ *       standard I/O function replacements in
+ *       @link jvm/src/stdio.c stdio.c@endlink.
+ *
+ * @see @link jvm/src/portable_libm.c portable_libm.c@endlink
+ *
+ * @see @link jvm/src/portable_jmp_buf.c portable_jmp_buf.c@endlink
+ *
+ * @see @link jvm/src/portable.h portable.h@endlink
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/portable_libc.c $
+ *
+ * \$Id: portable_libc.c 0 09/28/2005 dlydick $
+ *
+ * Copyright 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.
+ *
+ * @version \$LastChangedRevision: 0 $
+ *
+ * @date \$LastChangedDate: 09/28/2005 $
+ *
+ * @author \$LastChangedBy: dlydick $
+ *
+ *         Original code contributed by Daniel Lydick on 09/28/2005.
+ *
+ * @section Reference
+ *
+ */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "arch.h"
+ARCH_SOURCE_COPYRIGHT_APACHE(portable_libc, c,
+"$URL: https://svn.apache.org/path/name/portable_libc.c $",
+"$Id: portable_libc.c 0 09/28/2005 dlydick $");
+
+ 
+#define I_AM_PORTABLE_C /* Suppress function name remapping */
+#include "jvmcfg.h"
+#include "exit.h"
+#include "heap.h"
+
+/*!
+ * @name Level 1 file access
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Portable replacement for @c @b mkdir(2) system call
+ *
+ *
+ * @param path   Path name of directory to create, relative or absolute.
+ *
+ * @param mode   Flag for mkdir creation mode.
+ *
+ *
+ * @returns 0 if successful or -1 with @c @b errno set
+ *          to report the error that occurred.
+ *
+ */
+rint portable_mkdir(const rchar *path, rint mode)
+{
+    ARCH_FUNCTION_NAME(portable_mkdir);
+
+    char *pathlocal = (char *) path;
+    int   modelocal = (int) mode;
+
+    int rc = mkdir(pathlocal, modelocal);
+
+    return((rint) rc);
+
+} /* END of portable_mkdir() */
+
+
+/*!
+ * @brief Portable replacement for @c @b rmdir(2) system call
+ *
+ *
+ * @param path   Path name of directory to remove, relative or absolute.
+ *
+ *
+ * @returns 0 if successful or -1 with @c @b errno set
+ *          to report the error that occurred.
+ *
+ */
+rint portable_rmdir(const rchar *path)
+{
+    ARCH_FUNCTION_NAME(portable_rmdir);
+
+    char *pathlocal = (char *) path;
+
+    int rc = rmdir(pathlocal);
+
+    return((rint) rc);
+
+} /* END of portable_rmdir() */
+
+
+/*!
+ * @brief Portable replacement for @c @b stat(2) system call
+ *
+ * @attention This function @b requires freeing of a result pointer
+ *            with @link #HEAP_FREE_DATA() HEAP_FREE_DATA()@endlink
+ *            when it is no longer needed.
+ *
+ *
+ * Notice that this function returns an (@link #rvoid rvoid@endlink *)
+ * with its result.
+ *
+ * @param path   Path name of file, relative or absolute.
+ *
+ *
+ * @returns (@link #rvoid rvoid@endlink *) to status buffer
+ *          if successful or @link #rnull rnull@endlink with
+ *          @c @b errno set to report the error that occurred.
+ *
+ */
+rvoid *portable_stat(const rchar *path)
+{
+    ARCH_FUNCTION_NAME(portable_stat);
+
+    char        *pathlocal = (char *) path;
+
+    struct stat *buflocal  = HEAP_GET_DATA(sizeof(struct stat), rfalse);
+
+    int rc = stat(pathlocal, buflocal);
+
+    if (0 == rc)
+    {
+        return((rvoid *) buflocal);
+    }
+    else
+    { 
+        HEAP_FREE_DATA(buflocal);
+        return((rvoid *) rnull);
+    }
+
+} /* END of portable_stat() */
+
+
+/*!
+ * @brief Portable replacement for reading
+ * <b><code>(struct stat).st_size</code></b>
+ *
+ *
+ * @param statbfr   Pointer to structure previously reported
+ *                  by @link #portable_stat() portable_stat()@endlink
+ *
+ *
+ * @returns @c @b st_size value from @c @b stat structure.
+ *
+ */
+rlong portable_stat_get_st_size(rvoid *statbfr)
+{
+    ARCH_FUNCTION_NAME(portable_stat_get_st_size);
+
+    struct stat *statbfrlocal = (struct stat *) statbfr;
+
+    long rc = (long) statbfrlocal->st_size;
+
+    return((rlong) rc);
+
+} /* END of portable_stat_get_st_size() */
+
+
+/*!
+ * @brief Portable replacement for @c @b open(2) system call
+ *
+ * The optional third parameter is not supported only because it
+ * is not needed.  It may be added if desired.
+ *
+ *
+ * @param path   Path name of file, relative or absolute.
+ *
+ * @param oflag  Flag for file open modes.
+ *
+ *
+ * @returns File handle of opened file or -1 with @c @b errno set
+ *          to report the error that occurred.
+ *
+ */
+rint portable_open(const rchar *path, rint oflag)
+{
+    ARCH_FUNCTION_NAME(portable_open);
+
+    char *pathlocal = (char *) path;
+    int   oflaglocal = (int) oflag;
+
+    int rc = open(pathlocal, oflaglocal);
+
+    return((rint) rc);
+
+} /* END of portable_open() */
+
+
+/*!
+ * @brief Portable replacement for @c @b read(2) system call
+ *
+ *
+ * @param[in] fildes  Integer file handle of open file.
+ *
+ * @param[out] buf    Location to store data read in.
+ *
+ * @param[in] nbyte   Number of bytes to read.
+ *
+ *
+ * @returns Number of bytes read or -1 with @c @b errno set
+ *          to report the error that occurred.
+ *
+ */
+rlong portable_read(rint fildes, rvoid *buf, rlong nbyte)
+{
+    ARCH_FUNCTION_NAME(portable_read);
+
+    int   fildeslocal = (int) fildes;
+    char *buflocal    = (char *) buf;
+    long  nbytelocal  = (long) nbyte;
+
+    long rc = read(fildeslocal, buflocal, nbytelocal);
+
+    return((rlong) rc);
+
+} /* END of portable_read() */
+
+
+/*!
+ * @brief Portable replacement for @c @b close(2) system call
+ *
+ *
+ * @param fildes      Integer file handle of open file.
+ *
+ *
+ * @returns 0 if successful or -1 with @c @b errno set
+ *          to report the error that occurred.
+ *
+ */
+rint portable_close(rint fildes)
+{
+    ARCH_FUNCTION_NAME(portable_close);
+
+    int   fildeslocal = (int) fildes;
+
+    int rc = close(fildeslocal);
+
+    return((rint) rc);
+
+} /* END of portable_close() */
+
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @name Level 2 file access
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Portable replacement for @c @b fopen(3) library function
+ *
+ *
+ * @param filename   Path name of file, relative or absolute.
+ *
+ * @param mode       String for file open modes.
+ *
+ *
+ * @returns (@link #rvoid rvoid@endlink *) to standard I/O stream
+ *          structure if successful or @link #rnull rnull@endlink with
+ *          @c @b errno set to report the error that occurred.
+ *
+ */
+rvoid *portable_fopen(const rchar *filename, const rchar *mode)
+{
+    ARCH_FUNCTION_NAME(portable_fopen);
+
+    char *filenamelocal = (char *) filename;
+    char *modelocal     = (char *) mode;
+
+    FILE *rc = fopen(filenamelocal, modelocal);
+
+    return((rvoid *) rc);
+
+} /* END of portable_fopen() */
+
+
+/*!
+ * @brief Portable replacement for @c @b fgets(3) library function
+ *
+ *
+ * @param[out] s      Output buffer to receive data read in.
+ *
+ * @param[in]  n      Number of bytes to read.
+ *
+ * @param[in]  stream FILE stream pointer returned by
+ *                    @link #portable_fopen() portable_fopen()@endlink
+ *
+ *
+ * @returns @b s if successful or @link #rnull rnull@endlink
+ *          if EOF or error.  If error, @c @b errno is also set
+ *          to report the error that occurred.
+ *
+ */
+rchar *portable_fgets(rchar *s, rint n, rvoid *stream)
+{
+    ARCH_FUNCTION_NAME(portable_fgets);
+
+    char *slocal      = (char *) s;
+    int   nlocal      = (int) n;
+    FILE *streamlocal = (FILE *) stream;
+
+    char *rc = (char *) fgets(slocal, nlocal, streamlocal);
+
+    return((rchar *) rc);
+
+} /* END of portable_fgets() */
+
+
+/*!
+ * @brief Portable replacement for @c @b fclose(3) library function
+ *
+ *
+ * @param stream  FILE stream pointer returned by
+ *                @link #portable_fopen() portable_fopen()@endlink
+ *
+ *
+ * @returns @b s if successful or -1 with @c @b errno set
+ *          to report the error that occurred.
+ *
+ */
+rint portable_fclose(rvoid *stream)
+{
+    ARCH_FUNCTION_NAME(portable_fclose);
+
+    FILE *streamlocal = (FILE *) stream;
+
+    int rc = (int) fclose(streamlocal);
+
+    return((rint) rc);
+
+} /* END of portable_fclose() */
+
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @name Shell and process control
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+
+/*!
+ * @brief Portable replacement for @c @b getwd(3) library function
+ *
+ *
+ * @param[out] path_name  Buffer to hold name of current working
+ *                        directory.
+ *
+ *
+ * @returns @c @b path_name if successful or @link #rnull rnull@endlink
+ *          if an error occurred.  @c @b errno is not set.
+ *
+ */
+rchar *portable_getwd(rchar *path_name)
+{
+    ARCH_FUNCTION_NAME(portable_getwd);
+
+    char *path_name_local = (char *) path_name;
+
+    char *rc = getwd(path_name_local);
+
+    return((rchar *) rc);
+
+} /* END of portable_getwd() */
+
+
+/*!
+ * @brief Portable replacement for @c @b getenv(3) library function
+ *
+ *
+ * @param name   Null-terminated string containing the name of an
+ *               environment variable to read.
+ *
+ *
+ * @returns @c @b name if successful or @link #rnull rnull@endlink
+ *          if an error occurred.  @c @b errno is not set.
+ *
+ */
+rchar *portable_getenv(const rchar *name)
+{
+    ARCH_FUNCTION_NAME(portable_getenv);
+
+    char *namelocal = (char *) name;
+
+    char *rc = getenv(namelocal);
+
+    return((rchar *) rc);
+
+} /* END of portable_getenv() */
+
+
+/*!
+ * @brief Portable replacement for @c @b getpid(2) system call
+ *
+ *
+ * @b Parameters: @link #rvoid rvoid@endlink
+ *
+ *
+ * @returns Process ID number of current process or
+ *          <b><code>((ruint) -1)</code></b> with @c @b errno set
+ *          to report the error that occurred.
+ *
+ * @warning The return type of @c @b getpid(2) is typically
+ *          platform-specific, even if only marginally so.
+ *          Verify the proper size when porting.
+ *
+ */
+rlong  portable_getpid(rvoid)
+{
+    ARCH_FUNCTION_NAME(portable_getpis);
+
+    pid_t rc = getpid();
+
+    return((rlong) rc);
+
+} /* END of portable_getpid() */
+
+
+/*!
+ * @brief Portable replacement for @c @b system(3) library function
+ *
+ * @param string  Shell command string to execute.
+ *
+ *
+ * @returns File handle of opened file or -1 with @c @b errno set
+ *          to report the error that occurred.
+ *
+ */
+rint portable_system(const rchar *string)
+{
+    ARCH_FUNCTION_NAME(portable_system);
+
+    char *stringlocal = (char *) string;
+
+    int rc = system(stringlocal);
+
+    return((rint) rc);
+
+} /* END of portable_system() */
+
+
+/*!
+ * @brief Portable replacement for @c @b sleep(3) library function
+ *
+ *
+ * @param seconds  Number of seconds to sleep.
+ *
+ *
+ * @returns Number of seconds from @c @b seconds that did not
+ *          expire before return, typically due to a signal or
+ *          other event.
+ *
+ */
+ruint  portable_sleep(ruint seconds)
+{
+    ARCH_FUNCTION_NAME(portable_sleep);
+
+    unsigned int   secondslocal = (unsigned int) seconds;
+
+    unsigned int rc = sleep(secondslocal);
+
+    return((ruint) rc);
+
+} /* END of portable_sleep() */
+
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @name String manipulation
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Portable replacement for @c @b strchr(3) library function
+ *
+ *
+ * @param s  Null-terminated string to evaluate
+ *
+ * @param c  Character to locate in @c @b s buffer
+ *
+ *
+ * @returns the first occurrence in @c @b s of @c @b c or
+ *          @link #rnull rnull@endlink if not found.
+ *
+ */
+rchar *portable_strchr(const rchar *s, rint c)
+{
+    ARCH_FUNCTION_NAME(portable_strchr);
+
+    char *slocal = (char *) s;
+    int   clocal = (int)    c;
+
+    char *rc = strchr(slocal, clocal);
+
+    return((rchar *) rc);
+
+} /* END of portable_strchr() */
+
+
+/*!
+ * @brief Portable replacement for @c @b strrchr(3) library function
+ *
+ *
+ * @param s  Null-terminated string to evaluate
+ *
+ * @param c  Character to locate in @c @b s buffer
+ *
+ *
+ * @returns the last occurrence in @c @b s of @c @b c or
+ *          @link #rnull rnull@endlink if not found.
+ *
+ */
+rchar *portable_strrchr(const rchar *s, rint c)
+{
+    ARCH_FUNCTION_NAME(portable_strrchr);
+
+    char *slocal = (char *) s;
+    int   clocal = (int)    c;
+
+    char *rc = strrchr(slocal, clocal);
+
+    return((rchar *) rc);
+
+} /* END of portable_strrchr() */
+
+
+/*!
+ * @brief Portable replacement for @c @b strcmp(3) library function
+ *
+ *
+ * @param s1  First null-terminated string to evaluate
+ *
+ * @param s2  Second null-terminated string to evaluate
+ *
+ *
+ * @returns lexicographical difference between first pair of
+ *          differing bytes between the strings, or 0 if identical.
+ *
+ */
+rint portable_strcmp(const rchar *s1, const rchar *s2)
+{
+    ARCH_FUNCTION_NAME(portable_strcmp);
+
+    char   *s1local = (char *) s1;
+    char   *s2local = (char *) s2;
+
+    int rc = strcmp(s1local, s2local);
+
+    return((rint) rc);
+
+} /* END of portable_strcmp() */
+
+
+/*!
+ * @brief Portable replacement for @c @b strncmp(3) library function
+ *
+ *
+ * @param s1  First null-terminated string to evaluate
+ *
+ * @param s2  Second null-terminated string to evaluate
+ *
+ * @param n   Number of bytes in the two strings to compare
+ *
+ *
+ * @returns lexicographical difference between first pair of
+ *          differing bytes between the strings, or 0 if identical.
+ *
+ */
+rint portable_strncmp(const rchar *s1, const rchar *s2, rlong n)
+{
+    ARCH_FUNCTION_NAME(portable_strncmp);
+
+    char   *s1local = (char *) s1;
+    char   *s2local = (char *) s2;
+    size_t  nlocal  = (size_t) n;
+
+    int rc = strncmp(s1local, s2local, nlocal);
+
+    return((rint) rc);
+
+} /* END of portable_strncmp() */
+
+
+/*!
+ * @brief Portable replacement for @c @b strlen(3) library function
+ *
+ *
+ * @param s  Null-terminated string to evaluate
+ *
+ *
+ * @returns the number of characters found in @c @b s buffer
+ *
+ */
+rlong portable_strlen(const rchar *s)
+{
+    ARCH_FUNCTION_NAME(portable_strlen);
+
+    char *slocal = (char *) s;
+
+    size_t rc = strlen(slocal);
+
+    return((rlong) rc);
+
+} /* END of portable_strlen() */
+
+
+/*!
+ * @brief Portable replacement for @c @b strcat(3) library function
+ *
+ *
+ * @param[in,out] s1  Destination null-terminated string whence @c @b s2
+ *                    contents are appended
+ *
+ * @param[in] s2     Source null-terminated string to append to @c @b s1
+ *                    buffer
+ *
+ *
+ * @returns @c @b s1
+ *
+ */
+rchar *portable_strcat(rchar *s1, const rchar *s2)
+{
+    ARCH_FUNCTION_NAME(portable_strcat);
+
+    char   *s1local = (char *) s1;
+    char   *s2local = (char *) s2;
+
+    char *rc = strcat(s1local, s2local);
+
+    return((rchar *) rc);
+
+} /* END of portable_strcat() */
+
+
+/*!
+ * @brief Portable replacement for @c @b strcpy(3) library function
+ *
+ *
+ * @param[out] s1  Destination null-terminated string buffer
+ *                 into which @c @b s2 contents are copied
+ *
+ * @param[in] s2   Source null-terminated string to copy into @c @b s1
+ *                 buffer
+ *
+ *
+ * @returns @c @b s1
+ *
+ */
+rchar *portable_strcpy(rchar *s1, const rchar *s2)
+{
+    ARCH_FUNCTION_NAME(portable_strcpy);
+
+    char   *s1local = (char *) s1;
+    char   *s2local = (char *) s2;
+
+    char *rc = strcpy(s1local, s2local);
+
+    return((rchar *) rc);
+
+} /* END of portable_strcpy() */
+
+
+/*@} */ /* End of grouped definitions */
+
+/*!
+ * @name Memory manipulation
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Portable replacement for @c @b memcpy(3) library function
+ *
+ *
+ * @param[out] s1  Destination buffer to receive contents of @c @b s2
+ *                 buffer
+ *
+ * @param[in] s2   Source buffer to copy to @c @b s1 buffer
+ *
+ * @param[in] n   Number of bytes to copy from one buffer to the other
+ *
+ *
+ * @returns @c @b s1
+ *
+ */
+rvoid *portable_memcpy(rvoid *s1, const rvoid *s2, rlong n)
+{
+    ARCH_FUNCTION_NAME(portable_memcpy);
+
+    void   *s1local = (void *) s1;
+    void   *s2local = (void *) s2;
+    size_t  nlocal  = (size_t) n;
+
+    void *rc = memcpy(s1local, s2local, nlocal);
+
+    return((rvoid *) rc);
+
+} /* END of portable_memcpy() */
+
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @name C type library
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Portable replacement for @c @b atol(3) library function
+ *
+ *
+ * @param str  Null-terminated string to convert
+ *
+ *
+ * @returns integer equivalent of @c @b s2 or 0 if error and @c @b errno
+ *          will be set to indicate error.
+ *
+ */
+rlong portable_atol(const rchar *str)
+{
+    ARCH_FUNCTION_NAME(portable_atol);
+
+    char   *strlocal = (char *) str;
+
+    long rc = atol(strlocal);
+
+    return((rlong) rc);
+
+} /* END of portable_atol() */
+
+
+/*!
+ * @brief Portable replacement for @c @b isspace(3) library function
+ *
+ *
+ * @param c  Character to evaluate
+ *
+ *
+ * @returns non-zero if @c @b c is a white space character,
+ *          otherwise 0.  If @c @b c is not in the domain of
+ *          comparison, the result is undefined.
+ *
+ */
+rint portable_isspace(rint c)
+{
+    ARCH_FUNCTION_NAME(portable_isspace);
+
+    int clocal = (int) c;
+
+    int rc = isspace(clocal);
+
+    return((rint) rc);
+
+} /* END of portable_isspace() */
+
+
+/*@} */ /* End of grouped definitions */
+
+
+/*!
+ * @name Memory allocation
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Portable replacement for @c @b malloc(3) library function
+ *
+ *
+ * @param size  Number of bytes to allocate
+ *
+ *
+ * @returns pointer to allocated memory area if successful,
+ *          otherwise @link #rnull rnull@endlink.
+ *
+ */
+rvoid *portable_malloc(rlong size)
+{
+    ARCH_FUNCTION_NAME(portable_malloc);
+
+    size_t sizelocal = (size_t) size;
+
+    void *rc = malloc(sizelocal);
+
+    return((rvoid *) rc);
+
+} /* END of portable_malloc() */
+
+
+/*!
+ * @brief Portable replacement for @c @b free(3) library function
+ *
+ *
+ * @param ptr  Pointer to buffer to free
+ *
+ *
+ * @returns @link #rvoid rvoid@endlink
+ *
+ */
+rvoid portable_free(rvoid *ptr)
+{
+    ARCH_FUNCTION_NAME(portable_free);
+
+    void   *ptrlocal = (void *) ptr;
+
+    free(ptrlocal);
+
+    return;
+
+} /* END of portable_free() */
+
+
+/*@} */ /* End of grouped definitions */
+
+
+/* EOF */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libm.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libm.c?rev=326443&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libm.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/bootjvm/bootJVM/jvm/src/portable_libm.c Wed Oct 19 01:00:59 2005
@@ -0,0 +1,143 @@
+/*!
+ * @file portable_libm.c
+ *
+ * @brief Portable version of @b system(2) calls and @b library(3)
+ * utility functions.
+ *
+ * Isolate all section 3 math library functions from the normal
+ * compilation environment so as to eliminate all questions about
+ * @b libm compilation modes, especially use of structure packing.
+ * For GCC, this means how the compile option <b>-fpack-struct</b>
+ * was or was not used.
+ *
+ * For other comments, please refer to
+ * @link jvm/src/portable_libc.c portable_libc.c@endlink.
+ *
+ * @see @link jvm/src/portable_libc.c portable_libc.c@endlink
+ *
+ * @see @link jvm/src/portable_jmp_buf.c portable_jmp_buf.c@endlink
+ *
+ * @see @link jvm/src/portable.h portable.h@endlink
+ *
+ *
+ * @section Control
+ *
+ * \$URL: https://svn.apache.org/path/name/portable_libm.c $
+ *
+ * \$Id: portable_libm.c 0 09/28/2005 dlydick $
+ *
+ * Copyright 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.
+ *
+ * @version \$LastChangedRevision: 0 $
+ *
+ * @date \$LastChangedDate: 09/28/2005 $
+ *
+ * @author \$LastChangedBy: dlydick $
+ *
+ *         Original code contributed by Daniel Lydick on 09/28/2005.
+ *
+ * @section Reference
+ *
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "arch.h"
+ARCH_SOURCE_COPYRIGHT_APACHE(portable_libm, c,
+"$URL: https://svn.apache.org/path/name/portable_libm.c $",
+"$Id: portable_libm.c 0 09/28/2005 dlydick $");
+
+ 
+#define I_AM_PORTABLE_C /* Suppress function name remapping */
+#include "jvmcfg.h"
+
+
+/*!
+ * @name fmod() function for both jfloat and jdouble operands.
+ *
+ *
+ * @param x  First of two operands, the divisor
+ *
+ * @param y  Second of two operands, the dividend
+ *
+ *
+ * @returns The remainder of dividing @c @b x by @c @b y
+ *
+ */
+
+/*@{ */ /* Begin grouped definitions */
+
+/*!
+ * @brief Portable replacement for @c @b fmod(3) library function for
+ * @link #jfloat jfloat@endlink operands.
+ *
+ * Cast @link #jfloat jfloat@endlink operands as native
+ * machine @c @b float and invoke @c @b fmod(3) .  Cast the
+ * @c @b double result back into a @link #jfloat jfloat@endlink
+ * for return.
+ *
+ */
+jfloat portable_jfloat_fmod(jfloat x, jfloat y)
+{
+    ARCH_FUNCTION_NAME(portable_jfloat_fmod);
+
+    double xlocal = (double) x;
+    double ylocal = (double) y;
+
+    double rc = fmod(xlocal, ylocal);
+
+    return((jfloat) rc);
+
+} /* END of portable_jfloat_fmod() */
+
+
+/*!
+ * @brief Portable replacement for @c @b fmod(3) library function for
+ * @link #jdouble jdouble@endlink operands.
+ *
+ *
+ * Cast @link #jdouble jdouble@endlink operands as native
+ * machine @c @b double and invoke @c @b fmod(3) .  Cast the
+ * @c @b double result back into a @link #jdouble jdouble@endlink
+ * for return.
+ *
+ */
+jfloat portable_jdouble_fmod(jdouble x, jdouble y)
+{
+    ARCH_FUNCTION_NAME(portable_jdouble_fmod);
+
+    double xlocal = (double) x;
+    double ylocal = (double) y;
+
+    double rc = fmod(xlocal, ylocal);
+
+    return((jdouble) rc);
+
+} /* END of portable_jdouble_fmod() */
+
+/*@} */ /* End of grouped definitions */
+
+
+/* EOF */