Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
error.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2 -*- */
2 /* Copyright(C) 2013 Brazil
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License version 2.1 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public
14  License along with this library; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "error.h"
19 
20 #ifdef HAVE_ERRNO_H
21 #include <errno.h>
22 #endif /* HAVE_ERRNO_H */
23 
24 #include <string.h>
25 
26 #ifdef WIN32
27 const char *
29 {
30 # define ERROR_MESSAGE_BUFFER_SIZE 4096
31  int error_code = WSAGetLastError();
32  static char message[ERROR_MESSAGE_BUFFER_SIZE];
33 
34  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
35  FORMAT_MESSAGE_IGNORE_INSERTS,
36  NULL,
37  error_code,
38  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
39  message,
40  ERROR_MESSAGE_BUFFER_SIZE,
41  NULL);
42 
43  return message;
44 
45 # undef ERROR_MESSAGE_BUFFER_SIZE
46 }
47 #else
48 const char *
50 {
51  return strerror(errno);
52 }
53 #endif