comparison mcabber/src/histolog.c @ 273:fe438fe67b6f

Error checking when writing log files
author mikael@frmp8452
date Sun, 03 Jul 2005 20:58:35 +0100
parents 594e73bc9610
children 4d7040cff8ee
comparison
equal deleted inserted replaced
272:7f2e61392b2e 273:fe438fe67b6f
67 FILE *fp; 67 FILE *fp;
68 time_t ts; 68 time_t ts;
69 const char *p; 69 const char *p;
70 char *filename; 70 char *filename;
71 char str_ts[20]; 71 char str_ts[20];
72 int err;
72 73
73 if (!UseFileLogging) return; 74 if (!UseFileLogging) return;
74 75
75 filename = user_histo_file(jid); 76 filename = user_histo_file(jid);
76 77
97 * We don't check them, we'll trust the caller. 98 * We don't check them, we'll trust the caller.
98 */ 99 */
99 100
100 fp = fopen(filename, "a"); 101 fp = fopen(filename, "a");
101 g_free(filename); 102 g_free(filename);
102 if (!fp) return; 103 if (!fp) {
104 scr_LogPrint("Unable to write history (cannot open logfile)");
105 return;
106 }
103 107
104 to_iso8601(str_ts, ts); 108 to_iso8601(str_ts, ts);
105 fprintf(fp, "%c%c %-18.18s %03d %s\n", type, info, str_ts, len, data); 109 err = fprintf(fp, "%c%c %-18.18s %03d %s\n", type, info, str_ts, len, data);
106 fclose(fp); 110 fclose(fp);
111 if (err < 0) {
112 scr_LogPrint("Error while writing to log file: %s", strerror(errno));
113 }
107 } 114 }
108 115
109 // hlog_read_history() 116 // hlog_read_history()
110 // Reads the jid's history logfile 117 // Reads the jid's history logfile
111 void hlog_read_history(const char *jid, GList **p_buddyhbuf, guint width) 118 void hlog_read_history(const char *jid, GList **p_buddyhbuf, guint width)