mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Avoid code repetition between time_str and datetime_str.
This commit is contained in:
parent
6493450947
commit
8566a72767
@ -1,3 +1,7 @@
|
||||
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".
|
||||
|
@ -265,7 +265,7 @@ store_cookie (struct cookie_jar *jar, struct cookie *cookie)
|
||||
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));
|
||||
}
|
||||
}
|
||||
@ -1255,7 +1255,7 @@ cookie_jar_save (struct cookie_jar *jar, const char *file)
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -37,6 +37,7 @@ so, delete this exception statement from your version. */
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "wget.h"
|
||||
#include "utils.h"
|
||||
@ -967,7 +968,7 @@ Error in server response, closing control connection.\n"));
|
||||
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;
|
||||
|
||||
@ -1149,7 +1150,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
|
||||
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)
|
||||
{
|
||||
@ -1213,7 +1214,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
|
||||
/* Not as great. */
|
||||
abort ();
|
||||
}
|
||||
tms = time_str (NULL);
|
||||
tms = time_str (time (NULL));
|
||||
if (!opt.spider)
|
||||
tmrate = retr_rate (len - restval, con->dltime);
|
||||
|
||||
|
@ -2280,7 +2280,7 @@ http_loop (struct url *u, char **newloc, char **local_file, const char *referer,
|
||||
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)
|
||||
@ -2344,7 +2344,7 @@ http_loop (struct url *u, char **newloc, char **local_file, const char *referer,
|
||||
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)
|
||||
|
@ -41,6 +41,7 @@ so, delete this exception statement from your version. */
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "wget.h"
|
||||
#include "utils.h"
|
||||
@ -1017,7 +1018,7 @@ Can't timestamp and not clobber old files at the same time.\n"));
|
||||
{
|
||||
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),
|
||||
|
51
src/utils.c
51
src/utils.c
@ -253,51 +253,38 @@ concat_strings (const char *str0, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 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");
|
||||
}
|
||||
|
||||
/* The Windows versions of the following two functions are defined in
|
||||
|
@ -40,8 +40,8 @@ struct file_memory {
|
||||
|
||||
#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 ();
|
||||
|
Loading…
Reference in New Issue
Block a user