authorgravatar for gereeter+code@gmail.comJonathan S <gereeter+code@gmail.com> 2020-03-28 00:33:12-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-29 18:27:39-04:00
logc209da1589f50dee9e961f64cb389d0b4e485aba
treee8a34da5d0822d19cc0e5391497f3558c16b71e6
parent0674b51453d5631f400936b4da7c74788f745e90

Document the failure to improve selfExe{,Dir}PathAlloc


1 files changed, 14 insertions(+), 4 deletions(-)

lib/std/fs.zig+14-4
...@@ -1800,8 +1800,13 @@ pub const SelfExePathError = os.ReadLinkError || os.SysCtlError;...@@ -1800,8 +1800,13 @@ pub const SelfExePathError = os.ReadLinkError || os.SysCtlError;
1800/// `selfExePath` except allocates the result on the heap.1800/// `selfExePath` except allocates the result on the heap.
1801/// Caller owns returned memory.1801/// Caller owns returned memory.
1802pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 {1802pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 {
1803 // TODO(#4812): Consider looping with larger and larger buffers to handle1803 // Use of MAX_PATH_BYTES here is justified as, at least on one tested Linux
1804 // overlong paths.1804 // system, readlink will completely fail to return a result larger than
1805 // PATH_MAX even if given a sufficiently large buffer. This makes it
1806 // fundamentally impossible to get the selfExePath of a program running in
1807 // a very deeply nested directory chain in this way.
1808 // TODO(#4812): Investigate other systems and whether it is possible to get
1809 // this path by trying larger and larger buffers until one succeeds.
1805 var buf: [MAX_PATH_BYTES]u8 = undefined;1810 var buf: [MAX_PATH_BYTES]u8 = undefined;
1806 return mem.dupe(allocator, u8, try selfExePath(&buf));1811 return mem.dupe(allocator, u8, try selfExePath(&buf));
1807}1812}
...@@ -1858,8 +1863,13 @@ pub fn selfExePathW() [:0]const u16 {...@@ -1858,8 +1863,13 @@ pub fn selfExePathW() [:0]const u16 {
1858/// `selfExeDirPath` except allocates the result on the heap.1863/// `selfExeDirPath` except allocates the result on the heap.
1859/// Caller owns returned memory.1864/// Caller owns returned memory.
1860pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 {1865pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 {
1861 // TODO(#4812): Consider looping with larger and larger buffers to handle1866 // Use of MAX_PATH_BYTES here is justified as, at least on one tested Linux
1862 // overlong paths.1867 // system, readlink will completely fail to return a result larger than
1868 // PATH_MAX even if given a sufficiently large buffer. This makes it
1869 // fundamentally impossible to get the selfExeDirPath of a program running
1870 // in a very deeply nested directory chain in this way.
1871 // TODO(#4812): Investigate other systems and whether it is possible to get
1872 // this path by trying larger and larger buffers until one succeeds.
1863 var buf: [MAX_PATH_BYTES]u8 = undefined;1873 var buf: [MAX_PATH_BYTES]u8 = undefined;
1864 return mem.dupe(allocator, u8, try selfExeDirPath(&buf));1874 return mem.dupe(allocator, u8, try selfExeDirPath(&buf));
1865}1875}