www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.c.stdlib.getErrno() under Windows?

reply "Garett Bass" <garettbass studiotekne.com> writes:
I'm able to successfully use strtol() with a well-formed 
numeric string.  However, I'm unable to retrieve the errno() 
values specified in the strtol() documentation when I 
provide a poorly-formed string.  In all cases that I have 
tried thus far, getErrno() always returns zero:

    char[] s = "QQQ\0";
    setErrno(0);
    int k = strtol(cast(char*)s, null, 0); // base 10
    int errno = getErrno();
    if (errno == 0) {
        writefln("k = %d", k);
    } else {
        writefln("Error : %d", errno);
    }

Any ideas?

Thanks,
Garett
Nov 01 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Tue, 1 Nov 2005 20:13:53 -0600, Garett Bass  
<garettbass studiotekne.com> wrote:
 I'm able to successfully use strtol() with a well-formed
 numeric string.  However, I'm unable to retrieve the errno()
 values specified in the strtol() documentation when I
 provide a poorly-formed string.  In all cases that I have
 tried thus far, getErrno() always returns zero:

     char[] s = "QQQ\0";
     setErrno(0);
     int k = strtol(cast(char*)s, null, 0); // base 10
     int errno = getErrno();
     if (errno == 0) {
         writefln("k = %d", k);
     } else {
         writefln("Error : %d", errno);
     }
I'm not sure it _should_ be setting errno, from MSDN: "strtol returns 0 if no conversion can be performed. wcstol returns values analogously to strtol. For both functions, errno is set to ERANGE if overflow or underflow occurs." It only sets errno on overflow or underflow. I write this to test my theory: #include <stdlib.h> #include <stdio.h> void main() { char *s = "QQQ"; strtol(s,NULL,0); printf("ERRNO(%d)",errno); } and on windows, using MS Visual Studio 6.0 it prints "ERRNO(0)". Regan
Nov 01 2005