| 4034 | #if defined(__FreeBSD__) |
| 4035 | |
| 4036 | int CPLGetRemainingFileDescriptorCount() |
| 4037 | { |
| 4038 | struct rlimit limitNumberOfFilesPerProcess; |
| 4039 | if (getrlimit(RLIMIT_NOFILE, &limitNumberOfFilesPerProcess) != 0) |
| 4040 | { |
| 4041 | return -1; |
| 4042 | } |
| 4043 | const int maxNumberOfFilesPerProcess = |
| 4044 | static_cast<int>(limitNumberOfFilesPerProcess.rlim_cur); |
| 4045 | |
| 4046 | const pid_t pid = getpid(); |
| 4047 | int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_FILEDESC, |
| 4048 | static_cast<int>(pid)}; |
| 4049 | |
| 4050 | size_t len = 0; |
| 4051 | |
| 4052 | if (sysctl(mib, 4, nullptr, &len, nullptr, 0) == -1) |
| 4053 | { |
| 4054 | return -1; |
| 4055 | } |
| 4056 | |
| 4057 | return maxNumberOfFilesPerProcess - |
| 4058 | static_cast<int>(len / sizeof(struct kinfo_file)); |
| 4059 | } |
| 4060 | |
| 4061 | #else |
| 4062 | |