diff options
Diffstat (limited to 'pjlib/src')
-rw-r--r-- | pjlib/src/pj/os_info.c | 73 | ||||
-rw-r--r-- | pjlib/src/pj/os_info_iphone.m | 47 |
2 files changed, 104 insertions, 16 deletions
diff --git a/pjlib/src/pj/os_info.c b/pjlib/src/pj/os_info.c index a10a95ce..9f810a56 100644 --- a/pjlib/src/pj/os_info.c +++ b/pjlib/src/pj/os_info.c @@ -47,11 +47,19 @@ # include <windows.h> #endif +#if defined(PJ_DARWINOS) && PJ_DARWINOS != 0 +# include "TargetConditionals.h" +#endif #ifndef PJ_SYS_INFO_BUFFER_SIZE # define PJ_SYS_INFO_BUFFER_SIZE 64 #endif + +#if defined(PJ_DARWINOS) && PJ_DARWINOS != 0 && TARGET_OS_IPHONE + void pj_iphone_os_get_sys_info(pj_sys_info *si, pj_str_t *si_buffer); +#endif + static char *ver_info(pj_uint32_t ver, char *buf) { int len; @@ -78,6 +86,31 @@ static char *ver_info(pj_uint32_t ver, char *buf) return buf; } +static pj_uint32_t parse_version(char *str) +{ + char *tok; + int i, maxtok; + pj_uint32_t version = 0; + + while (*str && !pj_isdigit(*str)) + str++; + + maxtok = 4; + for (tok = strtok(str, ".-"), i=0; tok && i<maxtok; + ++i, tok=strtok(NULL, ".-")) + { + int n; + + if (!pj_isdigit(*tok)) + break; + + n = atoi(tok); + version |= (n << ((3-i)*8)); + } + + return version; +} + PJ_DEF(const pj_sys_info*) pj_get_sys_info(void) { static char si_buffer[PJ_SYS_INFO_BUFFER_SIZE]; @@ -105,10 +138,29 @@ PJ_DEF(const pj_sys_info*) pj_get_sys_info(void) * Machine and OS info. */ #if defined(PJ_HAS_UNAME) && PJ_HAS_UNAME + #if defined(PJ_DARWINOS) && PJ_DARWINOS != 0 && TARGET_OS_IPHONE + { + pj_str_t buf = {si_buffer + PJ_SYS_INFO_BUFFER_SIZE - left, left}; + pj_str_t machine = {"arm", 3}; + pj_str_t sdk_name = {"iOS-SDK", 7}; + char tmp[PJ_SYS_INFO_BUFFER_SIZE]; + + pj_iphone_os_get_sys_info(&si, &buf); + left -= si.os_name.slen + 1; + + si.os_ver = parse_version(si.machine.ptr); + + si.machine = machine; + si.sdk_name = sdk_name; + +#ifdef PJ_SDK_NAME + pj_memcpy(tmp, PJ_SDK_NAME, pj_ansi_strlen(PJ_SDK_NAME) + 1); + si.sdk_ver = parse_version(tmp); +#endif + } + #else { struct utsname u; - char *tok; - int i, maxtok; /* Successful uname() returns zero on Linux and positive value * on OpenSolaris. @@ -118,21 +170,10 @@ PJ_DEF(const pj_sys_info*) pj_get_sys_info(void) ALLOC_CP_STR(u.machine, machine); ALLOC_CP_STR(u.sysname, os_name); - - maxtok = 4; - for (tok = strtok(u.release, ".-"), i=0; - tok && i<maxtok; - ++i, tok=strtok(NULL, ".-")) - { - int n; - - if (!pj_isdigit(*tok)) - break; - - n = atoi(tok); - si.os_ver |= (n << ((3-i)*8)); - } + + si.os_ver = parse_version(u.release); } + #endif #elif defined(_MSC_VER) { OSVERSIONINFO ovi; diff --git a/pjlib/src/pj/os_info_iphone.m b/pjlib/src/pj/os_info_iphone.m new file mode 100644 index 00000000..39d9b89b --- /dev/null +++ b/pjlib/src/pj/os_info_iphone.m @@ -0,0 +1,47 @@ +/* $Id$ */ +/* + * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com) + * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <pj/os.h> +#include <pj/string.h> + +#include <UIKit/UIDevice.h> + +void pj_iphone_os_get_sys_info(pj_sys_info *si, pj_str_t *si_buffer) +{ + unsigned buf_len = si_buffer->slen, left = si_buffer->slen, len; + UIDevice *device = [UIDevice currentDevice]; + + if ([device respondsToSelector:@selector(isMultitaskingSupported)]) + si->flags |= PJ_SYS_HAS_IOS_BG; + +#define ALLOC_CP_STR(str,field) \ + do { \ + len = [str length]; \ + if (len && left >= len+1) { \ + si->field.ptr = si_buffer->ptr + buf_len - left; \ + si->field.slen = len; \ + [str getCString:si->field.ptr maxLength:len+1 \ + encoding:NSASCIIStringEncoding]; \ + left -= (len+1); \ + } \ + } while (0) + + ALLOC_CP_STR([device systemName], os_name); + ALLOC_CP_STR([device systemVersion], machine); +} |