SDL_ttf: build: Compile with large inode number support where possible

From 52c1aa3913f95c86e67ddffe4c28ed81d7a4305a Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Thu, 26 May 2022 15:11:23 +0100
Subject: [PATCH] build: Compile with large inode number support where possible

On filesystems with large inode numbers, such as overlayfs, attempting
to stat() a file on a 32-bit system using legacy syscalls can fail
with EOVERFLOW. If we opt-in to more modern "large file support"
syscalls, then source code references to functions like stat() are
transparently replaced with ABIs that support large file sizes and
inode numbers, such as stat64().

In general, SDL_ttf delegates its file I/O to SDL, so it is unaffected
by this issue. However, if we build with the vendored libraries, they
use libc functions like stat(), subjecting them to the EOVERFLOW problem.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 CMakeLists.txt | 8 ++++++++
 configure.ac   | 1 +
 2 files changed, 9 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cf67f6e..05d9f48 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -82,6 +82,7 @@ endif()
 include(CMakeDependentOption)
 include(CMakePackageConfigHelpers)
 include(GNUInstallDirs)
+include(CheckSymbolExists)
 
 option(VENDORED_DEFAULT "Default value for *_VENDORED options. Can be overridden for each library. Is only used in the first configure run." ON)
 
@@ -104,6 +105,13 @@ else()
     set(sdl2_ttf_install_name_infix static)
 endif()
 
+# Enable large file support on 32-bit glibc, so that the vendored libraries
+# can access files with large inode numbers
+check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC)
+if (LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4)
+    add_compile_definitions(PRIVATE _FILE_OFFSET_BITS=64)
+endif()
+
 add_library(SDL2_ttf
     SDL_ttf.c
     SDL_ttf.h
diff --git a/configure.ac b/configure.ac
index 364c385..983a1cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -66,6 +66,7 @@ dnl Check for tools
 AC_PROG_CC
 AC_PROG_CXX
 AC_CHECK_TOOL(RC,[windres],[:])
+AC_SYS_LARGEFILE
 AC_PROG_INSTALL
 AC_PROG_MAKE_SET