aa1713ed7bcb1b52032542f990363316cd7b1364
hiram
  Wed May 20 11:21:58 2026 -0700
Mac OSX does not have posix_fallocate() function

diff --git src/hg/lib/trackDbCache.c src/hg/lib/trackDbCache.c
index 6a08f6bfd2f..abf717e0d1c 100644
--- src/hg/lib/trackDbCache.c
+++ src/hg/lib/trackDbCache.c
@@ -338,31 +338,38 @@
 
 int fd = open(tempFileName, oflags, 0666 );
 if (fd < 0)
     {
     cacheLog("unable to open shared memory %s errno %d", tempFileName, errno);
     mustRemove(tempFileName);
     return;
     }
 else
     {
     cacheLog("open shared memory %s", tempFileName);
     }
 ftruncate(fd, 0);
 // Reserve real tmpfs pages now so writes through the mmap below can't SIGBUS
 // when /dev/shm is full (ftruncate alone leaves the file sparse).
+#ifdef __APPLE__
+    #include <fcntl.h>
+    fstore_t store = {F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, size, 0};
+    fcntl(fd, F_PREALLOCATE, &store);
+    int err = ftruncate(fd, size);
+#else
     int err = posix_fallocate(fd, 0, size);
+#endif
 if (err != 0)
     {
     fprintf(stderr, "trackDbCache: posix_fallocate of %ld bytes in %s failed (%s); skipping cache write\n",
             size, trackDbCacheDir, strerror(err));
     cacheLog("unable to allocate %ld bytes for trackDb cache, errno %d", size, err);
     close(fd);
     mustRemove(tempFileName);
     return;
     }
 
 size_t psize = getpagesize();
 unsigned long pageMask = psize - 1;
 unsigned long paddress = 0;
 
 unsigned char *mem;