]> git.sesse.net Git - vlc/blob - src/network/error.c
Fix type-punning breakage
[vlc] / src / network / error.c
1 /*****************************************************************************
2  * error.c: Network error handling
3  *****************************************************************************
4  * Copyright (C) 2006 Rémi Denis-Courmont
5  * $Id$
6  *
7  * Author : Rémi Denis-Courmont <rem # videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <errno.h>
29 #include "network.h"
30
31 #if defined (WIN32) || defined (UNDER_CE)
32 const char *net_strerror( int value )
33 {
34     /* There doesn't seem to be any portable error message generation for
35      * Winsock errors. Some old versions had s_error, but it appears to be
36      * gone, and is not documented.
37      */
38
39     switch( value )
40     {
41         /* Feel free to add any error message as you see fit */
42         case WSAENETUNREACH:
43             return "Destination unreachable";
44
45         case WSAETIMEDOUT:
46             return "Connection timed out";
47
48         case WSAECONNREFUSED:
49             return "Connection refused";
50
51         default:
52         {
53             static char errmsg[14 + 5 + 1];
54             /* Given PE don't support thread-local storage, this cannot be
55              * implemented in a thread-safe manner, I'm afraid. */
56
57             if( ((unsigned)value) > 99999 ) /* avoid overflow */
58                 return "Invalid error code";
59
60             sprintf( errmsg, "Winsock error %u", (unsigned)value );
61             return errmsg;
62         }
63     }
64
65     return strerror( value );
66 }
67 #endif