66// 
77// ===----------------------------------------------------------------------===//
88
9+ #include  " hdr/errno_macros.h" 
910#include  " src/__support/CPP/array.h" 
10- #include  " src/__support/CPP/optional.h" 
1111#include  " src/__support/CPP/string_view.h" 
12- #include  " src/__support/libc_errno .h" 
12+ #include  " src/__support/error_or .h" 
1313#include  " src/__support/macros/config.h" 
1414#include  " src/string/memory_utils/inline_memcpy.h" 
1515
16- //  TODO: clean this up.
17- //   1. Change from optional to ErrorOr, and return the errno instead of setting
18- //     it here.
19- //   2. Replace inline memcpy with __builtin_memcpy
20- 
2116//  TODO: Get PATH_MAX via https://github.com/llvm/llvm-project/issues/85121
2217#include  < linux/limits.h> 
2318
@@ -28,24 +23,18 @@ namespace shm_common {
2823LIBC_INLINE_VAR constexpr  cpp::string_view SHM_PREFIX = " /dev/shm/" 
2924using  SHMPath = cpp::array<char , NAME_MAX + SHM_PREFIX.size() + 1 >;
3025
31- LIBC_INLINE cpp::optional <SHMPath> translate_name (cpp::string_view name) {
26+ LIBC_INLINE ErrorOr <SHMPath> translate_name (cpp::string_view name) {
3227  //  trim leading slashes
3328  size_t  offset = name.find_first_not_of (' /' 
34-   if  (offset == cpp::string_view::npos) {
35-     libc_errno = EINVAL;
36-     return  cpp::nullopt ;
37-   }
29+   if  (offset == cpp::string_view::npos)
30+     return  Error (EINVAL);
3831  name = name.substr (offset);
3932
4033  //  check the name
41-   if  (name.size () > NAME_MAX) {
42-     libc_errno = ENAMETOOLONG;
43-     return  cpp::nullopt ;
44-   }
45-   if  (name == " ." " .." contains (' /' 
46-     libc_errno = EINVAL;
47-     return  cpp::nullopt ;
48-   }
34+   if  (name.size () > NAME_MAX)
35+     return  Error (ENAMETOOLONG);
36+   if  (name == " ." " .." contains (' /' 
37+     return  Error (EINVAL);
4938
5039  //  prepend the prefix
5140  SHMPath buffer;
0 commit comments