24 #if !defined HAVE_CLOSEFROM && !defined __WIN32__    32 #ifdef HAVE_SYS_RESOURCE_H    33 # include <sys/types.h>    34 # include <sys/resource.h>    41 #elif defined __APPLE__    42 # include <sys/attr.h>    53     int maxfd = fcntl(0, F_MAXFD);
    54     if (maxfd >= 0) 
return maxfd;
    58     if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
    59         rl.rlim_max != RLIM_INFINITY) {
    60         return static_cast<int>(rl.rlim_max) - 1;
    63     return static_cast<int>(sysconf(_SC_OPEN_MAX)) - 1;
    91     if (fcntl(fd, F_CLOSEM, 0) >= 0)
    93 #elif defined HAVE_GETDIRENTRIES && defined __linux__    94     const char* path = 
"/proc/self/fd";
    95     int dir = 
open(path, O_RDONLY|O_DIRECTORY);
   104             ssize_t c = getdirentries(dir, buf, 
sizeof(buf), &base);
   114             for (ssize_t pos = 0; pos < c; pos += d->d_reclen) {
   116                 const char* leaf = d->
d_name;
   149                 while (
close(n) < 0 && errno == EINTR) { }
   154 #elif defined __APPLE__ // macOS   155     const char* path = 
"/dev/fd";
   157     typedef unsigned int gdea_type;
   159     typedef unsigned long gdea_type;
   161     int dir = 
open(path, O_RDONLY|O_DIRECTORY);
   164         struct attrlist alist;
   165         std::memset(&alist, 0, 
sizeof(alist));
   166         alist.bitmapcount = ATTR_BIT_MAP_COUNT;
   167         alist.commonattr = ATTR_CMN_NAME;
   176             gdea_type count = 
sizeof(buf);
   178             int r = getdirentriesattr(dir, &alist, buf, 
sizeof(buf),
   179                                       &count, &base, &new_state, 0);
   186             while (count-- > 0) {
   187                 const char* leaf = p + 
sizeof(u_int32_t);
   188                 p += *
static_cast<u_int32_t*
>(
static_cast<void*
>(p));
   205                 while (
close(n) < 0 && errno == EINTR) { }
   220     char path[6 + 
sizeof(pid_t) * 3 + 4];
   222     snprintf(path, 
sizeof(path), 
"/proc/%ld/fd", 
long(getpid()));
   223     path[
sizeof(path) - 1] = 
'\0';
   225     sprintf(path, 
"/proc/%ld/fd", 
long(getpid()));
   230     while (fd <= maxfd) {
   233         while (
close(fd) < 0 && errno == EINTR) { }
 
Parse signed and unsigned type from string and check for trailing characters. 
 
Cast a pointer we know is suitably aligned. 
 
Implementation of closefrom() function. 
 
WritableDatabase open()
Construct a WritableDatabase object for a new, empty InMemory database. 
 
include <dirent.h>, with alternative implementation for windows. 
 
std::enable_if< std::is_const< typename std::remove_pointer< U >::type >::value, T >::type alignment_cast(U ptr)
Cast a pointer we know is suitably aligned. 
 
bool parse_signed(const char *p, T &res)
 
<unistd.h>, but with compat. 
 
include <fcntl.h>, but working around broken platforms.