+2012-05-15 13:12 Christos Zoulas <christos@zoulas.com>
+
+ * use ctime_r, asctime_r
+
2012-04-06 17:18 Christos Zoulas <christos@zoulas.com>
* Fixes for indirect offsets to handle apple disk formats
AC_CHECK_FUNCS(mmap strerror strndup strtoul mbrtowc mkstemp utimes utime wcwidth strtof fork)
dnl Provide implementation of some required functions if necessary
-AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline)
+AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r)
dnl Checks for libraries
AC_CHECK_LIB(z,gzopen)
--- /dev/null
+/* $File: asctime_r.c,v 1.1 2012/05/15 17:14:36 christos Exp $ */
+
+#include "file.h"
+#ifndef lint
+FILE_RCSID("@(#)$File: asctime_r.c,v 1.1 2012/05/15 17:14:36 christos Exp $")
+#endif /* lint */
+#include <time.h>
+#include <string.h>
+
+/* asctime_r is not thread-safe anyway */
+char *
+asctime_r(const struct tm *t, char *dst)
+{
+ char *p = asctime(t);
+ if (p == NULL)
+ return NULL;
+ memcpy(dst, p, 26);
+ return dst;
+}
uint16_t cdf_tole2(uint16_t);
uint32_t cdf_tole4(uint32_t);
uint64_t cdf_tole8(uint64_t);
-char *cdf_ctime(const time_t *);
+char *cdf_ctime(const time_t *, char *);
#ifdef CDF_DEBUG
void cdf_dump_header(const cdf_header_t *);
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: cdf_time.c,v 1.11 2011/12/13 13:48:41 christos Exp $")
+FILE_RCSID("@(#)$File: cdf_time.c,v 1.12 2012/05/15 17:14:36 christos Exp $")
#endif
#include <time.h>
}
char *
-cdf_ctime(const time_t *sec)
+cdf_ctime(const time_t *sec, char *buf)
{
- static char ctbuf[26];
- char *ptr = ctime(sec);
+ char *ptr = ctime_r(sec, buf);
if (ptr != NULL)
- return ptr;
- (void)snprintf(ctbuf, sizeof(ctbuf), "*Bad* 0x%16.16llx\n",
- (long long)*sec);
- return ctbuf;
+ return buf;
+ (void)snprintf(buf, 26, "*Bad* 0x%16.16llx\n", (long long)*sec);
+ return buf;
}
main(int argc, char *argv[])
{
struct timespec ts;
+ char buf[25];
static const cdf_timestamp_t tst = 0x01A5E403C2D59C00ULL;
static const char *ref = "Sat Apr 23 01:30:00 1977";
char *p, *q;
cdf_timestamp_to_timespec(&ts, tst);
- p = cdf_ctime(&ts.tv_sec);
+ p = cdf_ctime(&ts.tv_sec, buf);
if ((q = strchr(p, '\n')) != NULL)
*q = '\0';
if (strcmp(ref, p) != 0)
--- /dev/null
+/* $File: ctime_r.c,v 1.1 2012/05/15 17:14:36 christos Exp $ */
+
+#include "file.h"
+#ifndef lint
+FILE_RCSID("@(#)$File: ctime_r.c,v 1.1 2012/05/15 17:14:36 christos Exp $")
+#endif /* lint */
+#include <time.h>
+#include <string.h>
+
+/* ctime_r is not thread-safe anyway */
+char *
+ctime_r(const time_t *t, char *dst)
+{
+ char *p = ctime(t);
+ if (p == NULL)
+ return NULL;
+ memcpy(dst, p, 26);
+ return dst;
+}
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.136 2012/04/03 22:25:07 christos Exp $
+ * @(#)$File: file.h,v 1.137 2012/05/15 17:14:36 christos Exp $
*/
#ifndef __file_h__
#include <inttypes.h>
#endif
#include <regex.h>
+#include <time.h>
#include <sys/types.h>
#include <sys/param.h>
/* Do this here and now, because struct stat gets re-defined on solaris */
struct stat;
#define FILE_T_LOCAL 1
#define FILE_T_WINDOWS 2
-protected const char *file_fmttime(uint64_t, int);
+protected const char *file_fmttime(uint64_t, int, char *);
protected int file_buffer(struct magic_set *, int, const char *, const void *,
size_t);
protected int file_fsmagic(struct magic_set *, const char *, struct stat *);
ssize_t getline(char **dst, size_t *len, FILE *fp);
ssize_t getdelim(char **dst, size_t *len, int delimiter, FILE *fp);
#endif
+#ifndef HAVE_CTIME_R
+char *ctime_r(const time_t *, char *);
+#endif
+#ifndef HAVE_ASCTIME_R
+char *asctime_r(const struct tm *, char *);
+#endif
#if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
#define QUICK
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: print.c,v 1.73 2012/05/07 18:23:11 christos Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.74 2012/05/15 17:14:36 christos Exp $")
#endif /* lint */
#include <string.h>
protected void
file_mdump(struct magic *m)
{
- private const char optyp[] = { FILE_OPS };
+ static const char optyp[] = { FILE_OPS };
+ char tbuf[26];
(void) fprintf(stderr, "%u: %.*s %u", m->lineno,
(m->cont_level & 7) + 1, ">>>>>>>>", m->offset);
case FILE_BEDATE:
case FILE_MEDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.l, FILE_T_LOCAL));
+ file_fmttime(m->value.l, FILE_T_LOCAL, tbuf));
break;
case FILE_LDATE:
case FILE_LELDATE:
case FILE_BELDATE:
case FILE_MELDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.l, 0));
+ file_fmttime(m->value.l, 0, tbuf));
case FILE_QDATE:
case FILE_LEQDATE:
case FILE_BEQDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.q, FILE_T_LOCAL));
+ file_fmttime(m->value.q, FILE_T_LOCAL, tbuf));
break;
case FILE_QLDATE:
case FILE_LEQLDATE:
case FILE_BEQLDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.q, 0));
+ file_fmttime(m->value.q, 0, tbuf));
break;
case FILE_QWDATE:
case FILE_LEQWDATE:
case FILE_BEQWDATE:
(void)fprintf(stderr, "%s,",
- file_fmttime(m->value.q, FILE_T_WINDOWS));
+ file_fmttime(m->value.q, FILE_T_WINDOWS, tbuf));
break;
case FILE_FLOAT:
case FILE_BEFLOAT:
}
protected const char *
-file_fmttime(uint64_t v, int flags)
+file_fmttime(uint64_t v, int flags, char *buf)
{
char *pp;
time_t t = (time_t)v;
}
if (flags & FILE_T_LOCAL) {
- pp = ctime(&t);
+ pp = ctime_r(&t, buf);
} else {
#ifndef HAVE_DAYLIGHT
private int daylight = 0;
tm = gmtime(&t);
if (tm == NULL)
goto out;
- pp = asctime(tm);
+ pp = asctime_r(tm, buf);
}
if (pp == NULL)
pp[strcspn(pp, "\n")] = '\0';
return pp;
out:
- return "*Invalid time*";
+ return strcpy(buf, "*Invalid time*");
}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.30 2012/03/03 15:44:58 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.31 2012/05/15 17:14:36 christos Exp $")
#endif
#include <stdlib.h>
case CDF_FILETIME:
tp = info[i].pi_tp;
if (tp != 0) {
+ char tbuf[64];
if (tp < 1000000000000000LL) {
- char tbuf[64];
cdf_print_elapsed_time(tbuf,
sizeof(tbuf), tp);
if (NOTMIME(ms) && file_printf(ms,
} else {
char *c, *ec;
cdf_timestamp_to_timespec(&ts, tp);
- c = cdf_ctime(&ts.tv_sec);
+ c = cdf_ctime(&ts.tv_sec, tbuf);
if ((ec = strchr(c, '\n')) != NULL)
*ec = '\0';
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.149 2012/04/06 21:15:54 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.150 2012/05/15 17:14:36 christos Exp $")
#endif /* lint */
#include "magic.h"
float vf;
double vd;
int64_t t = 0;
- char buf[128];
+ char buf[128], tbuf[26];
union VALUETYPE *p = &ms->ms_value;
switch (m->type) {
case FILE_BEDATE:
case FILE_LEDATE:
case FILE_MEDATE:
- if (file_printf(ms, m->desc, file_fmttime(p->l,
- FILE_T_LOCAL)) == -1)
+ if (file_printf(ms, m->desc, file_fmttime(p->l, FILE_T_LOCAL,
+ tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint32_t);
break;
case FILE_BELDATE:
case FILE_LELDATE:
case FILE_MELDATE:
- if (file_printf(ms, m->desc, file_fmttime(p->l, 0)) == -1)
+ if (file_printf(ms, m->desc, file_fmttime(p->l, 0, tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint32_t);
break;
case FILE_QDATE:
case FILE_BEQDATE:
case FILE_LEQDATE:
- if (file_printf(ms, m->desc, file_fmttime(p->q,
- FILE_T_LOCAL)) == -1)
+ if (file_printf(ms, m->desc, file_fmttime(p->q, FILE_T_LOCAL,
+ tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
case FILE_QLDATE:
case FILE_BEQLDATE:
case FILE_LEQLDATE:
- if (file_printf(ms, m->desc, file_fmttime(p->q, 0)) == -1)
+ if (file_printf(ms, m->desc, file_fmttime(p->q, 0, tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
case FILE_QWDATE:
case FILE_BEQWDATE:
case FILE_LEQWDATE:
- if (file_printf(ms, m->desc, file_fmttime(p->q,
- FILE_T_WINDOWS)) == -1)
+ if (file_printf(ms, m->desc, file_fmttime(p->q, FILE_T_WINDOWS,
+ tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;