Implement init/deinit of inotify system
Use RAII to handle inotify resource lifetime, i.e. initialize with actor creation and deinitialize with actor deletion.
This commit is contained in:
19
Sources/Inotify/InotifyError.swift
Normal file
19
Sources/Inotify/InotifyError.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
import CInotify
|
||||
|
||||
public enum InotifyError: Error, Sendable, CustomStringConvertible {
|
||||
case initFailed(errno: Int32)
|
||||
|
||||
public var description: String {
|
||||
switch self {
|
||||
case .initFailed(let code):
|
||||
"inotify_init1 failed: \(readableErrno(code))"
|
||||
}
|
||||
}
|
||||
|
||||
private func readableErrno(_ code: Int32) -> String {
|
||||
if let cStr = get_error_message() {
|
||||
return String(cString: cStr) + " (errno \(code))"
|
||||
}
|
||||
return "errno \(code)"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user