Re: gmtime_r bug in High Sierra?
Re: gmtime_r bug in High Sierra?
- Subject: Re: gmtime_r bug in High Sierra?
- From: Stephane Sudre <email@hidden>
- Date: Sun, 10 Sep 2017 16:32:04 +0200
\o/
Adding __attribute__((packed)); seems to fix the issue in my executable.
Thanks for the solution. I've never used the getattrlist before, so
finding the origin of the issue could have taken me days (I was
thinking that the problem could also be with the value set during the
creation of the file).
I shall probably file 4 bug reports (and close the one on gmtime_r)
since in High Sierra b9:
(1) xar -cf creates a toc with apparently random FinderCreateTime values.
(2) pkgutil --flatten creates a toc with FinderCreateTime values set
to Epoch times.
(3) productbuild --component creates a toc with apparently random
FinderCreateTime values.
(4) the latest public source code of xar does not set the packed __attribute__
(1), (2) and (3) are probably related to (4) as these 3 tools are
linked directly or indirectly to libxar.
On Sun, Sep 10, 2017 at 9:08 AM, Thomas Tempelmann <email@hidden> wrote:
> On Sun, Sep 10, 2017 at 8:13 AM, Stephane Sudre <email@hidden>
> wrote:
>
>> So now, it looks like the problem is earlier in the code and it comes
>> from the value returned by getattrlist(2).
>>
>> If I run the code (*) for a file on a HFS+ volume, the value looks
>> correct.
>> If I run the code for a file on a APFS volume, the value looks incorrect.
>
>
> I just made a quick test app from the xar code you mentioned. One thing to
> keep in mind is to use a "pack" instruction with the attribute struct
> returned by getattrlist. With this code, it works on both 10.13 and 10.12.6,
> on APFS and HFS, correctly:
>
> #include <unistd.h>
> #include <time.h>
> #include <string.h>
> #include <stdio.h>
> #include <sys/attr.h>
>
> int main(int argc, const char * argv[])
> {
> if (argc < 2) {
> fprintf(stderr, "Must provide a file path\n");
> } else {
> const char *path = argv[1];
> struct fits {
> uint32_t length;
> struct timespec ts;
> } __attribute__((packed));
> struct fits fts;
> struct attrlist attrs;
> memset(&attrs, 0, sizeof(attrs));
> attrs.bitmapcount = ATTR_BIT_MAP_COUNT;
> attrs.commonattr = ATTR_CMN_CRTIME;
> int ret = getattrlist(path, &attrs, &fts, sizeof(fts), 0);
> if (ret) {
> perror(argv[0]);
> } else {
> char tmpc[64];
> struct tm tm;
> gmtime_r(&fts.ts.tv_sec, &tm);
> strftime(tmpc, sizeof(tmpc), "%FT%T", &tm);
> printf("crtime: %s and %ld ns\n",tmpc, fts.ts.tv_nsec);
> }
> }
> return 0;
> }
>
> So, based on this, there's no bug in the API. If you find a specific case
> where this still doesn't work for you, please let us know.
>
> Thomas
>
--
Packaging Resources - http://s.sudre.free.fr/Packaging.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden