Skip to content

Commit fc62ae7

Browse files
committed
Fix off_t ambiguity
Depending on the build system architecture, off_t may be a 32-bit or 64-bit value. We can just use 64-bit on 32-bit as well.
1 parent 5b0eac7 commit fc62ae7

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

include/zsclient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace zsync2 {
5555
// set fileSize to size of remote file in bytes
5656
// returns true if the value is available (i.e., the update has started and the value can be read from the
5757
// .zsync file), false otherwise
58-
bool remoteFileSize(off_t& fileSize);
58+
bool remoteFileSize(long long& fileSize);
5959

6060
// set path in which the .zsync file should be stored when downloaded first
6161
void storeZSyncFileInPath(const std::string& path);

src/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ function(add_libzsync2 NAME BUILD_TYPE)
4747

4848
# largefile support à la gpgme
4949
# libzsync uses off_t everywhere, this allows us to support files larger than 2GiB
50-
# must(!) be public definitions, otherwise integrating libzsync2 elsewhere (e.g., AppImageUpdate) may lead to
51-
# compiler errors because the off_t definitions differ
50+
# our public APIs do not use off_t but long long to avoid this ambiguity
5251
target_compile_definitions("${NAME}"
53-
PUBLIC -D_FILE_OFFSET_BITS=64
54-
PUBLIC -DLARGEFILE_SOURCE
52+
PRIVATE -D_FILE_OFFSET_BITS=64
53+
PRIVATE -DLARGEFILE_SOURCE
5554
)
5655
endfunction()
5756

src/zsclient.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace zsync2 {
5858

5959
std::string cwd;
6060

61-
off_t remoteFileSizeCache;
61+
long long remoteFileSizeCache;
6262

6363
unsigned long rangesOptimizationThreshold;
6464

@@ -1058,12 +1058,12 @@ namespace zsync2 {
10581058
return true;
10591059
}
10601060

1061-
bool remoteFileSize(off_t& fileSize) {
1061+
bool remoteFileSize(long long& fileSize) {
10621062
if (remoteFileSizeCache < 0) {
10631063
if (zsHandle == nullptr)
10641064
return false;
10651065

1066-
remoteFileSizeCache = zsync_filelen(zsHandle);
1066+
remoteFileSizeCache = static_cast<long long>(zsync_filelen(zsHandle));
10671067
}
10681068

10691069
if (remoteFileSizeCache < 0)
@@ -1134,7 +1134,7 @@ namespace zsync2 {
11341134
return d->setCwd(path);
11351135
}
11361136

1137-
bool ZSyncClient::remoteFileSize(off_t& fileSize) {
1137+
bool ZSyncClient::remoteFileSize(long long& fileSize) {
11381138
return d->remoteFileSize(fileSize);
11391139
}
11401140

0 commit comments

Comments
 (0)