1From 455341880f52b4df3b30490db1c17eb65110c00c Mon Sep 17 00:00:00 2001
2From: Alyssa Ross <hi@alyssa.is>
3Date: Wed, 29 May 2024 10:29:02 +0200
4Subject: [PATCH] Stop using transitional LFS64 APIs
5
6The *64 APIs were intended for transitional use, and have been removed
7in musl 1.2.4. Nowadays, the best practice is to set
8_FILE_OFFSET_BITS=64 across the board, making all the unsuffixed APIs
9will be 64-bit. This fixes building with recent versions of musl, and
10avoids the need to remember to use the *64 variants every time to
11properly handle large files on 32-bit platforms.
12
13Test: build with musl 1.2.4.
14Change-Id: I7fa7a3ae4aa19a765740f5b2af916fd6f0ed0b32
15---
16
17diff --git a/CMakeLists.txt b/CMakeLists.txt
18index 4de86a4..10c402a 100644
19--- a/CMakeLists.txt
20+++ b/CMakeLists.txt
21@@ -69,7 +69,7 @@
22 add_subdirectory(build-config/${AEMU_COMMON_BUILD_CONFIG})
23 endif()
24
25-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extern-c-compat -Wno-return-type-c-linkage")
26+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extern-c-compat -Wno-return-type-c-linkage -D_FILE_OFFSET_BITS=64")
27
28 add_subdirectory(base)
29 add_subdirectory(snapshot)
30diff --git a/snapshot/TextureLoader.cpp b/snapshot/TextureLoader.cpp
31index 31e02e8..5c21134 100644
32--- a/snapshot/TextureLoader.cpp
33+++ b/snapshot/TextureLoader.cpp
34@@ -46,7 +46,7 @@
35 void TextureLoader::loadTexture(uint32_t texId, const loader_t& loader) {
36 android::base::AutoLock scopedLock(mLock);
37 assert(mIndex.count(texId));
38- HANDLE_EINTR(fseeko64(mStream.get(), mIndex[texId], SEEK_SET));
39+ HANDLE_EINTR(fseeko(mStream.get(), mIndex[texId], SEEK_SET));
40 switch (mVersion) {
41 case 1:
42 loader(&mStream);
43@@ -71,7 +71,7 @@
44 mDiskSize = size;
45 }
46 auto indexPos = mStream.getBe64();
47- HANDLE_EINTR(fseeko64(mStream.get(), static_cast<int64_t>(indexPos), SEEK_SET));
48+ HANDLE_EINTR(fseeko(mStream.get(), static_cast<int64_t>(indexPos), SEEK_SET));
49 mVersion = mStream.getBe32();
50 if (mVersion < 1 || mVersion > 2) {
51 return false;
52diff --git a/snapshot/TextureSaver.cpp b/snapshot/TextureSaver.cpp
53index 537626b..c8854e9 100644
54--- a/snapshot/TextureSaver.cpp
55+++ b/snapshot/TextureSaver.cpp
56@@ -50,7 +50,7 @@
57 [texId](FileIndex::Texture& tex) {
58 return tex.texId == texId;
59 }));
60- mIndex.textures.push_back({texId, ftello64(mStream.get())});
61+ mIndex.textures.push_back({texId, ftello(mStream.get())});
62
63 CompressingStream stream(mStream);
64 saver(&stream, &mBuffer);
65@@ -60,7 +60,7 @@
66 if (mFinished) {
67 return;
68 }
69- mIndex.startPosInFile = ftello64(mStream.get());
70+ mIndex.startPosInFile = ftello(mStream.get());
71 writeIndex();
72 mEndTime = base::getHighResTimeUs();
73 #if SNAPSHOT_PROFILE > 1
74@@ -74,7 +74,7 @@
75
76 void TextureSaver::writeIndex() {
77 #if SNAPSHOT_PROFILE > 1
78- auto start = ftello64(mStream.get());
79+ auto start = ftello(mStream.get());
80 #endif
81
82 mStream.putBe32(static_cast<uint32_t>(mIndex.version));
83@@ -83,13 +83,13 @@
84 mStream.putBe32(b.texId);
85 mStream.putBe64(static_cast<uint64_t>(b.filePos));
86 }
87- auto end = ftello64(mStream.get());
88+ auto end = ftello(mStream.get());
89 mDiskSize = uint64_t(end);
90 #if SNAPSHOT_PROFILE > 1
91 printf("texture: index size: %d\n", int(end - start));
92 #endif
93
94- fseeko64(mStream.get(), 0, SEEK_SET);
95+ fseeko(mStream.get(), 0, SEEK_SET);
96 mStream.putBe64(static_cast<uint64_t>(mIndex.startPosInFile));
97 }
98