1 /*
2 * Copyright (C) 2013-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
3 * Copyright (C) 2009-2013 Sourcefire, Inc.
4 *
5 * Authors: aCaB <acab@clamav.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
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., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include <string.h>
23 #include "w32_errno.h"
24
w32_strerror(int errnum)25 char *w32_strerror(int errnum)
26 {
27 size_t i;
28 for (i = 0; i < sizeof(w32_errnos) / sizeof(w32_errnos[0]); i++) {
29 if (w32_errnos[i].err == errnum)
30 return w32_errnos[i].strerr;
31 }
32 return "Unknown error";
33 }
34
w32_strerror_r(int errnum,char * buf,size_t buflen)35 int w32_strerror_r(int errnum, char *buf, size_t buflen)
36 {
37 strncpy(buf, w32_strerror(errnum), buflen);
38 if (buflen) buf[buflen - 1] = '\0';
39 return 0;
40 }
41