mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Make important improvements
- Fix preadv() and pwritev() for old distros - Introduce _npassert() and _unassert() macros - Prove that file locks work properly on Windows - Support fcntl(F_DUPFD_CLOEXEC) on more systems
This commit is contained in:
parent
1ad2f530f9
commit
3f49889841
130 changed files with 1225 additions and 431 deletions
|
@ -38,7 +38,7 @@ FILE *fdopen(int fd, const char *mode) {
|
|||
f->fd = fd;
|
||||
f->bufmode = ischardev(fd) ? _IOLBF : _IOFBF;
|
||||
f->iomode = fopenflags(mode);
|
||||
f->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
((pthread_mutex_t *)f->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
f->size = BUFSIZ;
|
||||
if ((f->buf = malloc(f->size))) {
|
||||
if ((f->iomode & O_ACCMODE) != O_RDONLY) {
|
||||
|
|
|
@ -23,5 +23,5 @@
|
|||
* Acquires reentrant lock on stdio object, blocking if needed.
|
||||
*/
|
||||
void(flockfile)(FILE *f) {
|
||||
pthread_mutex_lock(&f->lock);
|
||||
pthread_mutex_lock((pthread_mutex_t *)f->lock);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) {
|
|||
f->end = size;
|
||||
f->size = size;
|
||||
f->iomode = fopenflags(mode);
|
||||
f->lock._type = PTHREAD_MUTEX_RECURSIVE;
|
||||
((pthread_mutex_t *)f->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
|
||||
if (f->iomode & O_APPEND) {
|
||||
if ((p = memchr(buf, '\0', size))) {
|
||||
f->beg = p - (char *)buf;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
@ -24,5 +25,5 @@
|
|||
* @return 0 on success, or non-zero if another thread owns the lock
|
||||
*/
|
||||
int(ftrylockfile)(FILE *f) {
|
||||
return pthread_mutex_trylock(&f->lock);
|
||||
return pthread_mutex_trylock((pthread_mutex_t *)f->lock);
|
||||
}
|
||||
|
|
|
@ -16,11 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/lock.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
* Releases lock on stdio object.
|
||||
*/
|
||||
void(funlockfile)(FILE *f) {
|
||||
pthread_mutex_unlock(&f->lock);
|
||||
pthread_mutex_unlock((pthread_mutex_t *)f->lock);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@
|
|||
#include "libc/limits.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
compatfn char *gets(char *s) {
|
||||
char *gets(char *s) {
|
||||
return fgets(s, INT_MAX, stdin);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_STDIO_STDIO_H_
|
||||
#define COSMOPOLITAN_LIBC_STDIO_STDIO_H_
|
||||
#include "libc/fmt/pflink.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
#ifndef _STDIO_H
|
||||
#define _STDIO_H
|
||||
#include "libc/fmt/pflink.h"
|
||||
|
||||
#define L_ctermid 20
|
||||
#define FILENAME_MAX PATH_MAX
|
||||
#define FOPEN_MAX 1000
|
||||
|
@ -17,19 +15,19 @@ COSMOPOLITAN_C_START_
|
|||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
typedef struct FILE {
|
||||
uint8_t bufmode; /* 0x00 _IOFBF, etc. (ignored if fd=-1) */
|
||||
bool noclose; /* 0x01 for fake dup() todo delete! */
|
||||
uint32_t iomode; /* 0x04 O_RDONLY, etc. (ignored if fd=-1) */
|
||||
int32_t state; /* 0x08 0=OK, -1=EOF, >0=errno */
|
||||
int fd; /* 0x0c ≥0=fd, -1=closed|buffer */
|
||||
uint32_t beg; /* 0x10 */
|
||||
uint32_t end; /* 0x14 */
|
||||
char *buf; /* 0x18 */
|
||||
uint32_t size; /* 0x20 */
|
||||
uint32_t nofree; /* 0x24 */
|
||||
int pid; /* 0x28 */
|
||||
char *getln; /* 0x30 */
|
||||
pthread_mutex_t lock; /* 0x38 */
|
||||
uint8_t bufmode; /* 0x00 _IOFBF, etc. (ignored if fd=-1) */
|
||||
bool noclose; /* 0x01 for fake dup() todo delete! */
|
||||
uint32_t iomode; /* 0x04 O_RDONLY, etc. (ignored if fd=-1) */
|
||||
int32_t state; /* 0x08 0=OK, -1=EOF, >0=errno */
|
||||
int fd; /* 0x0c ≥0=fd, -1=closed|buffer */
|
||||
uint32_t beg; /* 0x10 */
|
||||
uint32_t end; /* 0x14 */
|
||||
char *buf; /* 0x18 */
|
||||
uint32_t size; /* 0x20 */
|
||||
uint32_t nofree; /* 0x24 */
|
||||
int pid; /* 0x28 */
|
||||
char *getln; /* 0x30 */
|
||||
char lock[16]; /* 0x38 */
|
||||
} FILE;
|
||||
|
||||
extern FILE *stdin;
|
||||
|
@ -91,9 +89,9 @@ char *ctermid(char *);
|
|||
void perror(const char *) relegated;
|
||||
|
||||
typedef uint64_t fpos_t;
|
||||
compatfn char *gets(char *) paramsnonnull();
|
||||
compatfn int fgetpos(FILE *, fpos_t *) paramsnonnull();
|
||||
compatfn int fsetpos(FILE *, const fpos_t *) paramsnonnull();
|
||||
char *gets(char *) paramsnonnull();
|
||||
int fgetpos(FILE *, fpos_t *) paramsnonnull();
|
||||
int fsetpos(FILE *, const fpos_t *) paramsnonnull();
|
||||
|
||||
int system(const char *);
|
||||
int systemexec(const char *);
|
||||
|
@ -195,4 +193,4 @@ int vfprintf_unlocked(FILE *, const char *, va_list)
|
|||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_STDIO_STDIO_H_ */
|
||||
#endif /* _STDIO_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue