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/assert.h> |
| 22 | #include <pj/compat/stdarg.h> |
| 23 | #include <pj/unicode.h> |
| 24 | #include <pj/string.h> |
| 25 | |
| 26 | #include <e32err.h> |
| 27 | #include <in_sock.h> |
| 28 | |
| 29 | |
| 30 | #if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING!=0) |
| 31 | static const struct { |
| 32 | pj_os_err_type code; |
| 33 | const char *msg; |
| 34 | } gaErrorList[] = { |
| 35 | /* |
| 36 | * Generic error -1 to -46 |
| 37 | */ |
| 38 | PJ_BUILD_ERR( KErrNotFound, "Unable to find the specified object"), |
| 39 | PJ_BUILD_ERR( KErrGeneral, "General (unspecified) error"), |
| 40 | PJ_BUILD_ERR( KErrCancel, "The operation was cancelled"), |
| 41 | PJ_BUILD_ERR( KErrNoMemory, "Not enough memory"), |
| 42 | PJ_BUILD_ERR( KErrNotSupported, "The operation requested is not supported"), |
| 43 | PJ_BUILD_ERR( KErrArgument, "Bad request"), |
| 44 | PJ_BUILD_ERR( KErrTotalLossOfPrecision, "Total loss of precision"), |
| 45 | PJ_BUILD_ERR( KErrBadHandle, "Bad object"), |
| 46 | PJ_BUILD_ERR( KErrOverflow, "Overflow"), |
| 47 | PJ_BUILD_ERR( KErrUnderflow, "Underflow"), |
| 48 | PJ_BUILD_ERR( KErrAlreadyExists,"Already exists"), |
| 49 | PJ_BUILD_ERR( KErrPathNotFound, "Unable to find the specified folder"), |
| 50 | PJ_BUILD_ERR( KErrDied, "Closed"), |
| 51 | PJ_BUILD_ERR( KErrInUse, "The specified object is currently in use by another program"), |
| 52 | PJ_BUILD_ERR( KErrServerTerminated, "Server has closed"), |
| 53 | PJ_BUILD_ERR( KErrServerBusy, "Server busy"), |
| 54 | PJ_BUILD_ERR( KErrCompletion, "Completion error"), |
| 55 | PJ_BUILD_ERR( KErrNotReady, "Not ready"), |
| 56 | PJ_BUILD_ERR( KErrUnknown, "Unknown error"), |
| 57 | PJ_BUILD_ERR( KErrCorrupt, "Corrupt"), |
| 58 | PJ_BUILD_ERR( KErrAccessDenied, "Access denied"), |
| 59 | PJ_BUILD_ERR( KErrLocked, "Locked"), |
| 60 | PJ_BUILD_ERR( KErrWrite, "Failed to write"), |
| 61 | PJ_BUILD_ERR( KErrDisMounted, "Wrong disk present"), |
| 62 | PJ_BUILD_ERR( KErrEof, "Unexpected end of file"), |
| 63 | PJ_BUILD_ERR( KErrDiskFull, "Disk full"), |
| 64 | PJ_BUILD_ERR( KErrBadDriver, "Bad device driver"), |
| 65 | PJ_BUILD_ERR( KErrBadName, "Bad name"), |
| 66 | PJ_BUILD_ERR( KErrCommsLineFail,"Comms line failed"), |
| 67 | PJ_BUILD_ERR( KErrCommsFrame, "Comms frame error"), |
| 68 | PJ_BUILD_ERR( KErrCommsOverrun, "Comms overrun error"), |
| 69 | PJ_BUILD_ERR( KErrCommsParity, "Comms parity error"), |
| 70 | PJ_BUILD_ERR( KErrTimedOut, "Timed out"), |
| 71 | PJ_BUILD_ERR( KErrCouldNotConnect, "Failed to connect"), |
| 72 | PJ_BUILD_ERR( KErrCouldNotDisconnect, "Failed to disconnect"), |
| 73 | PJ_BUILD_ERR( KErrDisconnected, "Disconnected"), |
| 74 | PJ_BUILD_ERR( KErrBadLibraryEntryPoint, "Bad library entry point"), |
| 75 | PJ_BUILD_ERR( KErrBadDescriptor,"Bad descriptor"), |
| 76 | PJ_BUILD_ERR( KErrAbort, "Interrupted"), |
| 77 | PJ_BUILD_ERR( KErrTooBig, "Too big"), |
| 78 | PJ_BUILD_ERR( KErrDivideByZero, "Divide by zero"), |
| 79 | PJ_BUILD_ERR( KErrBadPower, "Batteries too low"), |
| 80 | PJ_BUILD_ERR( KErrDirFull, "Folder full"), |
| 81 | PJ_BUILD_ERR( KErrHardwareNotAvailable, ""), |
| 82 | PJ_BUILD_ERR( KErrSessionClosed, ""), |
| 83 | PJ_BUILD_ERR( KErrPermissionDenied, ""), |
| 84 | |
| 85 | /* |
| 86 | * Socket errors (-190 - -1000) |
| 87 | */ |
| 88 | PJ_BUILD_ERR( KErrNetUnreach, "Could not connect to the network. Currently unreachable"), |
| 89 | PJ_BUILD_ERR( KErrHostUnreach, "Could not connect to the specified server"), |
| 90 | PJ_BUILD_ERR( KErrNoProtocolOpt,"The specified server refuses the selected protocol"), |
| 91 | PJ_BUILD_ERR( KErrUrgentData, ""), |
| 92 | PJ_BUILD_ERR( KErrWouldBlock, "Conflicts with KErrExtended, but cannot occur in practice"), |
| 93 | |
| 94 | {0, NULL} |
| 95 | }; |
| 96 | |
| 97 | #endif /* PJ_HAS_ERROR_STRING */ |
| 98 | |
| 99 | |
| 100 | PJ_DEF(pj_status_t) pj_get_os_error(void) |
| 101 | { |
| 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | PJ_DEF(void) pj_set_os_error(pj_status_t code) |
| 106 | { |
| 107 | PJ_UNUSED_ARG(code); |
| 108 | } |
| 109 | |
| 110 | PJ_DEF(pj_status_t) pj_get_netos_error(void) |
| 111 | { |
| 112 | return -1; |
| 113 | } |
| 114 | |
| 115 | PJ_DEF(void) pj_set_netos_error(pj_status_t code) |
| 116 | { |
| 117 | PJ_UNUSED_ARG(code); |
| 118 | } |
| 119 | |
| 120 | PJ_BEGIN_DECL |
| 121 | |
| 122 | PJ_DECL(int) platform_strerror( pj_os_err_type os_errcode, |
| 123 | char *buf, pj_size_t bufsize); |
| 124 | PJ_END_DECL |
| 125 | |
| 126 | /* |
| 127 | * platform_strerror() |
| 128 | * |
| 129 | * Platform specific error message. This file is called by pj_strerror() |
| 130 | * in errno.c |
| 131 | */ |
| 132 | PJ_DEF(int) platform_strerror( pj_os_err_type os_errcode, |
| 133 | char *buf, pj_size_t bufsize) |
| 134 | { |
| 135 | int len = 0; |
| 136 | |
| 137 | pj_assert(buf != NULL); |
| 138 | pj_assert(bufsize >= 0); |
| 139 | |
| 140 | /* |
| 141 | * MUST NOT check stack here. |
| 142 | * This function might be called from PJ_CHECK_STACK() itself! |
| 143 | //PJ_CHECK_STACK(); |
| 144 | */ |
| 145 | |
| 146 | if (!len) { |
| 147 | #if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING!=0) |
| 148 | int i; |
| 149 | for (i = 0; gaErrorList[i].msg; ++i) { |
| 150 | if (gaErrorList[i].code == os_errcode) { |
| 151 | len = strlen(gaErrorList[i].msg); |
| 152 | if ((pj_size_t)len >= bufsize) { |
| 153 | len = bufsize-1; |
| 154 | } |
| 155 | pj_memcpy(buf, gaErrorList[i].msg, len); |
| 156 | buf[len] = '\0'; |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | #endif /* PJ_HAS_ERROR_STRING */ |
| 161 | |
| 162 | } |
| 163 | |
| 164 | if (!len) { |
| 165 | len = pj_ansi_snprintf( buf, bufsize, "Symbian native error %d", |
| 166 | os_errcode); |
| 167 | buf[len] = '\0'; |
| 168 | } |
| 169 | |
| 170 | return len; |
| 171 | } |
| 172 | |