mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Use re-entrant locks on stdio
This commit is contained in:
parent
4e9662cbc7
commit
1f229e4efc
78 changed files with 427 additions and 179 deletions
|
@ -18,21 +18,32 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* Writes string w/ trailing newline to stdout.
|
||||
*/
|
||||
int puts(const char *s) {
|
||||
FILE *f;
|
||||
static int PutsImpl(const char *s, FILE *f) {
|
||||
size_t n, r;
|
||||
f = stdout;
|
||||
if ((n = strlen(s))) {
|
||||
r = fwrite(s, 1, n, f);
|
||||
r = fwrite_unlocked(s, 1, n, f);
|
||||
if (!r) return -1;
|
||||
if (r < n) return r;
|
||||
}
|
||||
if (fputc('\n', f) == -1) {
|
||||
if (feof(f)) return n;
|
||||
if (fputc_unlocked('\n', f) == -1) {
|
||||
if (feof_unlocked(f)) return n;
|
||||
return -1;
|
||||
}
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes string w/ trailing newline to stdout.
|
||||
*
|
||||
* @return non-negative number on success, or `EOF` on error with
|
||||
* `errno` set and the `ferror(stdout)` state is updated
|
||||
*/
|
||||
int puts(const char *s) {
|
||||
FILE *f;
|
||||
int bytes;
|
||||
f = stdout;
|
||||
flockfile(f);
|
||||
bytes = PutsImpl(s, f);
|
||||
funlockfile(f);
|
||||
return bytes;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue