robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
05d7040425
master
1-- OS/process utils. 2 3local M ={} 4 5--- Counts (approximate) open file descriptors for this process. Works on Linux/macOS/BSD. 6---@return integer? # Number of open fds, or nil if `/dev/fd` failed (fds exhausted, or unavailable/Windows). 7function M . count_open_fds () 8local n =0 9for _ , _ , err in vim . fs . dir ( '/dev/fd' , { err =true } ) do 10-- If `/dev/fd` scan failed (e.g. EMFILE when fds exhausted), count would be misleading. 11if err then 12return nil 13end 14n =n + 1 15end 16-- Discount the scan's own descriptor. 17return math . max ( 0 , n - 1 ) 18end 19 20return M