summaryrefslogtreecommitdiff
path: root/sys/src/cmd/aquarela/smbtime.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/aquarela/smbtime.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/aquarela/smbtime.c')
-rwxr-xr-xsys/src/cmd/aquarela/smbtime.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/sys/src/cmd/aquarela/smbtime.c b/sys/src/cmd/aquarela/smbtime.c
new file mode 100755
index 000000000..3627a795b
--- /dev/null
+++ b/sys/src/cmd/aquarela/smbtime.c
@@ -0,0 +1,63 @@
+#include "headers.h"
+
+void
+smbplan9time2datetime(ulong time, int tzoff, ushort *datep, ushort *timep)
+{
+ Tm *tm;
+ if (tzoff < 0)
+ time -= (ulong)-tzoff;
+ else
+ time += tzoff;
+ tm = gmtime(time);
+ *datep = (tm->mday) | ((tm->mon + 1) << 5) | ((tm->year - 80) << 9);
+ *timep = (tm->sec >> 1) | (tm->min << 5) | (tm->hour << 11);
+}
+
+ulong
+smbdatetime2plan9time(ushort date, ushort time, int tzoff)
+{
+ Tm tm;
+ strcpy(tm.zone, "GMT");
+ tm.mday = date & 0x1f;
+ tm.mon = ((date >> 5) & 0xf) - 1;
+ tm.year = (date >> 9) + 80;
+ tm.yday = 0;
+ tm.sec = (time & 0x1f) << 1;
+ tm.min = (time >> 5) & 0x3f;
+ tm.hour = time >> 11;
+ smblogprint(-1, "smbdatetime2plan9time: converting %d/%d/%d %d:%d:%d\n",
+ tm.year + 1900, tm.mon + 1, tm.mday, tm.hour, tm.min, tm.sec);
+ return tm2sec(&tm) - tzoff;
+}
+
+vlong
+smbplan9time2time(ulong time)
+{
+ return ((vlong)time + 11644473600LL) * 10000000;
+}
+
+ulong
+smbtime2plan9time(vlong nttime)
+{
+ return (nttime / 10000000 - 11644473600LL);
+}
+
+ulong
+smbplan9time2utime(ulong time, int tzoff)
+{
+ if (tzoff < 0)
+ time -= (ulong)-tzoff;
+ else
+ time += tzoff;
+ return time;
+}
+
+ulong
+smbutime2plan9time(ulong utime, int tzoff)
+{
+ if (tzoff < 0)
+ utime += (ulong)-tzoff;
+ else
+ utime -= tzoff;
+ return utime;
+}