1
0
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:
hniksic 2006-08-08 07:32:53 -07:00
parent 6493450947
commit 8566a72767
7 changed files with 35 additions and 42 deletions

View File

@ -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> 2006-07-21 Hrvoje Niksic <hniksic@xemacs.org>
* init.c (commands): Correctly place "contentdisposition". * init.c (commands): Correctly place "contentdisposition".

View File

@ -265,7 +265,7 @@ store_cookie (struct cookie_jar *jar, struct cookie *cookie)
cookie->path, cookie->path,
cookie->permanent ? "permanent" : "session", cookie->permanent ? "permanent" : "session",
cookie->secure ? "secure" : "insecure", cookie->secure ? "secure" : "insecure",
cookie->expiry_time ? datetime_str (&exptime) : "none", cookie->expiry_time ? datetime_str (exptime) : "none",
cookie->attr, cookie->value)); cookie->attr, cookie->value));
} }
} }
@ -1255,7 +1255,7 @@ cookie_jar_save (struct cookie_jar *jar, const char *file)
} }
fputs ("# HTTP cookie file.\n", fp); 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); fputs ("# Edit at your own risk.\n\n", fp);
for (hash_table_iterate (jar->chains, &iter); for (hash_table_iterate (jar->chains, &iter);

View File

@ -37,6 +37,7 @@ so, delete this exception statement from your version. */
#endif #endif
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include "wget.h" #include "wget.h"
#include "utils.h" #include "utils.h"
@ -967,7 +968,7 @@ Error in server response, closing control connection.\n"));
expected_bytes ? expected_bytes - restval : 0, expected_bytes ? expected_bytes - restval : 0,
restval, &rd_size, len, &con->dltime, flags); restval, &rd_size, len, &con->dltime, flags);
tms = time_str (NULL); tms = time_str (time (NULL));
tmrate = retr_rate (rd_size, con->dltime); tmrate = retr_rate (rd_size, con->dltime);
total_download_time += con->dltime; total_download_time += con->dltime;
@ -1149,7 +1150,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
restval = 0; restval = 0;
/* Get the current time string. */ /* Get the current time string. */
tms = time_str (NULL); tms = time_str (time (NULL));
/* Print fetch message, if opt.verbose. */ /* Print fetch message, if opt.verbose. */
if (opt.verbose) if (opt.verbose)
{ {
@ -1213,7 +1214,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
/* Not as great. */ /* Not as great. */
abort (); abort ();
} }
tms = time_str (NULL); tms = time_str (time (NULL));
if (!opt.spider) if (!opt.spider)
tmrate = retr_rate (len - restval, con->dltime); tmrate = retr_rate (len - restval, con->dltime);

View File

@ -2280,7 +2280,7 @@ http_loop (struct url *u, char **newloc, char **local_file, const char *referer,
sleep_between_retrievals (count); sleep_between_retrievals (count);
/* Get the current time string. */ /* Get the current time string. */
tms = time_str (NULL); tms = time_str (time (NULL));
/* Print fetch message, if opt.verbose. */ /* Print fetch message, if opt.verbose. */
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); err = gethttp (u, &hstat, dt, proxy);
/* Time? */ /* Time? */
tms = time_str (NULL); tms = time_str (time (NULL));
/* Get the new location (with or without the redirection). */ /* Get the new location (with or without the redirection). */
if (hstat.newloc) if (hstat.newloc)

View File

@ -41,6 +41,7 @@ so, delete this exception statement from your version. */
#endif #endif
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include "wget.h" #include "wget.h"
#include "utils.h" #include "utils.h"
@ -1017,7 +1018,7 @@ Can't timestamp and not clobber old files at the same time.\n"));
{ {
logprintf (LOG_NOTQUIET, logprintf (LOG_NOTQUIET,
_("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"), _("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"),
time_str (NULL), time_str (time (NULL)),
opt.numurls, opt.numurls,
human_readable (total_downloaded_bytes), human_readable (total_downloaded_bytes),
secs_to_human_time (total_download_time), secs_to_human_time (total_download_time),

View File

@ -253,51 +253,38 @@ concat_strings (const char *str0, ...)
return ret; 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 /* Return pointer to a static char[] buffer in which zero-terminated
string-representation of TM (in form hh:mm:ss) is printed. string-representation of TM (in form hh:mm:ss) is printed.
If TM is NULL, the current time will be used. */ If TM is NULL, the current time will be used. */
char * char *
time_str (time_t *tm) time_str (time_t t)
{ {
static char output[15]; return fmttime(t, "%H:%M:%S");
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;
} }
/* Like the above, but include the date: YYYY-MM-DD hh:mm:ss. */ /* Like the above, but include the date: YYYY-MM-DD hh:mm:ss. */
char * char *
datetime_str (time_t *tm) datetime_str (time_t t)
{ {
static char output[20]; /* "YYYY-MM-DD hh:mm:ss" + \0 */ return fmttime(t, "%Y-%m-%d %H:%M:%S");
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;
} }
/* The Windows versions of the following two functions are defined in /* The Windows versions of the following two functions are defined in

View File

@ -40,8 +40,8 @@ struct file_memory {
#define HYPHENP(x) (*(x) == '-' && !*((x) + 1)) #define HYPHENP(x) (*(x) == '-' && !*((x) + 1))
char *time_str (time_t *); char *time_str (time_t);
char *datetime_str (time_t *); char *datetime_str (time_t);
#ifdef DEBUG_MALLOC #ifdef DEBUG_MALLOC
void print_malloc_debug_stats (); void print_malloc_debug_stats ();