Rewrite special file handling on Windows

This change gets GNU grep working. What caused it to not work, is it
wouldn't write to an output file descriptor when its dev/ino equaled
/dev/null's. So now we invent special dev/ino values for these files
This commit is contained in:
Justine Tunney 2023-10-14 01:06:00 -07:00
parent aca2261cda
commit 2db2f40a98
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
53 changed files with 485 additions and 299 deletions

View file

@ -20,15 +20,7 @@
#include "libc/intrin/atomic.h"
#include "libc/macros.internal.h"
#include "libc/nt/accounting.h"
static textwindows uint32_t __kmp32(const void *buf, size_t size) {
size_t i;
uint32_t h;
const uint32_t kPhiPrime = 0x9e3779b1;
const unsigned char *p = (const unsigned char *)buf;
for (h = i = 0; i < size; i++) h = (p[i] + h) * kPhiPrime;
return h;
}
#include "libc/str/str.h"
textwindows uint32_t sys_getuid_nt(void) {
char16_t buf[257];
@ -36,7 +28,7 @@ textwindows uint32_t sys_getuid_nt(void) {
uint32_t tmp, size = ARRAYLEN(buf);
if (!(tmp = atomic_load_explicit(&uid, memory_order_acquire))) {
GetUserName(&buf, &size);
tmp = __kmp32(buf, size >> 1) & 32767;
tmp = __fnv(buf, size >> 1) & 32767;
if (!tmp) ++tmp;
atomic_store_explicit(&uid, tmp, memory_order_release);
}