xref: /lighttpd1.4/src/fdlog.c (revision 5e14db43)
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 *
fdlog_init(const char * const fn,const int fd,const int mode)10 fdlog_init (const char * const fn, const int fd, const int mode)
11 {
12     fdlog_st * const fdlog = ck_calloc(1, sizeof(fdlog_st));
13     fdlog->fn = fn; /* note: fn must persist in memory (or else copy here) */
14     fdlog->fd = fd >= 0 ? fd : STDERR_FILENO;
15     fdlog->mode = mode;
16     return fdlog;
17 }
18 
19 
20 void
fdlog_free(fdlog_st * const fdlog)21 fdlog_free (fdlog_st * const fdlog)
22 {
23     if (fdlog->fd > STDERR_FILENO)
24         close(fdlog->fd);
25     free(fdlog->b.ptr);
26     free(fdlog);
27 }
28