mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Share file offset across processes
This change ensures that if a file descriptor for an open disk file gets shared by multiple processes within a process tree, then lseek() changes will be visible across processes, and read() / write() are synchronized. Note this only applies to Windows, because UNIX kernels already do this.
This commit is contained in:
parent
a80ab3f8fe
commit
761c6ad615
15 changed files with 256 additions and 63 deletions
|
@ -31,7 +31,7 @@ static textwindows int64_t GetPosition(struct Fd *f, int whence) {
|
|||
case SEEK_SET:
|
||||
return 0;
|
||||
case SEEK_CUR:
|
||||
return f->pointer;
|
||||
return f->shared->pointer;
|
||||
case SEEK_END: {
|
||||
struct NtByHandleFileInformation wst;
|
||||
if (!GetFileInformationByHandle(f->handle, &wst)) {
|
||||
|
@ -67,11 +67,14 @@ textwindows int64_t sys_lseek_nt(int fd, int64_t offset, int whence) {
|
|||
} else if (__isfdkind(fd, kFdFile)) {
|
||||
struct Fd *f = g_fds.p + fd;
|
||||
int filetype = GetFileType(f->handle);
|
||||
if (filetype != kNtFileTypePipe && filetype != kNtFileTypeChar) {
|
||||
if (filetype != kNtFileTypePipe && //
|
||||
filetype != kNtFileTypeChar && //
|
||||
f->shared) {
|
||||
int64_t res;
|
||||
if ((res = Seek(f, offset, whence)) != -1) {
|
||||
f->pointer = res;
|
||||
}
|
||||
__fd_lock(f);
|
||||
if ((res = Seek(f, offset, whence)) != -1)
|
||||
f->shared->pointer = res;
|
||||
__fd_unlock(f);
|
||||
return res;
|
||||
} else {
|
||||
return espipe();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue