Re: [HACKERS] pg_dump return status..
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. Of course, if sprintf() returns an error, you have pretty big problems. :-) -- Bruce Momjian| http://candle.pha.pa.us [EMAIL PROTECTED] | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup.| Drexel Hill, Pennsylvania 19026
Re: [HACKERS] pg_dump return status..
Nathan Myers writes: On Fri, Jan 05, 2001 at 11:20:43AM -0500, Tom Lane wrote: Philip Warner [EMAIL PROTECTED] 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 [EMAIL PROTECTED] -./\.- opinion of Schlumberger, Baker http://www.crosswinds.net/~petef -./\.- Hughes or their divisions.
Re: [HACKERS] pg_dump return status..
Pete Forman [EMAIL PROTECTED] writes: Philip Warner writes: All I need to know is how to detect an error. Does it return EOF on error? The standard sprintf() returns a negative int on error. I thought we were talking about fprintf. sprintf can't really detect any errors anyway, except maybe a bad format string. regards, tom lane
Re: [HACKERS] pg_dump return status..
[EMAIL PROTECTED] (Nathan Myers) writes: 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. On older systems fprintf returns 0 on success and EOF on failure. 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. Probably 0/EOF. sprintf on SunOS returns its first argument. Ian
Re: [HACKERS] pg_dump return status..
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. On older systems fprintf returns 0 on success and EOF on failure. The books I have all recommend testing for "a negative return value" to detect printf errors. The C standard also specifies "a negative value" for errors --- it is not guaranteed that that value is EOF. regards, tom lane