bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSLog() / NSLogv() annoyance


From: Chris B. Vetter
Subject: Re: NSLog() / NSLogv() annoyance
Date: Thu, 31 Jul 2003 09:54:35 -0700

On 30 Jul 2003 21:47:29 -0600
Adam Fedor <fedor@doc.com> wrote:
[...]
> > Can't figure out where errno is set to 2, though I suspect it's
> > coming from _NSLog_standard_printf_handler() trying to write to
> > syslog(?).
> I traced this down (and down, etc) - it actually happens when NSLog
> gets a user default, and NSUserDefaults gets set up and looks for
> .GNUsteprc, eventually getting to:
>   +[GSAttrDictionary attributesAt: traverseLink:]
> which does a 'stat' on the file which doesn't exist. Anyway, what
> should GNUstep do in this case? Reset errno to 0? The documentation
> says the value isn't significant unless a library function returns an
> error, so it really is undefined in this case.

That's interesting, because .GNUsteprc does exist, though it's empty.

Resetting errno to 0 isn't a good idea, since it may be set to an actual
error by a previous system call, that still needs to be checked (and
NSLog() is used to dump some info regarding said system call...)

Imagine something like
(actually that's how I stumbled across the 'problem')

  - (id) initWithHostname: (char *) hostname
  {
    // ...

    error = getaddrinfo(hostname, NULL, &hints, &address);
    NSLog(@"getaddrinfo() for host %s returns: %s",
          gai_strerror(error));

    if(error)
      return nil;

    errno = 0; // ignore

    // ... more stuff

    return self;
  }

If NSLog() sets errno to 0 ...

Instead, it could/should "back up" the original value of errno, call
stat(2) and do some kind of evaluation if necessary, then restore the
original?

-- 
Chris




reply via email to

[Prev in Thread] Current Thread [Next in Thread]