commit 12e51a077242e4860ce6ea4842fb3ca7369b0f97
parent 8b1ca348725ccecce1b95cf12170f54e8e54ea56
Author: Sebastian <sebastian@sebsite.pw>
Date: Tue, 5 Sep 2023 22:07:15 -0400
rt: don't add 1 to PATH_MAX
rt::PATH_MAX already accounts for the NUL terminator itself.
>From limits.h(0p):
> {PATH_MAX}
> Maximum number of bytes the implementation will store as a
> pathname in a user-supplied buffer of unspecified size,
> including the terminating null character.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/rt/+freebsd/syscalls.ha b/rt/+freebsd/syscalls.ha
@@ -13,7 +13,7 @@ fn syscall6(u64, u64, u64, u64, u64, u64, u64) u64;
export def PATH_MAX: size = 1024z;
export type path = (str | []u8 | *const u8);
-let pathbuf: [PATH_MAX + 1]u8 = [0...];
+let pathbuf: [PATH_MAX]u8 = [0...];
fn copy_kpath(path: path, buf: []u8) (*const u8 | errno) = {
let path = match (path) {
@@ -37,8 +37,8 @@ fn copy_kpath(path: path, buf: []u8) (*const u8 | errno) = {
return buf: *[*]u8: *const u8;
};
-// NUL terminates a string and stores it in a static buffer of PATH_MAX+1 bytes
-// in length.
+// NUL terminates a string and stores it in a static buffer of PATH_MAX bytes in
+// length.
fn kpath(path: path) (*const u8 | errno) = {
return copy_kpath(path, pathbuf);
};
@@ -113,7 +113,7 @@ export fn renameat(
newpath: str,
) (void | errno) = {
let oldpath = kpath(oldpath)?;
- static let newpathbuf: [PATH_MAX + 1]u8 = [0...];
+ static let newpathbuf: [PATH_MAX]u8 = [0...];
let newpath = copy_kpath(newpath, newpathbuf)?;
wrap_return(syscall4(SYS_renameat,
olddirfd: u64, oldpath: uintptr: u64,
@@ -222,10 +222,10 @@ export fn getdents(dirfd: int, buf: *opaque, nbytes: size) (size | errno) = {
// The return value is statically allocated and must be duplicated before
// calling getcwd again.
export fn getcwd() (*const u8 | errno) = {
- static let pathbuf: [PATH_MAX + 1]u8 = [0...];
+ static let pathbuf: [PATH_MAX]u8 = [0...];
wrap_return(syscall2(SYS___getcwd,
&pathbuf: *[*]u8: uintptr: u64,
- PATH_MAX + 1))?;
+ PATH_MAX))?;
return &pathbuf: *const u8;
};
diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha
@@ -16,7 +16,7 @@ fn syscall6(u64, u64, u64, u64, u64, u64, u64) u64;
export def PATH_MAX: size = 4096z;
export type path = (str | []u8 | *const u8);
-let pathbuf: [PATH_MAX + 1]u8 = [0...];
+let pathbuf: [PATH_MAX]u8 = [0...];
fn copy_kpath(path: path, buf: []u8) (*const u8 | errno) = {
let path = match (path) {
@@ -40,8 +40,8 @@ fn copy_kpath(path: path, buf: []u8) (*const u8 | errno) = {
return buf: *[*]u8: *const u8;
};
-// NUL terminates a string and stores it in a static buffer of PATH_MAX+1 bytes
-// in length.
+// NUL terminates a string and stores it in a static buffer of PATH_MAX bytes in
+// length.
fn kpath(path: path) (*const u8 | errno) = {
return copy_kpath(path, pathbuf);
};
@@ -115,7 +115,7 @@ export fn linkat(
flags: int,
) (void | errno) = {
let oldpath = kpath(oldpath)?;
- static let newpathbuf: [PATH_MAX + 1]u8 = [0...];
+ static let newpathbuf: [PATH_MAX]u8 = [0...];
let newpath = copy_kpath(newpath, newpathbuf)?;
wrap_return(syscall5(SYS_linkat,
olddirfd: u64, oldpath: uintptr: u64,
@@ -128,7 +128,7 @@ export fn symlinkat(
linkpath: path,
) (void | errno) = {
let target = kpath(target)?;
- static let linkpathbuf: [PATH_MAX + 1]u8 = [0...];
+ static let linkpathbuf: [PATH_MAX]u8 = [0...];
let linkpath = copy_kpath(linkpath, linkpathbuf)?;
wrap_return(syscall3(SYS_symlinkat, target: uintptr: u64,
newdirfd: u64, linkpath: uintptr: u64))?;
@@ -177,7 +177,7 @@ export fn renameat(
flags: uint,
) (void | errno) = {
let oldpath = kpath(oldpath)?;
- static let newpathbuf: [PATH_MAX + 1]u8 = [0...];
+ static let newpathbuf: [PATH_MAX]u8 = [0...];
let newpath = copy_kpath(newpath, newpathbuf)?;
wrap_return(syscall5(SYS_renameat2,
olddirfd: u64, oldpath: uintptr: u64,
@@ -447,10 +447,10 @@ export fn uname(uts: *utsname) (void | errno) = {
// The return value is statically allocated and must be duplicated before
// calling getcwd again.
export fn getcwd() (*const u8 | errno) = {
- static let pathbuf: [PATH_MAX + 1]u8 = [0...];
+ static let pathbuf: [PATH_MAX]u8 = [0...];
wrap_return(syscall2(SYS_getcwd,
&pathbuf: *[*]u8: uintptr: u64,
- PATH_MAX + 1))?;
+ PATH_MAX))?;
return &pathbuf: *const u8;
};