BarryServer : Git

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

// Related

OrionLibC

Barry Updating libc for pipes and signals ad9b6af (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",
	[ELOOP]   = "Too many levels of symbolic links",
	[ENAMETOOLONG] = "File name too long",
	[EINTR]   = "Interrupted system call",
};

/* 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]);
}