Strerror maps error numbers to strings. Additionally, a utility for
mapping errors to strings was added so that it could be reused for
perror and similar.
Details
- Reviewers
sivachandra lntue - Commits
- rG42bcb35c0f29: [libc] add strerror
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/src/__support/error_to_string.h | ||
---|---|---|
2 | Almost everything in this file should live in a .cpp file. The only thing declared in the .h file should something like: cpp::string_view error_to_string(int error); IMO, that single function should take care of unknown error numbers also. Do you have a use case where max_buff_size and get_unknown_str are required? A more fundamental question - is there any reason why this should live in __support at all? |
libc/src/__support/error_to_string.h | ||
---|---|---|
2 | I did make a .cpp file to contain the functions for the class, but was running into compile errors where the linker couldn't find the implementations, so I moved it into the header for now. As for the other parts: I placed this in support because both strerror which is in strings.h and perror which is in stdio.h use the same functionality. I can move it into strings, but generally I try to avoid including files between headers when possible. |
libc/src/__support/error_to_string.h | ||
---|---|---|
2 |
That shouldn't happen - we have lots of examples where in we store tables in .cpp files, especially in the math directory.
My question was more about, why should, say the strerror implementation, provide its own error buffer. Instead, why can't all these details be hidden behind a single error_to_string. Also, since errno is a thread local value, the error string buffer should also be thread local.
SGTM |
avoid global array of global pointers
moved implementation details into internal namespace
libc/src/__support/error_to_string.cpp | ||
---|---|---|
28 | Add a comment somewhere explaining why this is present at all. | |
230 | Can we use https://github.com/llvm/llvm-project/blob/main/libc/src/__support/CPP/stringstream.h to simply this? |
libc/src/__support/error_to_string.cpp | ||
---|---|---|
226 | There is no point making this method a constexpr and introducing the const_convert (that would in a way be an antipattern) method - the argument err_num is not going to be a constexpr so this function is always evaluated at runtime. |
Almost everything in this file should live in a .cpp file. The only thing declared in the .h file should something like:
IMO, that single function should take care of unknown error numbers also. Do you have a use case where max_buff_size and get_unknown_str are required?
A more fundamental question - is there any reason why this should live in __support at all?