FPUTS(3POSIX)
π FPUTS(3POSIX) β the POSIX Programmer's Manual, bestie edition π
okay so before we even get into it: this is fputs, page 3POSIX, from the POSIX Programmer's Manual. hi hello welcome, pull up a chair, we're putting strings on streams today and honestly? iconic behavior. β¨
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual, periodt. But listen β the Linux implementation of this interface may differ (so like, go read the corresponding Linux manual page for the details of Linux behavior, no cap), or the interface might not even be implemented on Linux at all. π Check before you commit, bestie.
π NAME π
fputs β put a string on a stream. that's it. that's the whole job. π
β¨ SYNOPSIS β¨
#include <stdio.h>
int fputs(const char *restrict s, FILE *restrict stream);
look at her. two restricts. she's mysterious, she's efficient, she's not here for your aliasing nonsense. π¦
π DESCRIPTION π
The functionality described on this reference page is aligned with the ISO C standard. So if there's any conflict between what's written here and the ISO C standard? That's unintentional, fr fr. This volume of POSIX.1β2017 defers to the ISO C standard. the ISO C standard is the main character here and we're just living in her world. π
So what does fputs() actually do? The fputs() function shall write the null-terminated string pointed to by s to the stream pointed to by stream. And the terminating null byte? shall not be written. nope. not invited. she stays home. π
And the timestamps β okay this part is lowkey important so pay attention: 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(). So it's not instant-instant, it's "marked for update", and the actual moment lands somewhere in that window. noted. β
π₯ RETURN VALUE π₯
Upon successful completion, fputs() shall return a non-negative number. Just non-negative. That's the whole promise. She's flexible like that. π
Otherwise β and this is the part where things go wrong β it shall return EOF, set an error indicator for the stream, and set errno to indicate the error. Three things. All at once. it's giving "we're not just failing, we're documenting the failure." π
π ERRORS π
Refer to fputc(). (yeah, she delegates. why reinvent the wheel when your cousin already did it. π«Ά)
The following sections are informative. like, they're not requirements, they're the lore. π§
π 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. very "waiting for my friend to text back" energy, honestly.
#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);
...
see how asctime() already brings its own newline so you don't have to add one? chef's kiss. that's the whole vibe of this function. π
π APPLICATION USAGE π
The puts() function appends a <newline> while fputs() does not. that's the entire difference and it matters, bestie. if you want a newline, you add it yourself. self-care. β¨
This volume of POSIX.1β2017 requires that successful completion simply return a non-negative integer. And because that's all it requires, there are at least three known different implementation conventions for this requirement:
- Return a constant value. simple. unbothered.
- Return the last character written. nostalgic. retro. respecting the ancestors.
- 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. (she's doing her best, the return type is just a regularintand it's TIRED. π)
π§ RATIONALE π§
The fputs() function is one whose source code was specified in the referenced The C Programming Language. Ancient texts. legendary texts. π
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. (the accumulator was just... sitting there... holding a character... and they returned it. no thoughts, head empty, return the accumulator. π)
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 like, the standard said one thing and the code said another and everyone just agreed to keep doing it. classic. π
π¦ FUTURE DIRECTIONS π¦
None. literally none. she's done evolving. she's perfect as she is. periodt. π
β 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!! brought to you by the fine people at IEEE / The Open Group, dated 2017, filed under FPUTS(3POSIX) in the POSIX Programmer's Manual. go forth and write your strings. the terminating null byte is NOT coming with you. πβ¨ππ¦
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms