[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#810975: 4store: FTBFS on arm64, kfreebsd-any: stat.h:76:21: error: field 'st_atim' has incomplete type



tags 810975 + patch
thanks

Hi,

Andreas Beckmann wrote:
> gcc -DHAVE_CONFIG_H -I. -I../..   -D_FORTIFY_SOURCE=2 -std=gnu99 -fno-strict-aliasing -Wall  -g -O2 -I./ -I../ -DGIT_REV="\"v1.1.6+20151109\"" -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -I/usr/include/raptor2 -I/usr/include/rasqal -I/usr/include/raptor2 -I/usr/include/libxml2 `pcre-config --cflags` -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall -c -o filter-datatypes.o filter-datatypes.c
> In file included from /usr/include/fcntl.h:68:0,
>                  from ../common/params.h:4,
>                  from query-datatypes.h:8,
>                  from filter.h:4,
>                  from filter-datatypes.c:28:
> /usr/include/aarch64-linux-gnu/bits/stat.h:76:21: error: field 'st_atim' has incomplete type
>      struct timespec st_atim;  /* Time of last access.  */
>                      ^
> /usr/include/aarch64-linux-gnu/bits/stat.h:77:21: error: field 'st_mtim' has incomplete type
>      struct timespec st_mtim;  /* Time of last modification.  */
>                      ^
> /usr/include/aarch64-linux-gnu/bits/stat.h:78:21: error: field 'st_ctim' has incomplete type
>      struct timespec st_ctim;  /* Time of last status change.  */
>                      ^

What's going wrong here is, filter-datatypes.c includes <time.h>
and at that time, __need_timespec is not defined:

    #define _XOPEN_SOURCE
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    #define __USE_MISC
    #include <time.h>

Later, when <fcntl.h> is included:

    #if defined __USE_XOPEN || defined __USE_XOPEN2K8
    # define __need_timespec
    # include <time.h>
    # include <bits/stat.h>

time.h was included already, and it has guard macros that stop it being
included again.  Therefore, it doesn't reach the part that would declare
timespec.

I think the _XOPEN_SOURCE isn't quite right.  I think they were trying
to get <string.h> to provide strdup(), but it's not working:

> filter-datatypes.c: In function 'fs_resource_value':
> filter-datatypes.c:107:16: warning: implicit declaration of function 'strdup' [-Wimplicit-function-declaration]
>      res->lex = strdup(v.lex);
>                 ^
> filter-datatypes.c:107:16: warning: incompatible implicit declaration of built-in function 'strdup'

And __USE_MISC to get strptime() and timegm() from <time.h>, but that's
forbidden in feature_test_macros(7):

    Programs should never define these macros directly: instead, the
    appropriate feature test macro(s) from the list above should be
    employed.

One solution would be:

    #define _DEFAULT_SOURCE /* for timegm() */
    #define _XOPEN_SOURCE /* for strptime(), strdup() */

but with glibc >= 2.19 it is easier to define _GNU_SOURCE, which implies
both of those, and would be consistent with other source files of 4store
already doing that.

Patch is attached.  It eliminates the warning and fixes the build for me
on at least kfreebsd-amd64.

Thanks!
Regards,
-- 
Steven Chamberlain
steven@pyro.eu.org
Subject: use _GNU_SOURCE instead of __USE_MISC
From: Steven Chamberlain <steven@pyro.eu.org>
Date: Sun, 28 Feb 2016 19:39:34 +0000

Defining __USE_MISC directly is forbidden in feature_test_macros(7).

Use _GNU_SOURCE, as other source files do already, which implies
_XOPEN_SOURCE and __USE_MISC.

--- a/src/frontend/filter-datatypes.c
+++ b/src/frontend/filter-datatypes.c
@@ -18,11 +18,11 @@
  *  Copyright (C) 2006 Steve Harris for Garlik
  */
 
-#define _XOPEN_SOURCE
+#define _GNU_SOURCE
+
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#define __USE_MISC
 #include <time.h>
 
 #include "filter.h"

Attachment: signature.asc
Description: Digital signature


Reply to: