Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #include <pj/string.h> |
| 20 | #include <pj/compat/errno.h> |
| 21 | #include <linux/config.h> |
| 22 | #include <linux/version.h> |
| 23 | #if defined(MODVERSIONS) |
| 24 | #include <linux/modversions.h> |
| 25 | #endif |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/errno.h> |
| 28 | |
| 29 | int kernel_errno; |
| 30 | |
| 31 | PJ_DEF(pj_status_t) pj_get_os_error(void) |
| 32 | { |
| 33 | return errno; |
| 34 | } |
| 35 | |
| 36 | PJ_DEF(void) pj_set_os_error(pj_status_t code) |
| 37 | { |
| 38 | errno = code; |
| 39 | } |
| 40 | |
| 41 | PJ_DEF(pj_status_t) pj_get_netos_error(void) |
| 42 | { |
| 43 | return errno; |
| 44 | } |
| 45 | |
| 46 | PJ_DEF(void) pj_set_netos_error(pj_status_t code) |
| 47 | { |
| 48 | errno = code; |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * platform_strerror() |
| 53 | * |
| 54 | * Platform specific error message. This file is called by pj_strerror() |
| 55 | * in errno.c |
| 56 | */ |
| 57 | int platform_strerror( pj_os_err_type os_errcode, |
| 58 | char *buf, pj_size_t bufsize) |
| 59 | { |
Benny Prijono | e85bc41 | 2006-07-29 20:29:24 +0000 | [diff] [blame] | 60 | char errmsg[PJ_ERR_MSG_SIZE]; |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 61 | int len; |
| 62 | |
| 63 | /* Handle EINVAL as special case so that it'll pass errno test. */ |
| 64 | if (os_errcode==EINVAL) |
| 65 | strcpy(errmsg, "Invalid value"); |
| 66 | else |
Benny Prijono | e85bc41 | 2006-07-29 20:29:24 +0000 | [diff] [blame] | 67 | snprintf(errmsg, sizeof(errmsg), "errno=%d", os_errcode); |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 68 | |
| 69 | len = strlen(errmsg); |
| 70 | |
| 71 | if (len >= bufsize) |
| 72 | len = bufsize-1; |
| 73 | |
| 74 | pj_memcpy(buf, errmsg, len); |
| 75 | buf[len] = '\0'; |
| 76 | |
| 77 | return len; |
| 78 | } |
| 79 | |
| 80 | |