blob: 52a63dceaac6c2ff574aad573da9c21538b0b689 [file] [log] [blame]
Benny Prijono9033e312005-11-21 02:08:39 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono9033e312005-11-21 02:08:39 +00005 *
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
24PJ_DEF(pj_status_t) pj_get_os_error(void)
25{
26 return PJ_STATUS_FROM_OS(errno);
27}
28
29PJ_DEF(void) pj_set_os_error(pj_status_t code)
30{
31 errno = PJ_STATUS_TO_OS(code);
32}
33
34PJ_DEF(pj_status_t) pj_get_netos_error(void)
35{
36 return PJ_STATUS_FROM_OS(errno);
37}
38
39PJ_DEF(void) pj_set_netos_error(pj_status_t code)
40{
41 errno = PJ_STATUS_TO_OS(code);
42}
43
Benny Prijonoa1e69682007-05-11 15:14:34 +000044PJ_BEGIN_DECL
45
46 PJ_DECL(int) platform_strerror(pj_os_err_type code,
47 char *buf, pj_size_t bufsize );
48PJ_END_DECL
49
Benny Prijono9033e312005-11-21 02:08:39 +000050/*
51 * platform_strerror()
52 *
53 * Platform specific error message. This file is called by pj_strerror()
54 * in errno.c
55 */
56int 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