equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
107 |
107 |
108 private static FileTime toFileTime(long sec, long nsec) { |
108 private static FileTime toFileTime(long sec, long nsec) { |
109 if (nsec == 0) { |
109 if (nsec == 0) { |
110 return FileTime.from(sec, TimeUnit.SECONDS); |
110 return FileTime.from(sec, TimeUnit.SECONDS); |
111 } else { |
111 } else { |
112 // truncate to microseconds to avoid overflow with timestamps |
112 try { |
113 // way out into the future. We can re-visit this if FileTime |
113 long nanos = Math.addExact(nsec, |
114 // is updated to define a from(secs,nsecs) method. |
114 Math.multiplyExact(sec, 1_000_000_000L)); |
115 long micro = sec*1000000L + nsec/1000L; |
115 return FileTime.from(nanos, TimeUnit.NANOSECONDS); |
116 return FileTime.from(micro, TimeUnit.MICROSECONDS); |
116 } catch (ArithmeticException ignore) { |
|
117 // truncate to microseconds if nanoseconds overflow |
|
118 long micro = sec*1_000_000L + nsec/1_000L; |
|
119 return FileTime.from(micro, TimeUnit.MICROSECONDS); |
|
120 } |
117 } |
121 } |
118 } |
122 } |
119 |
123 |
120 FileTime ctime() { |
124 FileTime ctime() { |
121 return toFileTime(st_ctime_sec, st_ctime_nsec); |
125 return toFileTime(st_ctime_sec, st_ctime_nsec); |