BarryServer : Git

All the code for all my projects
// BarryServer : Git / OrionLibC / blob / 03048a95d88cc7a78171393371f5c22a0250a014 / stdio / perror.c

// Related

OrionLibC

Barry Importing existing Orion LibC 03048a9 (2 years, 2 months ago)
#include <stdio.h>
#include <errno.h>

int errno;
const char *errorList[] = {
	[ENONE]   = "No error",
	[EPERM]   = "Operation not permitted",
	[ENOENT]  = "No such file or directory",
	[ESRCH]   = "No such process",
	[EINVAL]  = "Invalid argument",
	[EBADF]   = "Bad file descriptor",
	[ENOEXEC] = "Exec format error",
	[EMFILE]  = "Too many open files",
	[EFAULT]  = "Bad address",
	[EISDIR]  = "Is a directory",
	[ENOTDIR] = "Not a directory",
	[EACCES]  = "Permission denied",
	[ENODEV]  = "No such device",
	[EEXIST]  = "File exists",
	[ENXIO]   = "No such device or address",
	[ENOTBLK] = "Block device required",
	[ENOMEM]  = "Cannot allocate memory",
	[ECHILD]  = "No child processes",
	[ENOTTY]  = "Inappropriate ioctl for device",
};

/* Display an error message for errno */
void
perror(const char *s)
{
	if (errno < 0 || errno >= (sizeof(errorList)/sizeof(errorList[0])))
		return;
	if (!s)
		printf("%s\n", errorList[errno]);
	else if (!s[0])
		printf("%s\n", errorList[errno]);
	else
		printf("%s: %s\n", s, errorList[errno]);
}