<errno.h> errno strerror()

5 posts / 0 new
Last post
JosDuchIt
JosDuchIt's picture
Offline
Last seen: 7 years 4 months ago
Joined: 2012-01-08 20:57
<errno.h> errno strerror()

When you use strerro(errno) i understand it gives you information about the failure type of last C-lib function used.
I seem to get a "Function not implemented" error in a "switch" construct in case i get till the end of the "case"'s and not finding a match. Thar's OK for me.

I have some strange behaviour, in which, even if the match should be (and is) found, i get the same error too. This happens when i use the switch for the first time; As said the switch works OK though and does what is expected (except for the strange error message).
This happens for every valid "case", but only when the switch is used for the first time.

In fact it happens when i change (for the Gui4Cli interpreter) from window mode, to console input mode, and do send whatever (valid) command to the interpreter.
The switch i am talking about is the one that interprets the given command.

It is rather strange and i don't see how this happens, or how i could avoid it.

I would also like to know what errorstrings are defined for which standard C functions ? Where could i find this info?

thomas
thomas's picture
Offline
Last seen: 2 hours 15 min ago
Joined: 2011-05-16 14:23
strerror() simply returns the

strerror() simply returns the text corresponding to the number you supply to it, so it is completely unrelated to your problem. You could as well do printf("%s\n",strerrno(78));

And errno is only set by functions which are documented to do so.

switch is not a function but a syntax construct and it surely does not set errno.

Some function you called before set errno to 78 and errno keeps its value until another function overwrites it. This has nothing to do with switch running out of cases.

I would also like to know what errorstrings are defined for which standard C functions ? Where could i find this info?

I would expect that strerrno knows all errnos which are defined in sys/errno.h.

JosDuchIt
JosDuchIt's picture
Offline
Last seen: 7 years 4 months ago
Joined: 2012-01-08 20:57
@Thomas Thanks, i understood

@Thomas
Thanks, i understood some of this.
Good to know too it is not the swith construct generating an eerno corresponding to "Function not implemented."
edit: added
------------------------

errno is only set by functions which are documented to do so.

I did find this
http://www.kernel.org/doc/man-pages/online/pages/man3/errno.3.html
usefull
It states that errno is set by "system calls and some library functions in the event of an error-to indicate what went wrong"
If i understand this doc well it is not usefull to test for errno if not after a previous test for the return value of the function you just did activate.

But how do i know which functions do provide an errno, and which ones?
------------------------

What i am looking for now is
- which functions do generate the above errno (did not find that yet)
hunting throigh the SDK i don't find any library call that uses it.
- is there no overview giving this kind of info for all errno defined in sys/errno.h ?

thomas
thomas's picture
Offline
Last seen: 2 hours 15 min ago
Joined: 2011-05-16 14:23
Check the function

Check the function documentation. In most docs you will find a section like "if the function returns a failure, errno will give further information".

For example: http://www.cplusplus.com/reference/clibrary/cstdlib/strtod/

If the correct value is out of the range of representable values, a positive or negative HUGE_VAL is returned, and the global variable errno is set to ERANGE.

Note that "system calls" in your quote is not correct for AmigaOS. Only functions in clib/newlib (a.k.a. ANSI C) might set errno. Similarly "library" does not refer to AmigaOS libraries but to static link libraries (or perhaps .so files).

So searching the SDK (which mostly documents AmigaOS) will probably not give you any result. There is no AmigaOS function which will (or can) set errno.

The AmigaOS equivalent for errno is IDOS->IoErr(). Many AmigaOS functions, even non-DOS, use IoErr() to return more detailed information about an error.

JosDuchIt
JosDuchIt's picture
Offline
Last seen: 7 years 4 months ago
Joined: 2012-01-08 20:57
@Thomas, that was very

@Thomas, that was very enlightening.

Log in or register to post comments