1
/* $Id: errno.c 4537 2013-06-19 06:47:43Z riza $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
24
#include <pj/compat/socket.h>
25
#include <pj/string.h>
27
#if INCLUDE_ERRNO_TEST
29
#define THIS_FILE "errno"
31
#if (defined(PJ_WIN32) && PJ_WIN32 != 0) || \
32
(defined(PJ_WIN64) && PJ_WIN64 != 0)
36
#if defined(PJ_HAS_ERRNO_H) && PJ_HAS_ERRNO_H != 0
40
static void trim_newlines(char *s)
43
if (*s == '\r' || *s == '\n')
49
int my_strncasecmp(const char *s1, const char *s2, int max_len)
51
while (*s1 && *s2 && max_len > 0) {
52
if (pj_tolower(*s1) != pj_tolower(*s2))
61
const char *my_stristr(const char *whole, const char *part)
63
int part_len = (int)strlen(part);
65
if (my_strncasecmp(whole, part, part_len) == 0)
78
PJ_LOG(3,(THIS_FILE, "...errno test: check the msg carefully"));
83
* Windows platform error.
85
# ifdef ERROR_INVALID_DATA
86
rc = PJ_STATUS_FROM_OS(ERROR_INVALID_DATA);
90
pj_strerror(rc, errbuf, sizeof(errbuf));
91
trim_newlines(errbuf);
92
PJ_LOG(3,(THIS_FILE, "...msg for rc=ERROR_INVALID_DATA: '%s'", errbuf));
93
if (my_stristr(errbuf, "invalid") == NULL) {
95
"...error: expecting \"invalid\" string in the msg"));
96
#ifndef PJ_WIN32_WINCE
102
pj_strerror(rc, errbuf, CUT);
103
PJ_LOG(3,(THIS_FILE, "...msg for rc=ERROR_INVALID_DATA (cut): '%s'", errbuf));
109
# if defined(EINVAL) && !defined(PJ_SYMBIAN)
110
rc = PJ_STATUS_FROM_OS(EINVAL);
114
pj_strerror(rc, errbuf, sizeof(errbuf));
115
trim_newlines(errbuf);
116
PJ_LOG(3,(THIS_FILE, "...msg for rc=EINVAL: '%s'", errbuf));
117
if (my_stristr(errbuf, "invalid") == NULL) {
118
PJ_LOG(3, (THIS_FILE,
119
"...error: expecting \"invalid\" string in the msg"));
124
pj_strerror(rc, errbuf, CUT);
125
PJ_LOG(3,(THIS_FILE, "...msg for rc=EINVAL (cut): '%s'", errbuf));
132
rc = PJ_STATUS_FROM_OS(WSAEINVAL);
136
pj_strerror(rc, errbuf, sizeof(errbuf));
137
trim_newlines(errbuf);
138
PJ_LOG(3,(THIS_FILE, "...msg for rc=WSAEINVAL: '%s'", errbuf));
139
if (my_stristr(errbuf, "invalid") == NULL) {
140
PJ_LOG(3, (THIS_FILE,
141
"...error: expecting \"invalid\" string in the msg"));
146
pj_strerror(rc, errbuf, CUT);
147
PJ_LOG(3,(THIS_FILE, "...msg for rc=WSAEINVAL (cut): '%s'", errbuf));
150
pj_strerror(PJ_EBUG, errbuf, sizeof(errbuf));
151
PJ_LOG(3,(THIS_FILE, "...msg for rc=PJ_EBUG: '%s'", errbuf));
152
if (my_stristr(errbuf, "BUG") == NULL) {
153
PJ_LOG(3, (THIS_FILE,
154
"...error: expecting \"BUG\" string in the msg"));
158
pj_strerror(PJ_EBUG, errbuf, CUT);
159
PJ_LOG(3,(THIS_FILE, "...msg for rc=PJ_EBUG, cut at %d chars: '%s'",
163
pj_perror(3, THIS_FILE, PJ_SUCCESS, "...testing %s", "pj_perror");
164
PJ_PERROR(3,(THIS_FILE, PJ_SUCCESS, "...testing %s", "PJ_PERROR"));
170
#endif /* INCLUDE_ERRNO_TEST */