6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
+ #include " hdr/errno_macros.h"
9
10
#include " src/__support/CPP/array.h"
10
- #include " src/__support/CPP/optional.h"
11
11
#include " src/__support/CPP/string_view.h"
12
- #include " src/__support/libc_errno .h"
12
+ #include " src/__support/error_or .h"
13
13
#include " src/__support/macros/config.h"
14
14
#include " src/string/memory_utils/inline_memcpy.h"
15
15
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
-
21
16
// TODO: Get PATH_MAX via https://github.com/llvm/llvm-project/issues/85121
22
17
#include < linux/limits.h>
23
18
@@ -28,24 +23,18 @@ namespace shm_common {
28
23
LIBC_INLINE_VAR constexpr cpp::string_view SHM_PREFIX = " /dev/shm/" ;
29
24
using SHMPath = cpp::array<char , NAME_MAX + SHM_PREFIX.size() + 1 >;
30
25
31
- LIBC_INLINE cpp::optional <SHMPath> translate_name (cpp::string_view name) {
26
+ LIBC_INLINE ErrorOr <SHMPath> translate_name (cpp::string_view name) {
32
27
// trim leading slashes
33
28
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);
38
31
name = name.substr (offset);
39
32
40
33
// check the name
41
- if (name.size () > NAME_MAX) {
42
- libc_errno = ENAMETOOLONG;
43
- return cpp::nullopt ;
44
- }
45
- if (name == " ." || name == " .." || name.contains (' /' )) {
46
- libc_errno = EINVAL;
47
- return cpp::nullopt ;
48
- }
34
+ if (name.size () > NAME_MAX)
35
+ return Error (ENAMETOOLONG);
36
+ if (name == " ." || name == " .." || name.contains (' /' ))
37
+ return Error (EINVAL);
49
38
50
39
// prepend the prefix
51
40
SHMPath buffer;
0 commit comments