xref: /lighttpd1.4/src/fdlog.c (revision 2e0edb85)
1 #include "first.h"
2 #include "fdlog.h"
3 
4 #include <stdlib.h>
5 #include <unistd.h>     /* close() STDERR_FILENO */
6 
7 #include "ck.h"
8 
9 fdlog_st *
10 fdlog_init (const char * const fn, const int fd, const int mode)
11 {
12     fdlog_st * const fdlog = calloc(1, sizeof(fdlog_st));
13     ck_assert(fdlog);
14     fdlog->fn = fn; /* note: fn must persist in memory (or else copy here) */
15     fdlog->fd = fd >= 0 ? fd : STDERR_FILENO;
16     fdlog->mode = mode;
17     return fdlog;
18 }
19 
20 
21 void
22 fdlog_free (fdlog_st * const fdlog)
23 {
24     if (fdlog->fd > STDERR_FILENO)
25         close(fdlog->fd);
26     free(fdlog->b.ptr);
27     free(fdlog);
28 }
29