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