Files
swift-inotify/Sources/Inotify/Inotify.swift
T. R. Bernstein 098339f9d1 Implement init/deinit of inotify system
Use RAII to handle inotify resource lifetime, i.e. initialize with actor
creation and deinitialize with actor deletion.
2026-03-11 17:50:17 +01:00

17 lines
287 B
Swift

import CInotify
public actor Inotify {
private let fd: Int32
public init() throws {
self.fd = inotify_init1(Int32(IN_NONBLOCK | IN_CLOEXEC))
guard self.fd >= 0 else {
throw InotifyError.initFailed(errno: cinotify_get_errno())
}
}
deinit {
cinotify_deinit(self.fd)
}
}