On Thu, Jan 17, 2019 at 03:24:41PM +0100, Branko Čibej wrote:
> On 17.01.2019 13:28, Stefan Sperling wrote:
> > On Thu, Jan 10, 2019 at 01:17:40AM +0100, Branko Čibej wrote:
> >> I get that part, my question was related to APR's configure setting the
> >> type of apr_off_t and its format specifier correctly on Linux but
> >> incorrectly on OpenBSD, even though they're equivalent.
> > It seems to be wrong on Linux as well.
> >
> > This is on a Debian 8.11 / amd64 system:
> >
> > $ cat test.c
> > #include <stdio.h>
> > #include <sys/types.h>
> > #include <apr-1.0/apr.h>
> > int main()
> > {
> >         printf("sizeof(off_t)=%zd\n", sizeof(off_t));
> >         printf("sizeof(long)=%zd\n", sizeof(long));
> >         printf("sizeof(long long)=%zd\n", sizeof(long long));
> >         printf("APR_OFF_T_FMT=" APR_OFF_T_FMT "\n");
> >         return 0;
> > }
> > $ cc -o test test.c
> > $ ./test 
> > sizeof(off_t)=8
> > sizeof(long)=8
> > sizeof(long long)=8
> > APR_OFF_T_FMT=ld
> 
> That doesn't tell me anything .... the question is, what is the typedef
> for apr_off_t on linux? if it's 'long' there but 'long long' on OpenBSD,
> then *something* is being done specially there.
> 
> FWIW: All these types (apr_off_t, apr_size_t, apr_ssize_t) should be set
> to their OS/ABI underlying types where those are available. But they're
> not as far as I know.

You are right. The definition seems to be fine on Linux.

>From apr.h on that system:

typedef  size_t          apr_size_t;
typedef  ssize_t         apr_ssize_t;
typedef  off_t           apr_off_t;

So apr_off_t is off_t, which per above test program is 8 bytes long.

If I followed the maze of header files correctly it boils down to 'long int':

unistd.h:
# ifndef __off_t_defined
#  ifndef __USE_FILE_OFFSET64
typedef __off_t off_t;
#  else
typedef __off64_t off_t;
#  endif

x86_64-linux-gnu/bits/typesizes.h:
#define __OFF_T_TYPE            __SYSCALL_SLONG_TYPE
# define __SYSCALL_SLONG_TYPE   __SLONGWORD_TYPE

x86_64-linux-gnu/bits/types.h
#define __SLONGWORD_TYPE        long int

Note that these definitions differ for the 32 bit emulation ABI where
off_t instead boils down to 'long long int', via the _quad_t type.
I suppose a 32 bit APR library running on 64 bit would require "lld",
and this should work because APR's configure script should see
sizeof(long) == 4 in this case.

Whereas on OpenBSD, off_t is a 'long long' on all platforms, and
there is no 32 bit emulation which could change sizes of such types.

I would appreciate if someone could commit my configure.in patch
which adds overrides for OpenBSD specifically. That would fix my
immediate problem. And perhaps a better fix could be devised later?

Reply via email to