2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_STDIO_INTERNAL_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_STDIO_INTERNAL_H_
|
2024-12-17 04:51:27 +00:00
|
|
|
#include "libc/atomic.h"
|
|
|
|
#include "libc/intrin/dll.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/stdio/stdio.h"
|
2023-08-14 03:31:27 +00:00
|
|
|
#include "libc/thread/thread.h"
|
2021-03-27 05:31:41 +00:00
|
|
|
|
|
|
|
#define PUSHBACK 12
|
|
|
|
|
2024-12-17 04:51:27 +00:00
|
|
|
#define FILE_CONTAINER(e) DLL_CONTAINER(struct FILE, elem, e)
|
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2023-08-14 03:31:27 +00:00
|
|
|
struct FILE {
|
2024-12-17 04:51:27 +00:00
|
|
|
char bufmode; /* _IOFBF, _IOLBF, or _IONBF */
|
|
|
|
char freethis; /* fclose() should free(this) */
|
|
|
|
char freebuf; /* fclose() should free(this->buf) */
|
|
|
|
char forking; /* used by fork() implementation */
|
|
|
|
int oflags; /* O_RDONLY, etc. */
|
|
|
|
int state; /* 0=OK, -1=EOF, >0=errno */
|
|
|
|
int fd; /* ≥0=fd, -1=closed|buffer */
|
2023-09-12 04:34:53 +00:00
|
|
|
int pid;
|
2024-12-17 04:51:27 +00:00
|
|
|
atomic_int refs;
|
|
|
|
unsigned size;
|
|
|
|
unsigned beg;
|
|
|
|
unsigned end;
|
|
|
|
char *buf;
|
2023-09-12 04:34:53 +00:00
|
|
|
pthread_mutex_t lock;
|
2024-12-17 04:51:27 +00:00
|
|
|
struct Dll elem;
|
|
|
|
char *getln;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Stdio {
|
|
|
|
pthread_mutex_t lock; /* Subordinate to FILE::lock */
|
|
|
|
struct Dll *files;
|
2023-08-14 03:31:27 +00:00
|
|
|
};
|
|
|
|
|
2024-12-17 04:51:27 +00:00
|
|
|
extern struct Stdio __stdio;
|
2022-08-11 19:26:30 +00:00
|
|
|
|
2024-12-17 04:51:27 +00:00
|
|
|
void __stdio_lock(void);
|
|
|
|
void __stdio_unlock(void);
|
|
|
|
void __stdio_ref(FILE *);
|
|
|
|
void __stdio_unref(FILE *);
|
|
|
|
void __stdio_unref_unlocked(FILE *);
|
2023-07-24 15:31:54 +00:00
|
|
|
bool __stdio_isok(FILE *);
|
|
|
|
FILE *__stdio_alloc(void);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_STDIO_INTERNAL_H_ */
|