Author: mturk Date: Mon Apr 11 17:09:09 2011 New Revision: 1091130 URL: http://svn.apache.org/viewvc?rev=1091130&view=rev Log: Add generic BSD os implementation
Added: commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c (with props) Added: commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c?rev=1091130&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c Mon Apr 11 17:09:09 2011 @@ -0,0 +1,91 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "acr/jniapi.h" +#include "acr/string.h" +#include <sys/utsname.h> +#include <sys/param.h> +#include <sys/sysctl.h> + +static int _sys_done = -1; +static struct utsname _sys_buf; +static int _sys_ncpu = 0; +static const char _unknown[] = "unknown"; + +ACR_JNI_EXPORT(jint, Os, getType)(JNI_STDARGS) +{ + UNREFERENCED_STDARGS; + return ACR_OS_BSDX; +} + +ACR_JNI_EXPORT(jint, Os, getNumCpu)(JNI_STDARGS) +{ + UNREFERENCED_STDARGS; + if (_sys_ncpu == 0) { + int mib[2]; + size_t len = sizeof(_sys_ncpu); + + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + if (sysctl(mib, 2, &_sys_ncpu, &len, 0, 0) < 0) + _sys_ncpu = 1; + } + return _sys_ncpu; +} + +ACR_JNI_EXPORT(jint, Os, init)(JNI_STDARGS) +{ + UNREFERENCED_STDARGS; + if (_sys_done == 0) + return 0; + _sys_done = uname(&_sys_buf); + if (_sys_done) + return errno; + else + return 0; +} + +ACR_JNI_EXPORT(jstring, Os, getSysname)(JNI_STDARGS) +{ + if (_sys_done == 0) + return CSTR_TO_JSTRING(_sys_buf.sysname); + else + return CSTR_TO_JSTRING("unknownBSD"); +} + +ACR_JNI_EXPORT(jstring, Os, getNodename)(JNI_STDARGS) +{ + if (_sys_done == 0) + return CSTR_TO_JSTRING(_sys_buf.nodename); + else + return CSTR_TO_JSTRING(_unknown); +} + +ACR_JNI_EXPORT(jstring, Os, getRelease)(JNI_STDARGS) +{ + if (_sys_done == 0) + return CSTR_TO_JSTRING(_sys_buf.release); + else + return CSTR_TO_JSTRING(_unknown); +} + +ACR_JNI_EXPORT(jstring, Os, getVersion)(JNI_STDARGS) +{ + if (_sys_done == 0) + return CSTR_TO_JSTRING(_sys_buf.version); + else + return CSTR_TO_JSTRING(_unknown); +} Propchange: commons/sandbox/runtime/trunk/src/main/native/os/bsdx/os.c ------------------------------------------------------------------------------ svn:eol-style = native