fix: make getcwd report truncated buffers as ERANGE
This commit is contained in:
@@ -165,10 +165,15 @@ namespace montauk::abi {
|
||||
if (proc == nullptr || buf == nullptr || maxLen == 0) return -1;
|
||||
|
||||
const char* cwd = proc->cwd[0] ? proc->cwd : "0:/";
|
||||
int i = 0;
|
||||
for (; i < (int)maxLen - 1 && cwd[i]; i++) buf[i] = cwd[i];
|
||||
buf[i] = '\0';
|
||||
return i;
|
||||
uint64_t cwdLen = 0;
|
||||
while (cwd[cwdLen] != '\0') cwdLen++;
|
||||
|
||||
// Reserve -1 for non-size failures so libc can distinguish them
|
||||
// from a buffer that can be retried with a larger allocation.
|
||||
if (maxLen <= cwdLen) return -2;
|
||||
|
||||
for (uint64_t i = 0; i <= cwdLen; i++) buf[i] = cwd[i];
|
||||
return (int)cwdLen;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
Reference in New Issue
Block a user