aboutsummaryrefslogtreecommitdiffstats
path: root/man/el_init.3
blob: e7625764a76731fce4774224927fa735ec69f8e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
.TH "el_init" "3" "10 June 2019 (v9999)" "bofc.pl"
.SH NAME
.PP
.B el_init
- initializes library and el for printing.
.SH SYNOPSIS
.PP
.B "#include <embedlog.h>"
.PP
.BI "int el_init(void)"
.br
.BI "int el_oinit(struct el *" el ")"
.br
.BI "struct el * el_new(void)"
.SH DESCRIPTION
.PP
There are two types of functions in
.BR embedlog.
Functions that use global static structure inside library, these functions don't
accept
.I el
argument with options.
.PP
Another type are functions that accept additional
.I el
argument. These functions are prefixed with
.BR el_o .
.PP
.BR el_init (3)
initializes static global option structure. This option structure is used by all
functions that don't accept
.I el
object parameter.
If you want to use only one instance of
.BR embedlog ,
this is the function you want to use.
.PP
.BR el_oinit (3)
initializes only
.I el
struct passed to it.
Functions that accepts
.I el
object may be used.
If you want to have multiple embedlog instances (ie. one for program logs,
and one for queries) that stores logs differently - this is the function you
want to use.
Object initialized with this function must be deinitialized with
.BR el_ocleanup (3)
function.
.PP
.BR el_new (3)
Works in the same way as
.BR el_oinit (3)
but function returns newly heap-allocated pointer to
.I el
struct.
Object created with this function must be destroyed with
.BR el_destroy (3)
function.
.SH NOTES
Keeps in mind that using
.BR el_oinit (3)
function is suscible to ABI breakage.
If stable ABI is important to you, use
.BR el_new (3)
function.
Please check
.BR el_overview (3)
for more information about this.
.SH RETURN VALUE
.PP
.BR el_init (3)
cannot fail and always returns 0.
.BR el_oinit (3)
function will return 0 upon success and -1 on errors.
.BR el_new (3)
returns valid pointer on success and
.B NULL
when error occurs.
.SH ERRORS
.PP
.BR el_oinit (3)
can return:
.TP
.B EINVAL
.I el
object is invalid (null).
.PP
.BR el_new (3)
can return:
.TP
.B ENOMEM
Not enough memory in the system to perform necessary memory allocations.
.SH EXAMPLE
.PP
Note: error handling has been ommited for clarity sake
.PP
.nf
    #include <embedlog.h>

    int main(void)
    {
        struct el  el, *elp;

        /* initialize default and two custom el objects */
        el_init();
        el_oinit(&el);
        elp = el_new();

        /* make el to print to file and stderr */
        el_ooption(&el, EL_OUT, EL_OUT_FILE | EL_OUT_STDERR);
        el_ooption(&el, EL_FPATH, "/tmp/test.log");

        /* print messages */
        el_print(ELI, "will print to stderr");
        el_oprint(ELI, &el, "will print to file /tmp/test.log and stderr");
        el_oprint(ELN, elp, "print to stderr");

        /* cleanup after any initialization code (like fopen) */
        el_destroy(elp);
        el_ocleanup(&el);
        el_cleanup();

        return 0;
    }
.fi
.SH SEE ALSO
.PP
.BR el_overview (7),
.BR el_cleanup (3),
.BR el_destroy (3),
.BR el_flush (3),
.BR el_ocleanup (3),
.BR el_oflush (3),
.BR el_ooption (3),
.BR el_operror (3),
.BR el_opmemory (3),
.BR el_opmemory_table (3),
.BR el_oprint (3),
.BR el_option (3),
.BR el_oputs (3),
.BR el_ovprint (3),
.BR el_perror (3),
.BR el_pmemory (3),
.BR el_pmemory_table (3),
.BR el_print (3),
.BR el_puts (3),
.BR el_vprint (3).