Tristan Matthews | 0a329cc | 2013-07-17 13:20:14 -0400 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) |
| 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | #include <pj/errno.h> |
| 21 | #include <pj/string.h> |
| 22 | #include <errno.h> |
| 23 | |
| 24 | PJ_DEF(pj_status_t) pj_get_os_error(void) |
| 25 | { |
| 26 | return PJ_STATUS_FROM_OS(errno); |
| 27 | } |
| 28 | |
| 29 | PJ_DEF(void) pj_set_os_error(pj_status_t code) |
| 30 | { |
| 31 | errno = PJ_STATUS_TO_OS(code); |
| 32 | } |
| 33 | |
| 34 | PJ_DEF(pj_status_t) pj_get_netos_error(void) |
| 35 | { |
| 36 | return PJ_STATUS_FROM_OS(errno); |
| 37 | } |
| 38 | |
| 39 | PJ_DEF(void) pj_set_netos_error(pj_status_t code) |
| 40 | { |
| 41 | errno = PJ_STATUS_TO_OS(code); |
| 42 | } |
| 43 | |
| 44 | PJ_BEGIN_DECL |
| 45 | |
| 46 | PJ_DECL(int) platform_strerror(pj_os_err_type code, |
| 47 | char *buf, pj_size_t bufsize ); |
| 48 | PJ_END_DECL |
| 49 | |
| 50 | /* |
| 51 | * platform_strerror() |
| 52 | * |
| 53 | * Platform specific error message. This file is called by pj_strerror() |
| 54 | * in errno.c |
| 55 | */ |
| 56 | int platform_strerror( pj_os_err_type os_errcode, |
| 57 | char *buf, pj_size_t bufsize) |
| 58 | { |
| 59 | const char *syserr = strerror(os_errcode); |
| 60 | pj_size_t len = syserr ? strlen(syserr) : 0; |
| 61 | |
| 62 | if (len >= bufsize) len = bufsize - 1; |
| 63 | if (len > 0) |
| 64 | pj_memcpy(buf, syserr, len); |
| 65 | buf[len] = '\0'; |
| 66 | return len; |
| 67 | } |
| 68 | |
| 69 | |