os.Chtimes bounds on time (32 and 64 bit file time)
42 views
Skip to first unread message
dsta...@gmail.com
unread,
Oct 30, 2015, 5:41:30 PM10/30/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
I'm using os.Chtimes to set the modified time on a file. I am currently bounding the time between time.Time(time.Unix(0,0)), and time.Time(time.Unix(0,1<<63-1)) inclusive.
This works fine on my environment, but on systems that use a 32 bit file time, this causes times above time.Time(time.Unix(0,1<<31-1)) to overflow and results in undefined behaviour.
Is it safe to use runtime.GOARCH and only use 64 bits if the GOARCH is amd64? Is there a better way?
Thanks,
Darren
Dave Cheney
unread,
Oct 30, 2015, 6:26:28 PM10/30/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Hello,
Could you show a small sample in the playground to demonstrate the issue? The playground happens to be a 32bit environment, which should help highlight the problem you are having.
Thanks
Dave
dsta...@gmail.com
unread,
Oct 30, 2015, 7:45:05 PM10/30/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
It doesn't seem to repro on the playground. I don't have a local repro either. I'll attempt to get one and try again.
Ian Lance Taylor
unread,
Oct 30, 2015, 8:05:26 PM10/30/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to dsta...@gmail.com, golang-nuts
Perhaps we should introduce a new function like syscall.NsecToTimespec
that checks for overflow and returns an error in that case. Then we
would have an actual error rather than doing something odd.
Not that that would help you much. It's safe to use GOARCH, except
that amd64 is not the only 64-bit GOARCH. You could perhaps use
something like unsafe.Sizeof(Timespec{}.Sec).