FPUTS(3P)
πΈ FPUTS(3P) πΈ
okay bestie, welcome to the POSIX Programmer's Manual, page FPUTS(3P) π this is the glow-up edition of a classic, and yes we're doing the whole thing, no skipping, no cutting corners, we are thorough in this house π
β¨ PROLOG β¨
so like, heads up: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. π«Ά not me warning you before we even start, but that's the vibe.
π NAME π
fputs β put a string on a stream. that's it. that's the whole thing. iconic.
π¦ SYNOPSIS π¦
#include <stdio.h>
int fputs(const char *restrict s, FILE *restrict stream);
look at her. two restricts. she's got range. β¨
π DESCRIPTION π
okay so the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1β2017 defers to the ISO C standard. fr fr, the ISO C girlies are the blueprint.
The fputs() function shall write the null-terminated string pointed to by s to the stream pointed to by stream. The terminating null byte shall not be written. π«π like, the \0 is NOT invited to the party, it stays home.
The last data modification and last file status change timestamps of the file shall be marked for update between the successful execution of fputs() and the next successful completion of a call to fflush() or fclose() on the same stream or a call to exit() or abort(). the timestamps are getting a little makeover, but like, on a delay. slay scheduling π
π RETURN VALUE π
Upon successful completion, fputs() shall return a non-negative number. Otherwise, it shall return EOF, set an error indicator for the stream, and set errno to indicate the error. so like, success = some number β₯ 0, no notes. failure = EOF, sad stream, and errno tells you what went wrong. π
π₯ ERRORS π₯
Refer to fputc(). yeah bestie, the error lore lives over there, go read that page.
The following sections are informative.
π EXAMPLES π
Printing to Standard Output
The following example gets the current time, converts it to a string using localtime() and asctime(), and prints it to standard output using fputs(). It then prints the number of minutes to an event for which it is waiting. π lowkey a whole tiny app in here.
#include <time.h>
#include <stdio.h>
...
time_t now;
int minutes_to_event;
...
time(&now);
printf("The time is ");
fputs(asctime(localtime(&now)), stdout);
printf("There are still %d minutes to the event.\n",
minutes_to_event);
...
πΈ APPLICATION USAGE πΈ
The puts() function appends a <newline> while fputs() does not. that's THE difference, bestie, write it down. puts() adds the dramatic line break, fputs() is like "no extra characters, I'm a professional." π
This volume of POSIX.1β2017 requires that successful completion simply return a non-negative integer. There are at least three known different implementation conventions for this requirement:
- Return a constant value.
- Return the last character written.
- Return the number of bytes written. Note that this implementation convention cannot be adhered to for strings longer than
{INT_MAX}bytes as the value would not be representable in the return type of the function. For backwards-compatibility, implementations can return the number of bytes for strings of up to{INT_MAX}bytes, and return{INT_MAX}for all longer strings.
so basically, everyone agreed on "a non-negative number" and then nobody agreed on which number. classic committee behaviour ngl π
π§ RATIONALE π§
The fputs() function is one whose source code was specified in the referenced The C Programming Language. In the original edition, the function had no defined return value, yet many practical implementations would, as a side-effect, return the value of the last character written as that was the value remaining in the accumulator used as a return value. In the second edition of the book, either the fixed value 0 or EOF would be returned depending upon the return value of ferror(); however, for compatibility with extant implementations, several implementations would, upon success, return a positive value representing the last byte written.
so the return value has like, a whole ancestral history. accidental return values from the accumulator era. the chaos of it all. the way the past is never really past πβ¨
π FUTURE DIRECTIONS π
None.
(the most peaceful sentence in the entire document, honestly. she's at rest.)
β SEE ALSO β
- Section 2.5, Standard I/O Streams,
fopen(),putc(),puts() - The Base Definitions volume of POSIX.1β2017,
<stdio.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie. no cap, every flag, every caveat, every timestamp, all of it. π«Ά
okay so final sign-off: this masterpiece was brought to you by IEEE/The Open Group, dated 2017, and that's FPUTS(3P) β put a string on a stream, don't write the null, and go be the main character of your codebase. π
ππ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms