mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 14:22:28 +00:00
parent
ce9aeb2aed
commit
1df4296208
3 changed files with 19 additions and 9 deletions
|
@ -17,9 +17,11 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/stdio/internal.h"
|
#include "libc/stdio/internal.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
|
#include "libc/sysv/consts/s.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/thread/thread.h"
|
#include "libc/thread/thread.h"
|
||||||
|
|
||||||
|
@ -33,9 +35,12 @@
|
||||||
*/
|
*/
|
||||||
FILE *fdopen(int fd, const char *mode) {
|
FILE *fdopen(int fd, const char *mode) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(fd, &st))
|
||||||
|
return 0;
|
||||||
if ((f = __stdio_alloc())) {
|
if ((f = __stdio_alloc())) {
|
||||||
f->fd = fd;
|
f->fd = fd;
|
||||||
f->bufmode = ischardev(fd) ? _IOLBF : _IOFBF;
|
f->bufmode = S_ISREG(st.st_mode) ? _IOFBF : _IONBF;
|
||||||
f->iomode = fopenflags(mode);
|
f->iomode = fopenflags(mode);
|
||||||
f->buf = f->mem;
|
f->buf = f->mem;
|
||||||
f->size = BUFSIZ;
|
f->size = BUFSIZ;
|
||||||
|
|
|
@ -29,16 +29,15 @@
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
static ssize_t readvall(int fd, struct iovec *iov, int iovlen) {
|
static ssize_t readvall(int fd, struct iovec *iov, int iovlen) {
|
||||||
int olde;
|
|
||||||
ssize_t rc;
|
ssize_t rc;
|
||||||
size_t got, toto;
|
size_t got, toto;
|
||||||
toto = 0;
|
toto = 0;
|
||||||
olde = errno;
|
|
||||||
do {
|
do {
|
||||||
if ((rc = readv(fd, iov, iovlen)) == -1) {
|
if ((rc = readv(fd, iov, iovlen)) == -1) {
|
||||||
if (toto && errno == EINTR) {
|
if (toto) {
|
||||||
errno = olde;
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
|
return toto;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +134,12 @@ size_t fread_unlocked(void *buf, size_t stride, size_t count, FILE *f) {
|
||||||
iov[1].iov_base = NULL;
|
iov[1].iov_base = NULL;
|
||||||
iov[1].iov_len = 0;
|
iov[1].iov_len = 0;
|
||||||
}
|
}
|
||||||
if ((rc = readvall(f->fd, iov, 2)) == -1) {
|
if (f->bufmode == _IONBF) {
|
||||||
|
rc = readv(f->fd, iov, 2);
|
||||||
|
} else {
|
||||||
|
rc = readvall(f->fd, iov, 2);
|
||||||
|
}
|
||||||
|
if (rc == -1) {
|
||||||
f->state = errno;
|
f->state = errno;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
5
third_party/lua/test/files.lua
vendored
5
third_party/lua/test/files.lua
vendored
|
@ -867,8 +867,9 @@ if not _port then
|
||||||
-- {year=(1 << 31) + 1899, month=12, day=31, hour=23, min=59, sec=59}))
|
-- {year=(1 << 31) + 1899, month=12, day=31, hour=23, min=59, sec=59}))
|
||||||
|
|
||||||
-- this is too much
|
-- this is too much
|
||||||
checkerr("represented", os.time,
|
-- [jart] recent tz library upgrade seems to think it's ok
|
||||||
{year=(1 << 31) + 1899, month=12, day=31, hour=23, min=59, sec=60})
|
-- checkerr("represented", os.time,
|
||||||
|
-- {year=(1 << 31) + 1899, month=12, day=31, hour=23, min=59, sec=60})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- internal 'int' fields cannot hold these values
|
-- internal 'int' fields cannot hold these values
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue