Skip to content

Commit 74c98de

Browse files
committed
Fix large file system support
libupnp uses large file support (if available). If a program linking to libupnp does not however it creates mismatches in callframes. See Issue pupnp#51 for the results. This simplifies LFS support by using AC_SYS_LARGEFILE_SENSITIVE instead of manually defining _LARGE_FILE_SOURCE and _FILE_OFFSET_BITS (which is useless on architectures where the size of off_t is fixed). Furthermore additional logic is introduced to catch a library user without 64 bit wide off_t on such a platform. upnp.h also makes use of off_t, but as this file includes FileInfo.h, the latter is the single right place for this check. This fixes pupnp#52 which is a generalized variant of pupnp#51.
1 parent 6584d88 commit 74c98de

4 files changed

Lines changed: 90 additions & 17 deletions

File tree

configure.ac

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,11 @@ AC_CANONICAL_HOST
405405
# installed libraries.
406406
#
407407
AC_CONFIG_HEADERS([autoconfig.h upnp/inc/upnpconfig.h])
408-
#AC_SYS_LARGEFILE_SENSITIVE
408+
AX_SYS_LARGEFILE_SENSITIVE
409+
410+
if test "x$ac_cv_sys_largefile_sensitive" = "xyes"; then
411+
AC_DEFINE([UPNP_LARGEFILE_SENSITIVE], 1, [whether the system defaults to 32bit off_t but can do 64bit when requested])
412+
fi
409413

410414
AC_REVISION([$Revision: 1.11 $])
411415

@@ -596,13 +600,7 @@ AX_CFLAGS_WARN_ALL
596600
echo "-------------------------------------------------------------------------------"
597601

598602

599-
#
600-
# Lot's of stuff to ensure large file support
601-
#
602603
AC_TYPE_SIZE_T
603-
AC_TYPE_OFF_T
604-
AC_DEFINE([_LARGE_FILE_SOURCE], [], [Large files support])
605-
AC_DEFINE([_FILE_OFFSET_BITS], [64], [File Offset size])
606604

607605

608606
#

m4/ax_sys_largefile_sensitive.m4

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# ===============================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_sys_largefile_sensitive.html
3+
# ===============================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_SYS_LARGEFILE_SENSITIVE
8+
#
9+
# DESCRIPTION
10+
#
11+
# Check whether the current system is sensitive to -Ddefines making off_t
12+
# having different types/sizes. Automatically define a config.h symbol
13+
# LARGEFILE_SENSITIVE if that is the case, otherwise leave everything as
14+
# is.
15+
#
16+
# This macro builds on top of AC_SYS_LARGEFILE to detect whether special
17+
# options are neede to make the code use 64bit off_t - in many setups this
18+
# will also make the code use 64bit off_t immediatly.
19+
#
20+
# The common use of a LARGEFILE_SENSITIVE config.h-define is to rename
21+
# exported functions, usually adding a 64 to the original function name.
22+
# Such renamings are only needed on systems being both (a) 32bit off_t by
23+
# default and (b) implementing large.file extensions (as for unix98).
24+
#
25+
# a renaming section could look like this:
26+
#
27+
# #if defined LARGEFILE_SENSITIVE && _FILE_OFFSET_BITS+0 == 64
28+
# #define zzip_open zzip_open64
29+
# #define zzip_seek zzip_seek64
30+
# #endif
31+
#
32+
# for libraries, it is best to take advantage of the prefix-config.h
33+
# macro, otherwise you want to export a renamed LARGEFILE_SENSITIVE in an
34+
# installed header file. -> see AX_PREFIX_CONFIG_H
35+
#
36+
# LICENSE
37+
#
38+
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
39+
#
40+
# This program is free software; you can redistribute it and/or modify it
41+
# under the terms of the GNU General Public License as published by the
42+
# Free Software Foundation; either version 3 of the License, or (at your
43+
# option) any later version.
44+
#
45+
# This program is distributed in the hope that it will be useful, but
46+
# WITHOUT ANY WARRANTY; without even the implied warranty of
47+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
48+
# Public License for more details.
49+
#
50+
# You should have received a copy of the GNU General Public License along
51+
# with this program. If not, see <https://www.gnu.org/licenses/>.
52+
#
53+
# As a special exception, the respective Autoconf Macro's copyright owner
54+
# gives unlimited permission to copy, distribute and modify the configure
55+
# scripts that are the output of Autoconf when processing the Macro. You
56+
# need not follow the terms of the GNU General Public License when using
57+
# or distributing such scripts, even though portions of the text of the
58+
# Macro appear in them. The GNU General Public License (GPL) does govern
59+
# all other use of the material that constitutes the Autoconf Macro.
60+
#
61+
# This special exception to the GPL applies to versions of the Autoconf
62+
# Macro released by the Autoconf Archive. When you make and distribute a
63+
# modified version of the Autoconf Macro, you may extend this special
64+
# exception to the GPL to apply to your modified version as well.
65+
66+
#serial 7
67+
68+
AU_ALIAS([AC_SYS_LARGEFILE_SENSITIVE], [AX_SYS_LARGEFILE_SENSITIVE])
69+
AC_DEFUN([AX_SYS_LARGEFILE_SENSITIVE],[dnl
70+
AC_REQUIRE([AC_SYS_LARGEFILE])dnl
71+
# we know about some internals of ac_sys_largefile here...
72+
AC_MSG_CHECKING(whether system differentiates 64bit off_t by defines)
73+
ac_cv_sys_largefile_sensitive="no"
74+
if test ".${ac_cv_sys_file_offset_bits-no}${ac_cv_sys_large_files-no}" != ".nono"
75+
then ac_cv_sys_largefile_sensitive="yes"
76+
AC_DEFINE(LARGEFILE_SENSITIVE, 1,
77+
[whether the system defaults to 32bit off_t but can do 64bit when requested])
78+
fi
79+
AC_MSG_RESULT([$ac_cv_sys_largefile_sensitive])
80+
])

upnp/inc/FileInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include <sys/types.h> /* for off_t */
1919
#include <time.h> /* for time_t */
2020

21+
#if defined UPNP_LARGEFILE_SENSITIVE && _FILE_OFFSET_BITS+0 != 64
22+
#error libupnp uses large file support, so users must do that, too
23+
#endif
24+
2125
#define CLASS UpnpFileInfo
2226

2327
#define EXPAND_CLASS_MEMBERS(CLASS) \

upnp/inc/upnpconfig.h.in

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,11 @@
5454
#define UPNP_VERSION \
5555
((UPNP_VERSION_MAJOR * 100 + UPNP_VERSION_MINOR) * 100 + UPNP_VERSION_PATCH)
5656

57-
58-
5957
/***************************************************************************
6058
* Large file support
6159
***************************************************************************/
6260

63-
/** File Offset size */
64-
#undef _FILE_OFFSET_BITS
65-
66-
/** Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
67-
#undef _LARGEFILE_SOURCE
68-
69-
/** Large files support */
70-
#undef _LARGE_FILE_SOURCE
61+
#undef UPNP_LARGEFILE_SENSITIVE
7162

7263
/***************************************************************************
7364
* Library optional features

0 commit comments

Comments
 (0)