Re: gmtime_r bug in High Sierra?
Re: gmtime_r bug in High Sierra?
- Subject: Re: gmtime_r bug in High Sierra?
- From: Thomas Tempelmann <email@hidden>
- Date: Sun, 10 Sep 2017 09:08:53 +0200
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
_______________________________________________
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