1 /**
2 * collectd - src/utils_tail.h
3 * Copyright (C) 2007-2008 C-Ware, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Author:
24 * Luke Heberling <lukeh at c-ware.com>
25 *
26 * DESCRIPTION
27 * Facilitates reading information that is appended to a file, taking into
28 * account that the file may be rotated and a new file created under the
29 * same name.
30 **/
32 #ifndef UTILS_TAIL_H
33 #define UTILS_TAIL_H 1
35 struct cu_tail_s;
36 typedef struct cu_tail_s cu_tail_t;
38 typedef int tailfunc_t(void *data, char *buf, int buflen);
40 /*
41 * NAME
42 * cu_tail_create
43 *
44 * DESCRIPTION
45 * Allocates a new tail object..
46 *
47 * PARAMETERS
48 * `file' The name of the file to be tailed.
49 */
50 cu_tail_t *cu_tail_create (const char *file);
52 /*
53 * cu_tail_destroy
54 *
55 * Takes a tail object returned by `cu_tail_create' and destroys it, freeing
56 * all internal memory.
57 *
58 * Returns 0 when successful and non-zero otherwise.
59 */
60 int cu_tail_destroy (cu_tail_t *obj);
62 /*
63 * cu_tail_readline
64 *
65 * Reads from the file until `buflen' characters are read, a newline
66 * character is read, or an eof condition is encountered. `buf' is
67 * always null-terminated on successful return and isn't touched when non-zero
68 * is returned.
69 *
70 * You can check if the EOF condition is reached by looking at the buffer: If
71 * the length of the string stored in the buffer is zero, EOF occurred.
72 * Otherwise at least the newline character will be in the buffer.
73 *
74 * Returns 0 when successful and non-zero otherwise.
75 */
76 int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen);
78 /*
79 * cu_tail_readline
80 *
81 * Reads from the file until eof condition or an error is encountered.
82 *
83 * Returns 0 when successful and non-zero otherwise.
84 */
85 int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
86 void *data);
88 #endif /* UTILS_TAIL_H */