mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Check the return value of strftime() properly
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1113 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
aa447813d0
commit
d427f74143
@ -70,27 +70,31 @@ static void log_write_timestamp(int handle, const char *format,
|
||||
if (*format == '\0') return;
|
||||
|
||||
tm = localtime(&stamp);
|
||||
|
||||
str[sizeof(str)-1] = '\0';
|
||||
strftime(str, sizeof(str)-1, format, tm);
|
||||
|
||||
write(handle, str, strlen(str));
|
||||
if (suffix != NULL) write(handle, suffix, strlen(suffix));
|
||||
if (strftime(str, sizeof(str), format, tm) > 0) {
|
||||
write(handle, str, strlen(str));
|
||||
if (suffix != NULL) write(handle, suffix, strlen(suffix));
|
||||
}
|
||||
}
|
||||
|
||||
static char *log_filename(LOG_REC *log)
|
||||
{
|
||||
char *str, fname[1024];
|
||||
struct tm *tm;
|
||||
size_t ret;
|
||||
time_t now;
|
||||
|
||||
now = time(NULL);
|
||||
tm = localtime(&now);
|
||||
|
||||
str = convert_home(log->fname);
|
||||
strftime(fname, sizeof(fname), str, tm);
|
||||
ret = strftime(fname, sizeof(fname), str, tm);
|
||||
g_free(str);
|
||||
|
||||
if (ret <= 0) {
|
||||
g_warning("log_filename() : strftime() failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_strdup(fname);
|
||||
}
|
||||
|
||||
@ -104,8 +108,9 @@ int log_start_logging(LOG_REC *log)
|
||||
/* Append/create log file */
|
||||
g_free_not_null(log->real_fname);
|
||||
log->real_fname = log_filename(log);
|
||||
log->handle = open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
|
||||
log_file_create_mode);
|
||||
log->handle = log->real_fname == NULL ? -1 :
|
||||
open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
|
||||
log_file_create_mode);
|
||||
if (log->handle == -1) {
|
||||
signal_emit("log create failed", 1, log);
|
||||
log->failed = TRUE;
|
||||
|
@ -421,13 +421,14 @@ static void sig_server_disconnected(SERVER_REC *server)
|
||||
static void sig_print_text(void)
|
||||
{
|
||||
GSList *tmp;
|
||||
char month[10];
|
||||
char month[100];
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
|
||||
t = time(NULL);
|
||||
tm = localtime(&t);
|
||||
strftime(month, sizeof(month)-1, "%b", tm);
|
||||
if (strftime(month, sizeof(month), "%b", tm) <= 0)
|
||||
month[0] = '\0';
|
||||
|
||||
if (tm->tm_hour != 0 || tm->tm_min != 0)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user