Describe the errno an error stores, not the current one
The description looked up the message of whatever errno was set when the description was built, so an error printed later read "Success (errno 28)".
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <sys/inotify.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
static inline int cinotify_deinit(int fd) {
|
||||
return close(fd);
|
||||
@@ -14,12 +15,8 @@ static inline int cinotify_get_errno(void) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
static inline char* get_error_message() {
|
||||
int error_number = errno;
|
||||
errno = 0;
|
||||
char* error_message = strerror(error_number);
|
||||
if (errno > 0) return NULL;
|
||||
return error_message;
|
||||
static inline char* cinotify_error_message(int error_number) {
|
||||
return strerror(error_number);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,9 +17,7 @@ public enum InotifyError: Error, Sendable, CustomStringConvertible {
|
||||
}
|
||||
|
||||
private func readableErrno(_ code: Int32) -> String {
|
||||
if let cStr = get_error_message() {
|
||||
return String(cString: cStr) + " (errno \(code))"
|
||||
}
|
||||
return "errno \(code)"
|
||||
guard let message = cinotify_error_message(code) else { return "errno \(code)" }
|
||||
return String(cString: message) + " (errno \(code))"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user