Re: pg_dump return status..

From: Pete Forman <pete(dot)forman(at)westerngeco(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_dump return status..
Date: 2001-01-08 09:36:21
Message-ID: 14937.35349.648362.197502@kryten.bedford.waii.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Nathan Myers writes:
> On Fri, Jan 05, 2001 at 11:20:43AM -0500, Tom Lane wrote:
> > Philip Warner <pjw(at)rhyme(dot)com(dot)au> writes:
> > > how do I
> > > check for a failed write in a way that works on all Unixes? Is the
> > > following OK:
> >
> > > - fwrite: ok if return value equals item count
> > > - fprintf: ok if return value > 0.
> > > - fputc: ok if != EOF
> >
> > Probably fprintf() >= 0 --- according to my specs, it returns the number
> > of chars emitted, or a negative value on error. The other two are
> > correct.
>
> An fprintf returning 0 is a suspicious event; it's easy to imagine
> cases where it makes sense, but I don't think I have ever coded one.
> Probably >N (where N is the smallest reasonable output, defaulting
> to 1) may be a better test in real code.
>
> As I recall, on SunOS 4 the printf()s don't return the number of
> characters written. I don't recall what they do instead, and have
> no access to such machines any more.
>
> Other old BSD-derived systems are likely to have have wonky return
> values/types on the printf()s. Looking at the list of supported
> platforms, none jump out as likely candidates, but in the "unsupported"
> list, Ultrix and NextStep do. (Do we care?)
>
> If SunOS 4 is to remain a supported platform, the printf checks may
> need to be special-cased for it.

Current Solaris is liable to problems still, though these are not
relevant to this thread. printf() and fprintf() have always returned
the number of characters transmitted, or EOF for failure. It is
sprintf() that has problems.

There are two versions of sprintf() available in SunOS 4 - 8. The
standard one (ANSI C) in libc returns an int, the number of characters
written (excluding '\0'). The BSD version returns a char* which
points to the target. If you have a -lbsd on your link line then you
get the BSD version. There are no compiler errors, just run time
errors if you rely on the return from sprintf() being the number of
characters. The workaround is to put an extra -lc on the link line
before the -lbsd if your code needs both standard sprintf() and some
other BSD function.

Ultrix is documented as having the same behaviour as Solaris. I don't
know about NeXTSTEP/OPENSTEP/GNUStep.
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pete(dot)forman(at)westerngeco(dot)com -./\.- opinion of Schlumberger, Baker
http://www.crosswinds.net/~petef -./\.- Hughes or their divisions.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Esa Pikkarainen 2001-01-08 10:13:27 Version 7.1 when??
Previous Message Frank Joerdens 2001-01-08 09:21:57 Re: PHP and PostgreSQL

Browse pgsql-hackers by date

  From Date Subject
Next Message Pete Forman 2001-01-08 10:03:25 Re: patch: contrib/pgcrypto sanity
Previous Message Tatsuo Ishii 2001-01-08 09:12:56 Re: ALL, ANY bug?