2015-04-03 21:24:09 +00:00
|
|
|
/* radare - LGPL - Copyright 2007-2015 - pancake */
|
2009-02-09 11:42:54 +00:00
|
|
|
|
|
|
|
#include "r_print.h"
|
2009-03-12 00:42:32 +00:00
|
|
|
#include "r_util.h"
|
|
|
|
#if 1
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2009-02-09 11:42:54 +00:00
|
|
|
|
2013-04-15 23:48:03 +00:00
|
|
|
R_API int r_print_date_dos(RPrint *p, ut8 *buf, int len) {
|
2009-07-08 11:49:55 +00:00
|
|
|
ut8 _time[2] = { buf[0], buf[1] };
|
|
|
|
ut8 _date[2] = { buf[2], buf[3] };
|
|
|
|
ut32 t = _time[1]<<8 | _time[0];
|
|
|
|
ut32 d = _date[1]<<8 | _date[0];
|
|
|
|
ut32 year = ((d&0xfe00)>>9)+1980;
|
|
|
|
ut32 month = (d&0x01e0)>>5;
|
|
|
|
ut32 day = (d&0x001f)>>0;
|
|
|
|
ut32 hour = (t&0xf800)>>11;
|
|
|
|
ut32 minutes = (t&0x07e0)>>5;
|
|
|
|
ut32 seconds = (t&0x001f)<<1;
|
2009-02-09 11:42:54 +00:00
|
|
|
|
2015-04-03 21:24:09 +00:00
|
|
|
// TODO: support p->datezone
|
|
|
|
// TODO: support p->datefmt
|
2009-02-09 11:42:54 +00:00
|
|
|
/* la data de modificacio del fitxer, no de creacio del zip */
|
2010-09-23 10:59:54 +00:00
|
|
|
p->printf("%d-%02d-%02d %d:%d:%d\n",
|
2009-02-09 11:42:54 +00:00
|
|
|
year, month, day, hour, minutes, seconds);
|
2009-03-12 00:42:32 +00:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2013-04-15 23:48:03 +00:00
|
|
|
R_API int r_print_date_unix(RPrint *p, const ut8 *buf, int len) {
|
2009-03-12 00:42:32 +00:00
|
|
|
time_t t;
|
2013-04-15 23:48:03 +00:00
|
|
|
char s[256];
|
|
|
|
int ret = 0;
|
2010-09-23 10:59:54 +00:00
|
|
|
const struct tm* time;
|
2009-03-12 00:42:32 +00:00
|
|
|
|
|
|
|
if (p != NULL && len >= sizeof(t)) {
|
2013-02-22 20:05:08 +00:00
|
|
|
r_mem_copyendian ((ut8*)&t, buf, sizeof(time_t), p->big_endian);
|
2009-03-12 00:42:32 +00:00
|
|
|
// "%d:%m:%Y %H:%M:%S %z",
|
2014-03-08 06:41:22 +00:00
|
|
|
if (p->datefmt[0]) {
|
2015-04-03 21:24:09 +00:00
|
|
|
t += p->datezone * (60*60);
|
2010-09-23 10:59:54 +00:00
|
|
|
time = (const struct tm*)gmtime((const time_t*)&t);
|
|
|
|
if (time) {
|
2013-04-15 23:48:03 +00:00
|
|
|
ret = strftime (s, sizeof (s), p->datefmt, time);
|
2010-09-23 10:59:54 +00:00
|
|
|
if (ret) {
|
2013-04-15 23:48:03 +00:00
|
|
|
p->printf ("%s\n", s);
|
|
|
|
ret = sizeof (time_t);
|
2010-09-23 10:59:54 +00:00
|
|
|
}
|
2010-10-17 21:03:54 +00:00
|
|
|
} else p->printf ("Invalid time\n");
|
2009-03-12 00:42:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2009-02-09 11:42:54 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 23:48:03 +00:00
|
|
|
R_API int r_print_date_get_now(RPrint *p, char *str) {
|
2009-03-12 00:42:32 +00:00
|
|
|
int ret = 0;
|
|
|
|
*str = 0;
|
2009-02-09 11:42:54 +00:00
|
|
|
#if __UNIX__
|
|
|
|
struct tm curt; /* current time */
|
|
|
|
time_t l;
|
2009-03-12 00:42:32 +00:00
|
|
|
char *week_str[7]= {
|
|
|
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
|
|
|
char *month_str[12]= {
|
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
2009-02-09 11:42:54 +00:00
|
|
|
|
|
|
|
l = time(0);
|
2009-03-12 00:42:32 +00:00
|
|
|
localtime_r (&l, &curt);
|
2015-04-03 21:24:09 +00:00
|
|
|
// XXX localtime is affected by the timezone.
|
2009-02-09 11:42:54 +00:00
|
|
|
|
2009-03-12 00:42:32 +00:00
|
|
|
if ((curt.tm_wday >= 0 && curt.tm_wday < 7)
|
|
|
|
&& (curt.tm_mon >= 0 && curt.tm_mon < 12)) {
|
2015-04-03 21:24:09 +00:00
|
|
|
sprintf (str, "%s, %02d %s %d %02d:%02d:%02d GMT + %d",
|
2009-03-12 00:42:32 +00:00
|
|
|
week_str[curt.tm_wday],
|
|
|
|
curt.tm_mday,
|
|
|
|
month_str[curt.tm_mon],
|
|
|
|
curt.tm_year + 1900, curt.tm_hour,
|
2015-04-04 00:11:08 +00:00
|
|
|
curt.tm_min, curt.tm_sec, curt.tm_isdst);
|
2009-03-12 00:42:32 +00:00
|
|
|
ret = sizeof(time_t);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#warning r_print_date_now NOT IMPLEMENTED FOR THIS PLATFORM
|
2009-02-09 11:42:54 +00:00
|
|
|
#endif
|
2009-03-12 00:42:32 +00:00
|
|
|
return ret;
|
2009-02-09 11:42:54 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 23:48:03 +00:00
|
|
|
R_API int r_print_date_w32(RPrint *p, const ut8 *buf, int len) {
|
2009-07-08 11:49:55 +00:00
|
|
|
ut64 l, L = 0x2b6109100LL;
|
2009-03-12 00:42:32 +00:00
|
|
|
time_t t;
|
|
|
|
int ret = 0;
|
|
|
|
char datestr[256];
|
2009-02-09 11:42:54 +00:00
|
|
|
|
2014-07-30 20:13:55 +00:00
|
|
|
if (p && len >= sizeof (ut64)) {
|
2013-02-22 20:05:08 +00:00
|
|
|
r_mem_copyendian ((ut8*)&l, buf, sizeof (ut64), p->big_endian);
|
2009-03-12 00:42:32 +00:00
|
|
|
l /= 10000000; // 100ns to s
|
|
|
|
l = (l > L ? l-L : 0); // isValidUnixTime?
|
|
|
|
t = (time_t) l; // TODO limit above!
|
|
|
|
// "%d:%m:%Y %H:%M:%S %z",
|
2014-07-28 16:12:18 +00:00
|
|
|
if (p->datefmt[0]) {
|
2009-09-25 02:04:51 +00:00
|
|
|
ret = strftime(datestr, 256, p->datefmt,
|
2009-03-12 00:42:32 +00:00
|
|
|
(const struct tm*) gmtime((const time_t*)&t));
|
|
|
|
if (ret) {
|
|
|
|
p->printf("%s\n", datestr);
|
|
|
|
ret = R_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-09 11:42:54 +00:00
|
|
|
|
2009-03-12 00:42:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|