+2006-08-08 Hrvoje Niksic <hniksic@xemacs.org>
+
+ * utils.c (datetime_str): Avoid code repetition with time_str.
+
2006-07-21 Hrvoje Niksic <hniksic@xemacs.org>
* init.c (commands): Correctly place "contentdisposition".
cookie->path,
cookie->permanent ? "permanent" : "session",
cookie->secure ? "secure" : "insecure",
- cookie->expiry_time ? datetime_str (&exptime) : "none",
+ cookie->expiry_time ? datetime_str (exptime) : "none",
cookie->attr, cookie->value));
}
}
}
fputs ("# HTTP cookie file.\n", fp);
- fprintf (fp, "# Generated by Wget on %s.\n", datetime_str (&cookies_now));
+ fprintf (fp, "# Generated by Wget on %s.\n", datetime_str (cookies_now));
fputs ("# Edit at your own risk.\n\n", fp);
for (hash_table_iterate (jar->chains, &iter);
#endif
#include <assert.h>
#include <errno.h>
+#include <time.h>
#include "wget.h"
#include "utils.h"
expected_bytes ? expected_bytes - restval : 0,
restval, &rd_size, len, &con->dltime, flags);
- tms = time_str (NULL);
+ tms = time_str (time (NULL));
tmrate = retr_rate (rd_size, con->dltime);
total_download_time += con->dltime;
restval = 0;
/* Get the current time string. */
- tms = time_str (NULL);
+ tms = time_str (time (NULL));
/* Print fetch message, if opt.verbose. */
if (opt.verbose)
{
/* Not as great. */
abort ();
}
- tms = time_str (NULL);
+ tms = time_str (time (NULL));
if (!opt.spider)
tmrate = retr_rate (len - restval, con->dltime);
sleep_between_retrievals (count);
/* Get the current time string. */
- tms = time_str (NULL);
+ tms = time_str (time (NULL));
/* Print fetch message, if opt.verbose. */
if (opt.verbose)
err = gethttp (u, &hstat, dt, proxy);
/* Time? */
- tms = time_str (NULL);
+ tms = time_str (time (NULL));
/* Get the new location (with or without the redirection). */
if (hstat.newloc)
#endif
#include <assert.h>
#include <errno.h>
+#include <time.h>
#include "wget.h"
#include "utils.h"
{
logprintf (LOG_NOTQUIET,
_("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"),
- time_str (NULL),
+ time_str (time (NULL)),
opt.numurls,
human_readable (total_downloaded_bytes),
secs_to_human_time (total_download_time),
return ret;
}
\f
+/* Format the provided time according to the specified format. The
+ format is a string with format elements supported by strftime. */
+
+static char *
+fmttime (time_t t, const char *fmt)
+{
+ static char output[32];
+ struct tm *tm = localtime(&t);
+ if (!tm)
+ abort ();
+ if (!strftime(output, sizeof(output), fmt, tm))
+ abort ();
+ return output;
+}
+
/* Return pointer to a static char[] buffer in which zero-terminated
string-representation of TM (in form hh:mm:ss) is printed.
If TM is NULL, the current time will be used. */
char *
-time_str (time_t *tm)
+time_str (time_t t)
{
- static char output[15];
- struct tm *ptm;
- time_t secs = tm ? *tm : time (NULL);
-
- if (secs == -1)
- {
- /* In case of error, return the empty string. Maybe we should
- just abort if this happens? */
- *output = '\0';
- return output;
- }
- ptm = localtime (&secs);
- sprintf (output, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
- return output;
+ return fmttime(t, "%H:%M:%S");
}
/* Like the above, but include the date: YYYY-MM-DD hh:mm:ss. */
char *
-datetime_str (time_t *tm)
+datetime_str (time_t t)
{
- static char output[20]; /* "YYYY-MM-DD hh:mm:ss" + \0 */
- struct tm *ptm;
- time_t secs = tm ? *tm : time (NULL);
-
- if (secs == -1)
- {
- /* In case of error, return the empty string. Maybe we should
- just abort if this happens? */
- *output = '\0';
- return output;
- }
- ptm = localtime (&secs);
- sprintf (output, "%04d-%02d-%02d %02d:%02d:%02d",
- ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday,
- ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
- return output;
+ return fmttime(t, "%Y-%m-%d %H:%M:%S");
}
\f
/* The Windows versions of the following two functions are defined in
#define HYPHENP(x) (*(x) == '-' && !*((x) + 1))
-char *time_str (time_t *);
-char *datetime_str (time_t *);
+char *time_str (time_t);
+char *datetime_str (time_t);
#ifdef DEBUG_MALLOC
void print_malloc_debug_stats ();