coreutils/date.c with FEATURE_DATE_NANO=y broken?

Douglas Mencken dougmencken at gmail.com
Sun Jun 6 09:01:42 UTC 2010


On Sun, Jun 6, 2010 at 1:57 AM, Denys Vlasenko <vda.linux at googlemail.com> wrote:
>
> I did not yet research what set of magic #defines makes it work on glibc
> *and* on uclibc. The code as it stands now builds on uclibc for me.

Well, I did actually build it for uclibc (not gnu std c lib). But yes,
when building for gnu library it errors the same:

coreutils/date.c: In function 'date_main':
coreutils/date.c:207:23: error: 'struct stat' has no member named 'st_mtimensec'
make[1]: *** [coreutils/date.o] Error 1

"CONFIG_STATIC=y" build on uclibc system: the same error.

> Just disable this option for now, or, if you have time/desire to do so,
> research it yourself an send a patch which makes it work on glibc
> and does not break build on uclibc at the same time.

Well, 'st_mtimensec' comes from
${uclibc_src_tree}/libc/sysdeps/linux/${arch}/bits/stat.h, for example

#ifdef __USE_MISC
    /* Nanosecond resolution timestamps are stored in a format
       equivalent to 'struct timespec'.  This is the type used
       whenever possible but the Unix namespace rules do not allow the
       identifier 'timespec' to appear in the <sys/stat.h> header.
       Therefore we have to handle the use of this header in strictly
       standard-compliant sources special.  */
    struct timespec st_atim;            /* Time of last access.  */
    struct timespec st_mtim;            /* Time of last modification.  */
    struct timespec st_ctim;            /* Time of last status change.  */
# define st_atime st_atim.tv_sec        /* Backward compatibility.  */
# define st_mtime st_mtim.tv_sec
# define st_ctime st_ctim.tv_sec
#else
    __time_t st_atime;                  /* Time of last access.  */
    unsigned long int st_atimensec;     /* Nscecs of last access.  */
    __time_t st_mtime;                  /* Time of last modification.  */
    unsigned long int st_mtimensec;     /* Nsecs of last modification.  */
    __time_t st_ctime;                  /* Time of last status change.  */
    unsigned long int st_ctimensec;     /* Nsecs of last status change.  */
#endif

So if __USE_MISC is defined by ${uclibc_src_tree}/include/features.h :

#if defined _BSD_SOURCE || defined _SVID_SOURCE
# define __USE_MISC     1
#endif

then there will be no 'mtimensec' field in stat structure. Changing
the line inside ${bbox_src_tree}/coreutils/date.c with 'ts.tv_nsec =
statbuf.st_mtimensec' to 'ts.tv_nsec = statbuf.st_atim.tv_nsec' works
in the case when __USE_MISC is defined.

Patch (also attached):

~/build-farm # diff -u old-bbox-coreutils-date.c new-bbox-coreutils-date.c
--- old-bbox-coreutils-date.c
+++ new-bbox-coreutils-date.c
@@ -204,7 +204,11 @@
                xstat(filename, &statbuf);
                ts.tv_sec = statbuf.st_mtime;
 #if ENABLE_FEATURE_DATE_NANO
-               ts.tv_nsec = statbuf.st_mtimensec; //or st_atim.tv_nsec?
+# ifdef __USE_MISC
+               ts.tv_nsec = statbuf.st_atim.tv_nsec;
+# else
+               ts.tv_nsec = statbuf.st_mtimensec;
+# endif
 #endif
        } else {
 #if ENABLE_FEATURE_DATE_NANO

I don't have any system without __USE_MISC, so I can't test the second
case (which seems to work for you). But for me, it solves this build
problem, and I hope it would be compatible with your case.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: the_diff
Type: application/octet-stream
Size: 398 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20100606/81c15990/attachment.obj>


More information about the busybox mailing list