mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 10:18:31 +00:00
Share file offset across execve() on Windows
This is a breaking change. It defines the new environment variable named _COSMO_FDS_V2 which is used for inheriting non-stdio file descriptors on execve() or posix_spawn(). No effort has been spent thus far integrating with the older variable. If a new binary launches the older ones or vice versa they'll only be able to pass stdin / stdout / stderr to each other therefore it's important that you upgrade all your cosmo binaries if you depend on this functionality. You'll be glad you did because inheritance of file descriptors is more aligned with the POSIX standard than before.
This commit is contained in:
parent
761c6ad615
commit
3f26dfbb31
29 changed files with 572 additions and 249 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
#include "libc/intrin/fds.h"
|
||||
#include "libc/nt/enum/filetype.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/struct/byhandlefileinformation.h"
|
||||
|
@ -31,7 +32,7 @@ static textwindows int64_t GetPosition(struct Fd *f, int whence) {
|
|||
case SEEK_SET:
|
||||
return 0;
|
||||
case SEEK_CUR:
|
||||
return f->shared->pointer;
|
||||
return f->cursor->shared->pointer;
|
||||
case SEEK_END: {
|
||||
struct NtByHandleFileInformation wst;
|
||||
if (!GetFileInformationByHandle(f->handle, &wst)) {
|
||||
|
@ -69,12 +70,12 @@ textwindows int64_t sys_lseek_nt(int fd, int64_t offset, int whence) {
|
|||
int filetype = GetFileType(f->handle);
|
||||
if (filetype != kNtFileTypePipe && //
|
||||
filetype != kNtFileTypeChar && //
|
||||
f->shared) {
|
||||
f->cursor->shared) {
|
||||
int64_t res;
|
||||
__fd_lock(f);
|
||||
__cursor_lock(f->cursor);
|
||||
if ((res = Seek(f, offset, whence)) != -1)
|
||||
f->shared->pointer = res;
|
||||
__fd_unlock(f);
|
||||
f->cursor->shared->pointer = res;
|
||||
__cursor_unlock(f->cursor);
|
||||
return res;
|
||||
} else {
|
||||
return espipe();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue