Permalink
Browse files

make the utimes timevals an array of two longs instead of just one lo…

…ng -- to

accomodate 64 bit time_ts for both seconds and usecs. this also allows null
timeval args, in which case we can let utimes get the current time
  • Loading branch information...
1 parent 3dbf78b commit a9df130ab614deec5a3f35d66b902aa8d9878b8a @pjenvey pjenvey committed Dec 15, 2008
@@ -205,10 +205,13 @@ public int umask(int mask) {
return libc.umask(mask);
}
- public int utimes(String path, long atime, long mtime) {
- Timeval[] times = ((Timeval[])new DefaultNativeTimeval().toArray(2));
- times[0].setMicroseconds(atime);
- times[1].setMicroseconds(mtime);
+ public int utimes(String path, long[] atimeval, long[] mtimeval) {
+ Timeval[] times = null;
+ if (atimeval != null && mtimeval != null) {
+ times = ((Timeval[])new DefaultNativeTimeval().toArray(2));
+ times[0].setTime(atimeval);
+ times[1].setTime(mtimeval);
+ }
return libc.utimes(path, times);
}
@@ -8,8 +8,9 @@
public DefaultNativeTimeval() {}
- public void setMicroseconds(long time) {
- tv_sec.setValue(time / 1000);
- tv_usec.setValue(time % 1000);
+ public void setTime(long[] timeval) {
+ assert timeval.length == 2;
+ tv_sec.setValue(timeval[0]);
+ tv_usec.setValue(timeval[1]);
}
}
@@ -216,8 +216,15 @@ public int umask(int mask) {
return 0;
}
- public int utimes(String path, long atime, long mtime) {
- new File(path).setLastModified(mtime);
+ public int utimes(String path, long[] atimeval, long[] mtimeval) {
+ long mtimeMillis;
+ if (mtimeval != null) {
+ assert mtimeval.length == 2;
+ mtimeMillis = (mtimeval[0] * 1000) + (mtimeval[1] / 1000);
+ } else {
+ mtimeMillis = System.currentTimeMillis();
+ }
+ new File(path).setLastModified(mtimeMillis);
return 0;
}
@@ -54,7 +54,7 @@
public FileStat stat(String path);
public int symlink(String oldpath,String newpath);
public int umask(int mask);
- public int utimes(String path, long atime, long mtime);
+ public int utimes(String path, long[] atimeval, long[] mtimeval);
public int waitpid(int pid, int[] status, int flags);
public int wait(int[] status);
}
@@ -1,5 +1,5 @@
package org.jruby.ext.posix;
public interface Timeval {
- public void setMicroseconds(long time);
+ public void setTime(long[] timeval);
}
@@ -6,8 +6,8 @@
public long actime;
public long modtime;
- public UTimBuf64(long atime, long mtime) {
- actime = atime / 1000;
- modtime = mtime / 1000;
+ public UTimBuf64(long actime, long modtime) {
+ this.actime = actime;
+ this.modtime = modtime;
}
}
@@ -148,8 +148,11 @@ public String readlink(String oldpath) {
}
@Override
- public int utimes(String path, long atime, long mtime) {
- UTimBuf64 times = new UTimBuf64(atime, mtime);
+ public int utimes(String path, long[] atimeval, long[] mtimeval) {
+ UTimBuf64 times = null;
+ if (atimeval != null && mtimeval != null) {
+ times = new UTimBuf64(atimeval[0], mtimeval[0]);
+ }
return ((WindowsLibC)libc)._utime64(path, times);
}

0 comments on commit a9df130

Please sign in to comment.