From edea4dbcd3bdb23b8920ecce5e920fa487dcd3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 28 Aug 2024 10:55:26 +0200 Subject: [PATCH] Fix "too many open files" on MacOS Patch borrowed from https://github.com/sass/libsass/pull/3183 by @tom-un See See https://github.com/gohugoio/hugo/issues/12649 --- libsass_src/src/file.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libsass_src/src/file.cpp b/libsass_src/src/file.cpp index 163abd4..0b87137 100644 --- a/libsass_src/src/file.cpp +++ b/libsass_src/src/file.cpp @@ -12,6 +12,7 @@ # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) #else # include +# include #endif #include #include @@ -469,6 +470,20 @@ namespace Sass { CloseHandle(hFile); // just convert from unsigned char* char* contents = (char*) pBuffer; + #elif __APPLE__ + // On OSX `fopen` can fail with "too many open files" but succeeds using `open`. + struct stat st; + if (stat(path.c_str(), &st) == -1 || S_ISDIR(st.st_mode)) return 0; + int file = open(path.c_str(), O_RDONLY); + char* contents = 0; + if (file != -1) { + size_t size = st.st_size; + contents = (char*) malloc((size+2)*sizeof(char)); + read(file, contents, size); + contents[size+0] = '\0'; + contents[size+1] = '\0'; + close(file); + } #else // Read the file using `` instead of `` for better portability. // The `` header initializes `` and this buggy in GCC4/5 with static linking.