Skip site navigation (1) Skip section navigation (2)

Re: Strange interval arithmetic

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Strange interval arithmetic
Date: 2005-12-01 20:45:38
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackerspgsql-patches
On Thu, Dec 01, 2005 at 03:31:41PM -0500, Greg Stark wrote:
> Greg Stark <gsstark(at)MIT(dot)EDU> writes:
> > Generally speaking looking at errno when you haven't received an error return
> > from a libc function is asking for trouble. It could be leftover from any
> > previous libc error. 
> > 
> > That's how you get programs saying things like "strtol: No such file or
> > directory" ...
> Ah, I take back my taking back of this. It's still dicey to be doing it this
> way -- even if you reset errno before calling the library function.
> The problem is that the function can call other libc functions, which may in
> turn return errors. But these errors might be incidental and handled by the
> function you're calling.

I had that concern, as I've seen such incidental errno changes
before.  But Tom pointed out the following from SUS:

  The strtol() function shall not change the setting of errno if

Immediately after that the standard says:

  Since 0, {LONG_MIN} or {LLONG_MIN}, and {LONG_MAX} or {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, then call strtol() or strtoll(), then check errno.

I don't know if any systems are non-compliant in this respect, but
Tom said that "we've been doing it that way (errno test only) for
many years without complaints."

Michael Fuhr

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2005-12-01 20:49:36
Subject: Re: [HACKERS] Strange interval arithmetic
Previous:From: Tom LaneDate: 2005-12-01 20:43:05
Subject: Re: Strange interval arithmetic

pgsql-patches by date

Next:From: Magnus HaganderDate: 2005-12-01 20:49:06
Subject: Re: Check for integer overflow in datetime functions
Previous:From: Tom LaneDate: 2005-12-01 20:43:05
Subject: Re: Strange interval arithmetic

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group