1 /* $Id: e_err.c,v 1.15 2000/05/14 14:39:39 jens Exp $ */
2 /*
3 * Copyright (c) 1999, 2000
4 * Jens A. Nilsson, jnilsson@ludd.luth.se. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27 #ifndef lint
28 static char const cvsid[] = "$Id: e_err.c,v 1.15 2000/05/14 14:39:39 jens Exp $";
29 #endif
30
31 #include <errno.h>
32 #include <syslog.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <strings.h>
36
37 #include "e_err.h"
38
39 /* LINTLIBRARY */
40
41 #define MAX_STR ((size_t) 1024)
42
43 #ifdef NOPROTOS
44 void openlog(const char *ident, int logopt, int facility);
45 void syslog(int priority, const char *message, ...);
46 void closelog(void);
47 int snprintf(char *str, size_t size, const char *format, ...);
48 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
49 char *strerror(int);
50 #endif
51
52 #ifdef PROGNAME
53 const char *__progname = PROGNAME;
54 #else
55 #ifdef lint
56 const char *__progname = "lint";
57 #else
58 extern char *__progname;
59 #endif
60 #endif
61
62
63 static const char *e_pname;
64 static const char *e_newline = "\n";
65 static int e_log_facil = 0;
66 static int e_log_prio = 0;
67 static int e_log_opt = LOG_PID;
68 static int e_use_f = 1;
69 static FILE *e_fp = NULL;
70 static int e_log_opened = 0;
71 static int e_level = 0;
72 static int e_inited = 0;
73 static int e_section = -1; /* default is al sections */
74
75
76 #ifdef lint
77 #undef va_start
78 #define va_start(x, y) {x = x;}
79 #endif
80
81 #define CHK_INIT if (!e_inited) e_init()
82 #define CHK_LVL if (level > e_level) return
83 #define CHK_SECT if ((section & e_section) == 0) return
84
85
86 static void
e_init(void)87 e_init(void)
88 {
89 e_inited = 1;
90 e_pname = __progname;
91 e_fp = stderr;
92 }
93
94 static void
update_log(void)95 update_log(void)
96 {
97 if (e_log_opened)
98 closelog();
99 openlog(e_pname, e_log_opt, e_log_facil);
100 e_log_opened = 1;
101 }
102
103 void
e_buf_format(char * buf,size_t len,const char * name,char * error,const char * fmt,va_list args)104 e_buf_format(char *buf, size_t len, const char *name, char *error,
105 const char *fmt, va_list args)
106 {
107 char *p = buf;
108 int oerrno = errno;
109 unsigned res;
110
111 if (name != NULL) {
112 res = snprintf(p, len, "%s: ", name);
113 len -= res;
114 p += res;
115 }
116
117 res = vsnprintf(p, len, fmt, args);
118 if (res >= len) res = len - 1;
119 len -= res;
120 p += res;
121
122 /* remove trailing '\n' */
123 if (p > (buf + 1) && *(p - 1) == '\n') {
124 *(p - 1) = '\0';
125 p--;
126 len++;
127 }
128 /* this is mainly for jftp */
129 if (p > (buf + 1) && *(p - 1) == '\r') {
130 *(p - 1) = '\0';
131 p--;
132 len++;
133 }
134
135 if (error != NULL)
136 res = snprintf(p, len, ": %s", error);
137
138 errno = oerrno;
139 }
140
141 void
e_buf_file(char * buf,FILE * fp)142 e_buf_file(char *buf, FILE *fp)
143 {
144 int oerrno = errno;
145 int needed_extra, len_nl, len_buf, i;
146 char *p, *tmp_buf;
147
148
149 if (e_newline[0] == '\0' ||
150 e_newline[0] != '\n' ||
151 e_newline[1] != '\0') {
152
153 len_nl = (int)strlen(e_newline);
154 needed_extra = 0;
155 for (p = buf; p != NULL; p = strchr(p, '\n')) {
156 /* how much extra space will e_newline take up compared
157 * to "\n" or "\r\n"
158 */
159 needed_extra += len_nl - ((p != buf && *(p - 1) != '\r') ? 1 : 2);
160 p++;
161 }
162
163 len_buf = (int)strlen(buf);
164 if ((p = alloca((size_t)(len_buf + needed_extra + 1))) == NULL) {
165 /* this will probably fail too */
166 fprintf(fp, "e_err: write failed: out of memory%s", e_newline);
167 errno = oerrno;
168 return;
169 }
170
171 p[0] = '\0';
172 tmp_buf = p;
173 for (i = 0; buf[i] != '\0'; i++) {
174 /* calculated needed buffer size earlier,
175 * no risk for buffer overrun
176 */
177 if (buf [i] == '\n' || (buf[i] == '\r' && buf[i + 1] == '\n')) {
178 strcat(p, e_newline);
179 p += len_nl;
180 if (buf[i] == '\r' && buf[i + 1] == '\n')
181 i++;
182 continue;
183 }
184 *p = buf[i];
185 p++;
186 *p = '\0';
187 }
188 buf = tmp_buf;
189 }
190 (void) fprintf(fp, "%s%s", buf, e_newline);
191 (void) fflush(fp);
192 errno = oerrno;
193 }
194
195 void
e_buf_log(char * buf,int prio)196 e_buf_log(char *buf, int prio)
197 {
198 int oerrno = errno;
199 char *p;
200
201 if ((p = index(buf, ':')) != NULL) {
202 if (*p != '\0') p++;
203 if (*p != '\0') p++;
204 } else
205 p = buf;
206 syslog(prio, p);
207 errno = oerrno;
208 }
209
210
211
212 void
e_set_progname(char * name)213 e_set_progname(char *name)
214 {
215 CHK_INIT;
216 e_use_f = 1;
217 e_pname = name;
218 }
219
220 const char *
e_get_progname(void)221 e_get_progname(void)
222 {
223 CHK_INIT;
224 return e_pname;
225 }
226
227 void
e_set_log_facil(int facility)228 e_set_log_facil(int facility)
229 {
230 CHK_INIT;
231 e_use_f = 0;
232 e_log_facil = facility;
233 update_log();
234 }
235
236 int
e_get_log_facil(void)237 e_get_log_facil(void)
238 {
239 CHK_INIT;
240 return e_log_facil;
241 }
242
243 void
e_set_log_prio(int prio)244 e_set_log_prio(int prio)
245 {
246 CHK_INIT;
247 e_use_f = 0;
248 e_log_prio = prio;
249 update_log();
250 }
251
252 int
e_get_log_prio(void)253 e_get_log_prio(void)
254 {
255 CHK_INIT;
256 return e_log_prio;
257 }
258
259 void
e_use_log(void)260 e_use_log(void)
261 {
262 CHK_INIT;
263 e_use_f = 0;
264 }
265
266 void
e_set_file(FILE * fp)267 e_set_file(FILE *fp)
268 {
269 CHK_INIT;
270 e_use_f = 1;
271 e_fp = fp != NULL ? fp : stderr;;
272 e_pname = e_fp == stderr ? __progname : NULL;
273 }
274
275 FILE *
e_get_file(void)276 e_get_file(void)
277 {
278 CHK_INIT;
279 return e_fp;
280 }
281
282 void
e_use_file(void)283 e_use_file(void)
284 {
285 CHK_INIT;
286 e_use_f = 1;
287 }
288
289 void
e_set_level(int level)290 e_set_level(int level)
291 {
292 e_level = level;
293 }
294
295 int
e_get_level(void)296 e_get_level(void)
297 {
298 return e_level;
299 }
300
301 void
e_set_section(int section)302 e_set_section(int section)
303 {
304 e_section = section;
305 }
306
307 int
e_get_section(void)308 e_get_section(void)
309 {
310 return e_section;
311 }
312
313 void
e_set_newline_str(const char * str)314 e_set_newline_str(const char *str)
315 {
316 e_newline = str;
317 }
318
319 const char *
e_get_newline_str(void)320 e_get_newline_str(void)
321 {
322 return e_newline;
323 }
324
325
326 void
e_usage(const char * fmt,...)327 e_usage(const char *fmt, ...)
328 {
329 va_list ap;
330 char buf[MAX_STR];
331 char *p = buf;
332 size_t len = MAX_STR;
333 int oerrno = errno;
334 unsigned res;
335
336 CHK_INIT;
337 va_start(ap, fmt);
338
339 /* from buf_format(), slightly modified */
340 res = snprintf(p, len, "usage: %s ", e_pname);
341 len -= res;
342 p += res;
343
344 res = vsnprintf(p, len, fmt, ap);
345 len -= res;
346 p += res;
347
348 /* remove trailing '\n' */
349 if (p > (buf + 1) && *(p - 1) == '\n') {
350 *(p - 1) = '\0';
351 p--;
352 len++;
353 }
354 /* this is mainly for jftp */
355 if (p > (buf + 1) && *(p - 1) == '\r') {
356 *(p - 1) = '\0';
357 p--;
358 len++;
359 }
360 /* end from buf_format() */
361
362 e_buf_file(buf, stderr);
363 va_end(ap);
364 errno = oerrno;
365 }
366
367 void
e_err(int eval,const char * fmt,...)368 e_err(int eval, const char *fmt, ...)
369 {
370 va_list ap;
371
372 CHK_INIT;
373 va_start(ap, fmt);
374 e_verr(eval, fmt, ap);
375 va_end(ap);
376 }
377
378 void
e_verr(int eval,const char * fmt,va_list args)379 e_verr(int eval, const char *fmt, va_list args)
380 {
381 CHK_INIT;
382 if (e_use_f)
383 e_verr_file(eval, e_fp, fmt, args);
384 e_verr_log(eval, e_log_prio, fmt, args);
385 }
386
387 void
e_err_log(int eval,int prio,const char * fmt,...)388 e_err_log(int eval, int prio, const char *fmt, ...)
389 {
390 va_list ap;
391
392 CHK_INIT;
393 va_start(ap, fmt);
394 e_verr_log(eval, prio, fmt, ap);
395 va_end(ap);
396 }
397
398 void
e_verr_log(int eval,int prio,const char * fmt,va_list args)399 e_verr_log(int eval, int prio, const char *fmt, va_list args)
400 {
401 CHK_INIT;
402 e_vwarn_log(prio, fmt, args);
403 exit(eval);
404 }
405
406 void
e_err_file(int eval,FILE * fp,const char * fmt,...)407 e_err_file(int eval, FILE *fp, const char *fmt, ...)
408 {
409 va_list ap;
410
411 CHK_INIT;
412 va_start(ap, fmt);
413 e_verr_file(eval, fp, fmt, ap);
414 va_end(ap);
415 }
416
417 void
e_verr_file(int eval,FILE * fp,const char * fmt,va_list args)418 e_verr_file(int eval, FILE *fp, const char *fmt, va_list args)
419 {
420 CHK_INIT;
421 e_vwarn_file(fp, fmt, args);
422 exit(eval);
423 }
424
425 void
e_errx(int eval,const char * fmt,...)426 e_errx(int eval, const char *fmt, ...)
427 {
428 va_list ap;
429
430 CHK_INIT;
431 va_start(ap, fmt);
432 e_verrx(eval, fmt, ap);
433 va_end(ap);
434 }
435
436 void
e_verrx(int eval,const char * fmt,va_list args)437 e_verrx(int eval, const char *fmt, va_list args)
438 {
439 CHK_INIT;
440 if (e_use_f)
441 e_verrx_file(eval, e_fp, fmt, args);
442 e_verrx_log(eval, e_log_prio, fmt, args);
443 }
444
445 void
e_errx_log(int eval,int prio,const char * fmt,...)446 e_errx_log(int eval, int prio, const char *fmt, ...)
447 {
448 va_list ap;
449
450 CHK_INIT;
451 va_start(ap, fmt);
452 e_verrx_log(eval, prio, fmt, ap);
453 va_end(ap);
454 }
455
456 void
e_verrx_log(int eval,int prio,const char * fmt,va_list args)457 e_verrx_log(int eval, int prio, const char *fmt, va_list args)
458 {
459 CHK_INIT;
460 e_vwarnx_log(prio, fmt, args);
461 exit(eval);
462 }
463
464 void
e_errx_file(int eval,FILE * fp,const char * fmt,...)465 e_errx_file(int eval, FILE *fp, const char *fmt, ...)
466 {
467 va_list ap;
468
469 CHK_INIT;
470 va_start(ap, fmt);
471 e_verrx_file(eval, fp, fmt, ap);
472 va_end(ap);
473 }
474
475 void
e_verrx_file(int eval,FILE * fp,const char * fmt,va_list args)476 e_verrx_file(int eval, FILE *fp, const char *fmt, va_list args)
477 {
478 CHK_INIT;
479 e_vwarnx_file(fp, fmt, args);
480 exit(eval);
481 }
482
483 void
e_vtrace(int level,int section,const char * fmt,va_list args)484 e_vtrace(int level, int section, const char *fmt, va_list args)
485 {
486 CHK_INIT;
487 CHK_LVL;
488 CHK_SECT;
489 e_vwarn(fmt, args);
490 }
491
492 void
e_trace(int level,int section,const char * fmt,...)493 e_trace(int level, int section, const char *fmt, ...)
494 {
495 va_list ap;
496
497 CHK_INIT;
498 CHK_LVL;
499 CHK_SECT;
500 va_start(ap, fmt);
501 e_vwarn(fmt, ap);
502 va_end(ap);
503 }
504
505 void
e_vtrace_log(int level,int section,int prio,const char * fmt,va_list args)506 e_vtrace_log(int level, int section, int prio, const char *fmt, va_list args)
507 {
508 CHK_INIT;
509 CHK_LVL;
510 CHK_SECT;
511 e_vwarn_log(prio, fmt, args);
512 }
513
514 void
e_trace_log(int level,int section,int prio,const char * fmt,...)515 e_trace_log(int level, int section, int prio, const char *fmt, ...)
516 {
517 va_list ap;
518
519 CHK_INIT;
520 CHK_LVL;
521 CHK_SECT;
522 va_start(ap, fmt);
523 e_vwarn_log(prio, fmt, ap);
524 va_end(ap);
525 }
526
527 void
e_vtrace_file(int level,int section,FILE * fp,const char * fmt,va_list args)528 e_vtrace_file(int level, int section, FILE *fp, const char *fmt, va_list args)
529 {
530 CHK_INIT;
531 CHK_LVL;
532 CHK_SECT;
533 e_vwarn_file(fp, fmt, args);
534 }
535
536 void
e_trace_file(int level,int section,FILE * fp,const char * fmt,...)537 e_trace_file(int level, int section, FILE *fp, const char *fmt, ...)
538 {
539 va_list ap;
540
541 CHK_INIT;
542 CHK_LVL;
543 CHK_SECT;
544 va_start(ap, fmt);
545 e_vwarn_file(fp, fmt, ap);
546 va_end(ap);
547 }
548
549 void
e_vtracex(int level,int section,const char * fmt,va_list args)550 e_vtracex(int level, int section, const char *fmt, va_list args)
551 {
552 CHK_INIT;
553 CHK_LVL;
554 CHK_SECT;
555 e_vwarnx(fmt, args);
556 }
557
558 void
e_tracex(int level,int section,const char * fmt,...)559 e_tracex(int level, int section, const char *fmt, ...)
560 {
561 va_list ap;
562
563 CHK_INIT;
564 CHK_LVL;
565 CHK_SECT;
566 va_start(ap, fmt);
567 e_vwarnx(fmt, ap);
568 va_end(ap);
569 }
570
571 void
e_vtracex_log(int level,int section,int prio,const char * fmt,va_list args)572 e_vtracex_log(int level, int section, int prio, const char *fmt, va_list args)
573 {
574 CHK_INIT;
575 CHK_LVL;
576 CHK_SECT;
577 e_vwarnx_log(prio, fmt, args);
578 }
579
580 void
e_tracex_log(int level,int section,int prio,const char * fmt,...)581 e_tracex_log(int level, int section, int prio, const char *fmt, ...)
582 {
583 va_list ap;
584
585 CHK_INIT;
586 CHK_LVL;
587 CHK_SECT;
588 va_start(ap, fmt);
589 e_vwarnx_log(prio, fmt, ap);
590 va_end(ap);
591 }
592
593 void
e_vtracex_file(int level,int section,FILE * fp,const char * fmt,va_list args)594 e_vtracex_file(int level, int section, FILE *fp, const char *fmt, va_list args)
595 {
596 CHK_INIT;
597 CHK_LVL;
598 CHK_SECT;
599 e_vwarnx_file(fp, fmt, args);
600 }
601
602 void
e_tracex_file(int level,int section,FILE * fp,const char * fmt,...)603 e_tracex_file(int level, int section, FILE *fp, const char *fmt, ...)
604 {
605 va_list ap;
606
607 CHK_INIT;
608 CHK_LVL;
609 CHK_SECT;
610 va_start(ap, fmt);
611 e_vwarnx_file(fp, fmt, ap);
612 va_end(ap);
613 }
614
615 void
e_vlog(int level,const char * fmt,va_list args)616 e_vlog(int level, const char *fmt, va_list args)
617 {
618 CHK_INIT;
619 CHK_LVL;
620 e_vwarn(fmt, args);
621 }
622
623 void
e_log(int level,const char * fmt,...)624 e_log(int level, const char *fmt, ...)
625 {
626 va_list ap;
627
628 CHK_INIT;
629 CHK_LVL;
630 va_start(ap, fmt);
631 e_vwarn(fmt, ap);
632 va_end(ap);
633 }
634
635 void
e_vlog_log(int level,int prio,const char * fmt,va_list args)636 e_vlog_log(int level, int prio, const char *fmt, va_list args)
637 {
638 CHK_INIT;
639 CHK_LVL;
640 e_vwarn_log(prio, fmt, args);
641 }
642
643 void
e_log_log(int level,int prio,const char * fmt,...)644 e_log_log(int level, int prio, const char *fmt, ...)
645 {
646 va_list ap;
647
648 CHK_INIT;
649 CHK_LVL;
650 va_start(ap, fmt);
651 e_vwarn_log(prio, fmt, ap);
652 va_end(ap);
653 }
654
655 void
e_vlog_file(int level,FILE * fp,const char * fmt,va_list args)656 e_vlog_file(int level, FILE *fp, const char *fmt, va_list args)
657 {
658 CHK_INIT;
659 CHK_LVL;
660 e_vwarn_file(fp, fmt, args);
661 }
662
663 void
e_log_file(int level,FILE * fp,const char * fmt,...)664 e_log_file(int level, FILE *fp, const char *fmt, ...)
665 {
666 va_list ap;
667
668 CHK_INIT;
669 CHK_LVL;
670 va_start(ap, fmt);
671 e_vwarn_file(fp, fmt, ap);
672 va_end(ap);
673 }
674
675 void
e_vlogx(int level,const char * fmt,va_list args)676 e_vlogx(int level, const char *fmt, va_list args)
677 {
678 CHK_INIT;
679 CHK_LVL;
680 e_vwarnx(fmt, args);
681 }
682
683 void
e_logx(int level,const char * fmt,...)684 e_logx(int level, const char *fmt, ...)
685 {
686 va_list ap;
687
688 CHK_INIT;
689 CHK_LVL;
690 va_start(ap, fmt);
691 e_vwarnx(fmt, ap);
692 va_end(ap);
693 }
694
695 void
e_vlogx_log(int level,int prio,const char * fmt,va_list args)696 e_vlogx_log(int level, int prio, const char *fmt, va_list args)
697 {
698 CHK_INIT;
699 CHK_LVL;
700 e_vwarnx_log(prio, fmt, args);
701 }
702
703 void
e_logx_log(int level,int prio,const char * fmt,...)704 e_logx_log(int level, int prio, const char *fmt, ...)
705 {
706 va_list ap;
707
708 CHK_INIT;
709 CHK_LVL;
710 va_start(ap, fmt);
711 e_vwarnx_log(prio, fmt, ap);
712 va_end(ap);
713 }
714
715 void
e_vlogx_file(int level,FILE * fp,const char * fmt,va_list args)716 e_vlogx_file(int level, FILE *fp, const char *fmt, va_list args)
717 {
718 CHK_INIT;
719 CHK_LVL;
720 e_vwarnx_file(fp, fmt, args);
721 }
722
723 void
e_logx_file(int level,FILE * fp,const char * fmt,...)724 e_logx_file(int level, FILE *fp, const char *fmt, ...)
725 {
726 va_list ap;
727
728 CHK_INIT;
729 CHK_LVL;
730 va_start(ap, fmt);
731 e_vwarnx_file(fp, fmt, ap);
732 va_end(ap);
733 }
734
735 void
e_warn(const char * fmt,...)736 e_warn(const char *fmt, ...)
737 {
738 va_list ap;
739
740 CHK_INIT;
741 va_start(ap, fmt);
742 e_vwarn(fmt, ap);
743 va_end(ap);
744 }
745
746 void
e_vwarn(const char * fmt,va_list args)747 e_vwarn(const char *fmt, va_list args)
748 {
749 CHK_INIT;
750 if (e_use_f)
751 e_vwarn_file(e_fp, fmt, args);
752 else
753 e_vwarn_log(e_log_prio, fmt, args);
754 }
755
756 void
e_warn_log(int prio,const char * fmt,...)757 e_warn_log(int prio, const char *fmt, ...)
758 {
759 va_list ap;
760
761 CHK_INIT;
762 va_start(ap, fmt);
763 e_vwarn_log(prio, fmt, ap);
764 va_end(ap);
765 }
766
767 void
e_vwarn_log(int prio,const char * fmt,va_list args)768 e_vwarn_log(int prio, const char *fmt, va_list args)
769 {
770 char buf[MAX_STR];
771
772 CHK_INIT;
773 e_buf_format(buf, MAX_STR, e_pname, strerror(errno), fmt, args);
774 e_buf_log(buf, prio);
775 }
776
777 void
e_warn_file(FILE * fp,const char * fmt,...)778 e_warn_file(FILE *fp, const char *fmt, ...)
779 {
780 va_list ap;
781
782 CHK_INIT;
783 va_start(ap, fmt);
784 e_vwarn_file(fp, fmt, ap);
785 va_end(ap);
786 }
787
788 void
e_vwarn_file(FILE * fp,const char * fmt,va_list args)789 e_vwarn_file(FILE *fp, const char *fmt, va_list args)
790 {
791 char buf[MAX_STR];
792
793 CHK_INIT;
794 e_buf_format(buf, MAX_STR, e_pname, strerror(errno), fmt, args);
795 e_buf_file(buf, fp);
796 }
797
798 void
e_warnx(const char * fmt,...)799 e_warnx(const char *fmt, ...)
800 {
801 va_list ap;
802
803 CHK_INIT;
804 va_start(ap, fmt);
805 e_vwarnx(fmt, ap);
806 va_end(ap);
807 }
808
809 void
e_vwarnx(const char * fmt,va_list args)810 e_vwarnx(const char *fmt, va_list args)
811 {
812 CHK_INIT;
813 if (e_use_f)
814 e_vwarnx_file(e_fp, fmt, args);
815 else
816 e_vwarnx_log(e_log_prio, fmt, args);
817 }
818
819 void
e_warnx_log(int prio,const char * fmt,...)820 e_warnx_log(int prio, const char *fmt, ...)
821 {
822 va_list ap;
823
824 CHK_INIT;
825 va_start(ap, fmt);
826 e_vwarnx_log(prio, fmt, ap);
827 va_end(ap);
828 }
829
830 void
e_vwarnx_log(int prio,const char * fmt,va_list args)831 e_vwarnx_log(int prio, const char *fmt, va_list args)
832 {
833 char buf[MAX_STR];
834
835 CHK_INIT;
836 e_buf_format(buf, MAX_STR, e_pname, NULL, fmt, args);
837 e_buf_log(buf, prio);
838 }
839
840 void
e_warnx_file(FILE * fp,const char * fmt,...)841 e_warnx_file(FILE *fp, const char *fmt, ...)
842 {
843 va_list ap;
844
845 CHK_INIT;
846 va_start(ap, fmt);
847 e_vwarnx_file(fp, fmt, ap);
848 va_end(ap);
849 }
850
851 void
e_vwarnx_file(FILE * fp,const char * fmt,va_list args)852 e_vwarnx_file(FILE *fp, const char *fmt, va_list args)
853 {
854 char buf[MAX_STR];
855
856 CHK_INIT;
857 e_buf_format(buf, MAX_STR, e_pname, NULL, fmt, args);
858 e_buf_file(buf, fp);
859 }
860
861 int
e_daemon(int nochdir,int noclose,int facility,int prio)862 e_daemon(int nochdir, int noclose, int facility, int prio)
863 {
864 e_use_log();
865 e_set_log_facil(facility);
866 e_set_log_prio(prio);
867 return daemon(nochdir, noclose);
868 }
869
870