/*
 *  Copyright 2000-2005 The Apache Software Foundation
 *
 *  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.
 */

package org.apache.tomcat.jni;

/** OS
 *
 * @author Mladen Turk
 * @version $Revision$, $Date$
 */

public class OS {

    /* OS Enums */
    private static final int UNIX      = 1;
    private static final int NETWARE   = 2;
    private static final int WIN32     = 3;
    private static final int WIN64     = 4;
    private static final int LINUX     = 5;
    private static final int SOLARIS   = 6;
    private static final int BSD       = 7;

    public static final int LOG_EMERG  = 1;
    public static final int LOG_ERROR  = 2;
    public static final int LOG_NOTICE = 3;
    public static final int LOG_WARN   = 4;
    public static final int LOG_INFO   = 5;
    public static final int LOG_DEBUG  = 6;

    /**
     * Check for OS type.
     * @param type OS type to test.
     */
    private static native boolean is(int type);

    static {
        IS_UNIX    = is(UNIX);
        IS_NETWARE = is(NETWARE);
        IS_WIN32   = is(WIN32);
        IS_WIN64   = is(WIN64);
        IS_LINUX   = is(LINUX);
        IS_SOLARIS = is(SOLARIS);
        IS_BSD     = is(BSD);
    }

    public static boolean IS_UNIX    = false;
    public static boolean IS_NETWARE = false;
    public static boolean IS_WIN32   = false;
    public static boolean IS_WIN64   = false;
    public static boolean IS_LINUX   = false;
    public static boolean IS_SOLARIS = false;
    public static boolean IS_BSD     = false;

    /**
     * Get the name of the system default characer set.
     * @param pool the pool to allocate the name from, if needed
     */
    public static native String defaultEncoding(long pool);

    /**
     * Get the name of the current locale character set.
     * Defers to apr_os_default_encoding if the current locale's
     * data can't be retreved on this system.
     * @param pool the pool to allocate the name from, if needed
     */
    public static native String localeEncoding(long pool);

    /**
     * Generate random bytes.
     * @param buf Buffer to fill with random bytes
     * @param len Length of buffer in bytes
     */
    public static native int random(byte [] buf, int len);

    /**
     * Gather system info.
     * <PRE>
     * On exit the inf array will be filled with:
     * inf[0]  - Total usable main memory size
     * inf[1]  - Available memory size
     * inf[2]  - Total page file/swap space size
     * inf[3]  - Page file/swap space still available
     * inf[4]  - Amount of shared memory
     * inf[5]  - Memory used by buffers
     * inf[6]  - Memory Load
     *
     * inf[7]  - Idle Time in microseconds
     * inf[8]  - Kernel Time in microseconds
     * inf[9]  - User Time in microseconds
     *
     * inf[10] - Process creation time (apr_time_t)
     * inf[11] - Process Kernel Time in microseconds
     * inf[12] - Process User Time in microseconds
     *
     * inf[13] - Current working set size.
     * inf[14] - Peak working set size.
     * inf[15] - Number of page faults.
     * </PRE>
     * @param inf array that will be filled with system information.
     *            Array length must be at least 16.
     */
    public static native int info(long [] inf);

    /**
     * Expand environment variables.
     * @param str String to expand
     * @return Expanded string with replaced environment variables.
     */
    public static native String expand(String str);

    /**
     * Initialize system logging.
     * @param domain String that will be prepended to every message
     */
    public static native void sysloginit(String domain);

    /**
     * Log message.
     * @param level Log message severity. See LOG_XXX enums.
     * @param message Message to log
     */
    public static native void syslog(int level, String message);

}

@@ -1467,253 +1467,8 @@
 );%0A%0A
-    static %7B%0A        IS_UNIX    = is(UNIX);%0A        IS_NETWARE = is(NETWARE);%0A        IS_WIN32   = is(WIN32);%0A        IS_WIN64   = is(WIN64);%0A        IS_LINUX   = is(LINUX);%0A        IS_SOLARIS = is(SOLARIS);%0A        IS_BSD     = is(BSD);%0A    %7D%0A%0A
     
@@ -1473,32 +1473,38 @@
   public static 
+final 
 boolean IS_UNIX 
@@ -1504,29 +1504,32 @@
 S_UNIX    = 
-false
+is(UNIX)
 ;%0A    public
@@ -1528,32 +1528,38 @@
   public static 
+final 
 boolean IS_NETWA
@@ -1563,21 +1563,27 @@
 TWARE = 
-false
+is(NETWARE)
 ;%0A    pu
@@ -1586,32 +1586,38 @@
   public static 
+final 
 boolean IS_WIN32
@@ -1617,29 +1617,33 @@
 S_WIN32   = 
-false
+is(WIN32)
 ;%0A    public
@@ -1642,32 +1642,38 @@
   public static 
+final 
 boolean IS_WIN64
@@ -1673,29 +1673,33 @@
 S_WIN64   = 
-false
+is(WIN64)
 ;%0A    public
@@ -1698,32 +1698,38 @@
   public static 
+final 
 boolean IS_LINUX
@@ -1733,21 +1733,25 @@
 NUX   = 
-false
+is(LINUX)
 ;%0A    pu
@@ -1754,32 +1754,38 @@
   public static 
+final 
 boolean IS_SOLAR
@@ -1789,21 +1789,27 @@
 LARIS = 
-false
+is(SOLARIS)
 ;%0A    pu
@@ -1820,16 +1820,22 @@
  static 
+final 
 boolean 
@@ -1851,13 +1851,15 @@
   = 
-false
+is(BSD)
 ;%0A%0A 

Fix bug 38984. Patch provided by Peter Grimshaw.