Added get_errno_string

This commit is contained in:
David Capello 2008-02-10 18:58:17 +00:00
parent db9be355c2
commit 9c516cb354
2 changed files with 71 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007, 2008 David A. Capello
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -21,6 +21,7 @@
#ifndef USE_PRECOMPILED_HEADER
#include <allegro/file.h>
#include <allegro/unicode.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
@ -83,7 +84,7 @@ void core_exit(void)
}
if (log_filename) {
free(log_filename);
jfree(log_filename);
log_filename = NULL;
}
#endif
@ -123,3 +124,68 @@ bool is_interactive(void)
{
return ase_mode & MODE_GUI ? TRUE: FALSE;
}
/**
* Like 'strerror' but thread-safe.
*
* @return The same @a buf pointer.
*/
char *get_errno_string(int errnum, char *buf, int size)
{
static const char *errors[] = {
"No error", /* errno = 0 */
"Operation not permitted", /* errno = 1 (EPERM) */
"No such file or directory", /* errno = 2 (ENOFILE) */
"No such process", /* errno = 3 (ESRCH) */
"Interrupted function call", /* errno = 4 (EINTR) */
"Input/output error", /* errno = 5 (EIO) */
"No such device or address", /* errno = 6 (ENXIO) */
"Arg list too long", /* errno = 7 (E2BIG) */
"Exec format error", /* errno = 8 (ENOEXEC) */
"Bad file descriptor", /* errno = 9 (EBADF) */
"No child processes", /* errno = 10 (ECHILD) */
"Resource temporarily unavailable", /* errno = 11 (EAGAIN) */
"Not enough space", /* errno = 12 (ENOMEM) */
"Permission denied", /* errno = 13 (EACCES) */
"Bad address", /* errno = 14 (EFAULT) */
NULL,
"Resource device", /* errno = 16 (EBUSY) */
"File exists", /* errno = 17 (EEXIST) */
"Improper link", /* errno = 18 (EXDEV) */
"No such device", /* errno = 19 (ENODEV) */
"Not a directory", /* errno = 20 (ENOTDIR) */
"Is a directory", /* errno = 21 (EISDIR) */
"Invalid argument", /* errno = 22 (EINVAL) */
"Too many open files in system", /* errno = 23 (ENFILE) */
"Too many open files", /* errno = 24 (EMFILE) */
"Inappropriate I/O control operation", /* errno = 25 (ENOTTY) */
NULL,
"File too large", /* errno = 27 (EFBIG) */
"No space left on device", /* errno = 28 (ENOSPC) */
"Invalid seek", /* errno = 29 (ESPIPE) */
"Read-only file system", /* errno = 30 (EROFS) */
"Too many links", /* errno = 31 (EMLINK) */
"Broken pipe", /* errno = 32 (EPIPE) */
"Domain error", /* errno = 33 (EDOM) */
"Result too large", /* errno = 34 (ERANGE) */
NULL,
"Resource deadlock avoided", /* errno = 36 (EDEADLOCK) */
NULL,
"Filename too long", /* errno = 38 (ENAMETOOLONG) */
"No locks available", /* errno = 39 (ENOLCK) */
"Function not implemented", /* errno = 40 (ENOSYS) */
"Directory not empty", /* errno = 41 (ENOTEMPTY) */
"Illegal byte sequence", /* errno = 42 (EILSEQ) */
};
if (errnum >= 0
&& errnum < sizeof(errors)/sizeof(char *)
&& errors[errnum] != NULL) {
ustrncpy(buf, errors[errnum], size);
}
else {
ustrncpy(buf, "Unknown error", size);
}
return buf;
}

View File

@ -1,5 +1,5 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2005, 2007, 2008 David A. Capello
* Copyright (C) 2001-2008 David A. Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -36,4 +36,6 @@ void core_exit(void);
void verbose_printf(const char *format, ...);
bool is_interactive(void);
char *get_errno_string(int errnum, char *buf, int size);
#endif /* CORE_H */