Re: function question



"Bill Cunningham" <nospam@xxxxxxxxxxxxx> writes:

Volker Birk wrote:
Bill Cunningham <nospam@xxxxxxxxxxxxx> wrote:
errno = 0;

You shouldn't set errno yourself. The behaviour is undefined.

Yours,
VB.

There is one function that returns -1 on success. I can't remember if
it's a standard C function or a system call. With it I have read that it is
sugessted to set errno to zero. errno never sets itself to zero and I
believe all system calls return -1 on error.

Needed for functions such as strtol, strtoll, atol, atoll, atoi where
the (Solaris) manual page says:

USAGE
Because 0, LONG_MIN, LONG_MAX, LLONG_MIN, and LLONG_MAX are
returned on error and are also valid returns on success, an
application wishing to check for error situations should set
errno to 0, call the function, then check errno and if it is
non-zero, assume an error has occurred.



Casper
.



Relevant Pages

  • Re: detabbing again
    ... If no conversion could be performed, zero is returned. ... stored in errno. ... strtoll is but not strtol. ...
    (comp.lang.c)
  • Re: Schildt
    ... ever set errno to zero". ... "The value of errno is zero at program ... The standard legislates what may be called C99. ...
    (comp.lang.c)
  • Re: [PATCH] libc_r bug: successful close(2) sets errno to ENOTTY
    ... the standard specifies that the errno shall only be ... Wrong, strtol() can set errno in two cases, when the value is outside ...
    (freebsd-current)
  • Re: detabbing again
    ... Calling printf can loose the value of errno. ... test argvto see if it is zero and spit this case back to the user ... to the pointer whose address you pass to strtol. ...
    (comp.lang.c)
  • Re: Finding a word inside a string
    ... If strtol sets errno to ERANGE, ... If v happens to be zero, you do not know whether that is because your ...
    (comp.lang.c)