comparison nnchat.c @ 100:ed4067c10a8a

Remove useless buffer usage from error reporting function.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 17 Nov 2009 23:09:10 +0200
parents b7c981e27b66
children eaa524e153f9
comparison
equal deleted inserted replaced
99:0313fabd8049 100:ed4067c10a8a
280 280
281 return 0; 281 return 0;
282 } 282 }
283 283
284 284
285 void printMsg(char *fmt, ...) 285 void printMsgV(const char *fmt, va_list ap)
286 { 286 {
287 char tmpStr[128] = "", buf[8192]; 287 char tmpStr[128] = "", buf[8192];
288 va_list ap;
289 time_t timeStamp; 288 time_t timeStamp;
290 struct tm *tmpTime;; 289 struct tm *tmpTime;;
291 290
292 timeStamp = time(NULL); 291 timeStamp = time(NULL);
293 if ((tmpTime = localtime(&timeStamp)) != NULL) { 292 if ((tmpTime = localtime(&timeStamp)) != NULL) {
294 strftime(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ ", tmpTime); 293 strftime(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ ", tmpTime);
295 } 294 }
296 295
297 va_start(ap, fmt);
298 vsnprintf(buf, sizeof(buf), fmt, ap); 296 vsnprintf(buf, sizeof(buf), fmt, ap);
299 va_end(ap);
300 297
301 if (optLogFile) { 298 if (optLogFile) {
302 printFile(optLogFile, tmpStr); 299 printFile(optLogFile, tmpStr);
303 printFile(optLogFile, buf); 300 printFile(optLogFile, buf);
304 fflush(optLogFile); 301 fflush(optLogFile);
309 printWin(mainWin, buf); 306 printWin(mainWin, buf);
310 wrefresh(mainWin); 307 wrefresh(mainWin);
311 } 308 }
312 } 309 }
313 310
311 void printMsg(const char *fmt, ...)
312 {
313 va_list ap;
314
315 va_start(ap, fmt);
316 printMsgV(fmt, ap);
317 va_end(ap);
318 }
319
314 320
315 void errorMsg(char *fmt, ...) 321 void errorMsg(char *fmt, ...)
316 { 322 {
317 char buf[8192]; 323 va_list ap1, ap2;
318 va_list ap; 324
319 325 va_start(ap1, fmt);
320 va_start(ap, fmt); 326 va_copy(ap2, ap1);
321 vsnprintf(buf, sizeof(buf), fmt, ap); 327 printMsgV(fmt, ap1);
322 va_end(ap); 328 va_end(ap1);
323 329
324 printMsg(buf); 330 THERR_V(fmt, ap2);
325 THERR(buf); 331 va_end(ap2);
326 } 332 }
327 333
328 334
329 int handleUser(int sock, char *str) 335 int handleUser(int sock, char *str)
330 { 336 {
643 hstrerror(h_errno)); 649 hstrerror(h_errno));
644 goto err_exit; 650 goto err_exit;
645 } 651 }
646 THMSG(2, "True hostname: %s\n", tmpHost->h_name); 652 THMSG(2, "True hostname: %s\n", tmpHost->h_name);
647 653
648
649 #if 1 654 #if 1
650 /* To emulate the official client, we first make a request for 655 /* To emulate the official client, we first make a request for
651 * policy file, even though we don't use it for anything... 656 * policy file, even though we don't use it for anything...
652 */ 657 */
653 if ((tmpSocket = nn_open_connection((struct in_addr *) tmpHost->h_addr, 843)) < 0) { 658 if ((tmpSocket = nn_open_connection((struct in_addr *) tmpHost->h_addr, 843)) < 0) {
722 727
723 nn_editbuf_clear(editBuf); 728 nn_editbuf_clear(editBuf);
724 printEditBuf("", editBuf); 729 printEditBuf("", editBuf);
725 updateStatus(insertMode); 730 updateStatus(insertMode);
726 } 731 }
727 732
728 /* Enter mainloop */ 733 /* Enter mainloop */
729 prevTime = time(NULL); 734 prevTime = time(NULL);
730 FD_ZERO(&sockfds); 735 FD_ZERO(&sockfds);
731 FD_SET(tmpSocket, &sockfds); 736 FD_SET(tmpSocket, &sockfds);
732 737