-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathjsonl.c
More file actions
42 lines (35 loc) · 760 Bytes
/
jsonl.c
File metadata and controls
42 lines (35 loc) · 760 Bytes
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
/*
* JSON-Lines sink -- see include/jsonl.h.
*
* Deliberately free-standing: only libc open/write/close. This is the
* first telemetry pipe brought up during a fuzz run, so it cannot
* depend on trinity's output(), shm, or logging infrastructure.
*/
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "jsonl.h"
int jsonl_open(const char *path)
{
return open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
}
void jsonl_write(int fd, const char *json_line)
{
size_t len;
ssize_t ret;
if (fd < 0 || json_line == NULL)
return;
len = strlen(json_line);
if (len > 0) {
ret = write(fd, json_line, len);
(void)ret;
}
ret = write(fd, "\n", 1);
(void)ret;
}
void jsonl_close(int fd)
{
if (fd < 0)
return;
(void)close(fd);
}