UNIX errno -> message conversion

Pages: 12
I just made this, and then I thought it might help some people, so I'm posting it here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* For errno -> error conversion. An error's index is the corresponding
 * errno value (minus 1). */
struct {
    char* errname;
    char* errmesg;
} errors[] = {
    { "EPERM", "operation not permitted" },
    { "ENOENT", "no such file or directory" },
    { "ESRCH", "no such process" },
    { "EINTR", "interrupted system call" },
    { "EIO", "input/output error" },
    { "ENXIO", "no such device/address" },
    { "E2BIG", "argument list too long" },
    { "ENOEXEC", "exec format error" },
    { "EBADF", "bad file number" },
    { "ECHILD", "no child process" },
    { "EAGAIN", "try again" },
    { "ENOMEM", "not enough memory" },
    { "EACCES", "permission denied" },
    { "EFAULT", "bad address" },
    { "ENOTBLK", "block device required" },
    { "EBUSY", "device/resource is busy" },
    { "EEXIST", "file exists already" },
    { "EXDEV", "cross-device link" },
    { "ENODEV", "no such device" },
    { "ENOTDIR", "not a directory" },
    { "EISDIR", "is a directory" },
    { "EINVAL", "invalid argument" },
    { "ENFILE", "file table overflow" },
    { "EMFILE", "too many open files" },
    { "ENOTTY", "not a typewriter" }, /* What the hell??? */
    { "ETXTBSY", "text file is busy" },
    { "EFBIG", "file too large" },
    { "ENOSPC", "not enough/no disk space" },
    { "ESPIPE", "illegal seek" },
    { "EROFS", "read-only file system" },
    { "EMLINK", "too many links" },
    { "EPIPE",  "broken pipe" },
    { NULL, NULL }
};


I think I may have made a mistake in the numbering, though. If anyone can see my mistake, could they point it out? I've looked up and down and it seems fine...

Edit: I had missed out EBADF. I fixed it now, so it should be almost 100% correct, if not 100%.

Yes this is very easy to make but it took like ten minutes, and it took even longer to find a table on the internet. So I may have saved you guys like, twenty minutes of easy work!

Example usage:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int main(void) {
    int i = 1;
    
    while (i < 32) {
        error("", 1);
        errno = i;
        i++;
    }
    return 0;
}

/* Print an error message */
void error(const char* errmsg, int show_errno) {
#ifdef errno
    if (show_errno == 1) {
        fprintf(stderr, "%s -- %s", errors[errno - 1], errors[errno - 1]);
    } else {
        if (errmsg != NULL)
            fprintf(stderr, "%s", errmsg);
    }
#else
    if (errmsg != NULL)
        fprintf(stderr, "%s", errmsg);
#endif
    printf("\n");
}
(null) -- (null)
EPERM -- operation not permitted
ENOENT -- no such file or directory
ESRCH -- no such process
EINTR -- interrupted system call
EIO -- input/output error
ENXIO -- no such device/address
E2BIG -- argument list too long
ENOEXEC -- exec format error
EBADF -- bad file number
ECHILD -- no child process
EAGAIN -- try again
ENOMEM -- not enough memory
EACCES -- permission denied
EFAULT -- bad address
ENOTBLK -- block device required
EBUSY -- device/resource is busy
EEXIST -- file exists already
EXDEV -- cross-device link
ENODEV -- no such device
ENOTDIR -- not a directory
EISDIR -- is a directory
EINVAL -- invalid argument
ENFILE -- file table overflow
EMFILE -- too many open files
ENOTTY -- not a typewriter
ETXTBSY -- text file is busy
EFBIG -- file too large
ENOSPC -- not enough/no disk space
ESPIPE -- illegal seek
EROFS -- read-only file system
Last edited on
man 3 perror

Aaaaargh!
char *strerror(int errnum) returns the error message
Stop it! That took me ten/twenty minutes of easy work!

Before I mark this as solved; could someone explain what the purpose of "not a typewriter" is?
Last edited on
Indeed,

Yahoo! search and away

http://www.aplawrence.com/Unixart/errors.html

#define ENOTTY 25 /* Not a typewriter */

While a lot of people programming Unix and Linux may never have seen a real typewriter, would anyone ever confuse a computer with a typewriter? Seriously, this is the generic and time-honored Unix complaint when you try to do something that needs a character device. Ioctl's return this when applied to ordinary files, for example. So will attempts to get or set attributes ( tcgettattr() tcsetattr() ) on something not a terminal device. So will tcdrain(), tcflush(), tcflow() and tcsendbreak().
I simply cannot understand how ANYONE could think a computer is a typewriter. What, do they try to pull the monitor to the side or something and end up breaking it?

NOT A TYPEWRITER! STOP IT YOU'RE BREAKING MY NECK! AAAAARGH NOT A TYPEWRITER, DAMNIT, AAAAAAARGH!
No cursing please :P
What? That isn't cursing :l
What do you have against people swearing so much? Most of us hardly swear at all here, and even so; "damn" isn't a "swear word" to the best of my knowledge.

Literally it is cursing ("damn you" -> "curse you!") but in what way is it cursing in the modern sense?
Some people consider it a swear word. I personally don't really care as long as you aren't using it every other word. ^_^

e.g.
BAD: That ****ing ***** ****ing stole my ****ing **** new ****ing car!!!
meh, But the word has been changed because society has changed. Hehehe I had a mini-debate with someone about whether or not words were absolute.
Personally I don't care whether people swear or not, or even spout racist/sexist/*ist nonsense. It doesn't affect me; so I let them get on with it. They have the right to say what they want, as far as I'm concerned. Their fault if it gets them hit because a woman wants to disprove their "women are weaker than men" theory; or some African guy doesn't like their theory on the difference in evolution between whites and blacks (interestingly enough; white people tend to have thinner lips than black people. Monkeys also have very thin lips; ergo white people are closer to monkeys than black people. Me 1; racists 0).

I did laugh at Nick Griffin on Question Time. He got owned. For those who don't know; Nick Griffin is the leader of the British Na(zi)tional Party. He's a complete idiot; and in fact, he's an ex-con:
He has a controversial past, which includes a 1998 conviction for incitement to racial hatred for material denying the Holocaust.

How can you deny the Holocaust? What almost 20 million Jews, Slavs, Gypsies, etc. died of natural causes between 1930 and 1950?
If you include Russian casualties during Operation Barbarossa alone; that adds a further 27 million including civilians and military casualties.

What an idiot.

Oh and question time is a political show where normal people question politicians. I don't watch it but I did this one time because he was on it; and I wanted to see him get shown up. I wasn't disappointed.
Last edited on
Certain profanity used around here occasionally can be problematic for individuals who access the website
from a monitored connection, like if they are trying to be helpful to others over their lunch, for example.
That is true. That's another thing I strongly disagree with -- monitoring internet connections so that you can see exactly what your employees get up to. If they were playing games or something during working hours, fine; but I don't think employers should be so suspicious. It's a little bit OTT.

"I disapprove of what you say, but I will defend to the death your right to say it". - voltaire

closed account (z05DSL3A)
"Shaddap your face": Joe Dolce

Disclaimer:
This joke was bought to you by Grey Wolf Industries. All names are fictional and not based on any one. Any offences caused is unintentional, so get over it.


:0)
I have actualy never heard anyone say that the holocaust didn't happen, must be a British thing. :P
Because I had to say it.
Last edited on
I have actualy never heard anyone say that the holocaust didn't happen, must be a British thing. :P
Because I had to say it.

Racist.

















































OJ.
Last edited on
Racist.


Well, racist may be defined as:
1. a belief or doctrine that inherent differences among the various human races determine cultural or individual achievement, usually involving the idea that one's own race is superior and has the right to rule others.

And a race may be defined as:
1. a group of persons related by common descent or heredity.

So thus no it is not :P

(http://www.dictionary.com)
I said Only Joking :l

By the way
the transmission of genetic characters from parents to offspring
http://dictionary.reference.com/browse/heredity

derivation from an ancestor; lineage; extraction.
http://dictionary.reference.com/browse/descent

hatred or intolerance of another race or other races.
http://dictionary.reference.com/browse/racism

any of the traditional divisions of humankind, the commonest being the Caucasian, Mongoloid, and Negro, characterized by supposedly distinctive and universal physical characteristics: no longer in technical use.

http://dictionary.reference.com/browse/race

Therefore the British are a race. You are discriminating against the British race. You are being racist.

But I was joking, anyway...
Last edited on
Pages: 12