Not necessarily zero. Linux for example returns a non-zero value
on success. On failure it also sets the error indicator on the
stream and sets errno.
Mac OS X also have the following:
COMPATIBILITY
fputs() now returns a non-negative number (as opposed to 0) on successful
completion. As a result, many tests (e.g., "fputs() == 0", "fputs() !=
0") do not give the desired result. Use "fputs() != EOF" or "fputs() ==
EOF" to determine success or failure.
This is exactly what bit me so I wouldn't mind having a similar
note in our manual.
Thoughts?
- todd
Index: lib/libc/stdio/fputs.3
===================================================================
RCS file: /cvs/src/lib/libc/stdio/fputs.3,v
retrieving revision 1.11
diff -u -p -u -r1.11 fputs.3
--- lib/libc/stdio/fputs.3 13 Jan 2015 14:02:30 -0000 1.11
+++ lib/libc/stdio/fputs.3 25 May 2016 20:39:34 -0000
@@ -60,15 +60,13 @@ and a terminating newline character,
to the stream
.Em stdout .
.Sh RETURN VALUES
-The
-.Fn fputs
-function returns 0 on success and
+Upon successful completion a non-negative integer is returned.
+Otherwise,
.Dv EOF
-on error;
-.Fn puts
-returns a non-negative integer on success and
-.Dv EOF
-on error.
+is returned, the global variable
+.Va errno
+is set to indicate the error,
+and the error indicator is set for the stream.
.Sh ERRORS
.Bl -tag -width Er
.It Bq Er EBADF