1// LAF Base Library
2// Copyright (c) 2001-2016 David Capello
3//
4// This file is released under the terms of the MIT license.
5// Read LICENSE.txt for more information.
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include <string>
12
13namespace base {
14
15// Like 'strerror' but thread-safe.
16std::string get_errno_string(int errnum)
17{
18 static const char *errors[] = {
19 "No error", /* errno = 0 */
20 "Operation not permitted", /* errno = 1 (EPERM) */
21 "No such file or directory", /* errno = 2 (ENOFILE) */
22 "No such process", /* errno = 3 (ESRCH) */
23 "Interrupted function call", /* errno = 4 (EINTR) */
24 "Input/output error", /* errno = 5 (EIO) */
25 "No such device or address", /* errno = 6 (ENXIO) */
26 "Arg list too long", /* errno = 7 (E2BIG) */
27 "Exec format error", /* errno = 8 (ENOEXEC) */
28 "Bad file descriptor", /* errno = 9 (EBADF) */
29 "No child processes", /* errno = 10 (ECHILD) */
30 "Resource temporarily unavailable", /* errno = 11 (EAGAIN) */
31 "Not enough space", /* errno = 12 (ENOMEM) */
32 "Permission denied", /* errno = 13 (EACCES) */
33 "Bad address", /* errno = 14 (EFAULT) */
34 NULL,
35 "Resource device", /* errno = 16 (EBUSY) */
36 "File exists", /* errno = 17 (EEXIST) */
37 "Improper link", /* errno = 18 (EXDEV) */
38 "No such device", /* errno = 19 (ENODEV) */
39 "Not a directory", /* errno = 20 (ENOTDIR) */
40 "Is a directory", /* errno = 21 (EISDIR) */
41 "Invalid argument", /* errno = 22 (EINVAL) */
42 "Too many open files in system", /* errno = 23 (ENFILE) */
43 "Too many open files", /* errno = 24 (EMFILE) */
44 "Inappropriate I/O control operation", /* errno = 25 (ENOTTY) */
45 NULL,
46 "File too large", /* errno = 27 (EFBIG) */
47 "No space left on device", /* errno = 28 (ENOSPC) */
48 "Invalid seek", /* errno = 29 (ESPIPE) */
49 "Read-only file system", /* errno = 30 (EROFS) */
50 "Too many links", /* errno = 31 (EMLINK) */
51 "Broken pipe", /* errno = 32 (EPIPE) */
52 "Domain error", /* errno = 33 (EDOM) */
53 "Result too large", /* errno = 34 (ERANGE) */
54 NULL,
55 "Resource deadlock avoided", /* errno = 36 (EDEADLOCK) */
56 NULL,
57 "Filename too long", /* errno = 38 (ENAMETOOLONG) */
58 "No locks available", /* errno = 39 (ENOLCK) */
59 "Function not implemented", /* errno = 40 (ENOSYS) */
60 "Directory not empty", /* errno = 41 (ENOTEMPTY) */
61 "Illegal byte sequence", /* errno = 42 (EILSEQ) */
62 };
63
64 if (errnum >= 0
65 && errnum < (int)(sizeof(errors)/sizeof(char *))
66 && errors[errnum] != NULL) {
67 return errors[errnum];
68 }
69 else {
70 return "Unknown error";
71 }
72}
73
74} // namespace base
75