1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <[email protected]>
4 *
5 */
6 #ifndef _TRACE_WRITE_LOCAL_H
7 #define _TRACE_WRITE_LOCAL_H
8
9 /* Local for trace-input.c, trace-output.c and trace-msg.c */
10
__do_write(int fd,const void * data,size_t size)11 static inline ssize_t __do_write(int fd, const void *data, size_t size)
12 {
13 ssize_t tot = 0;
14 ssize_t w;
15
16 do {
17 w = write(fd, data + tot, size - tot);
18 tot += w;
19
20 if (!w)
21 break;
22 if (w < 0)
23 return w;
24 } while (tot != size);
25
26 return tot;
27 }
28
29 static inline ssize_t
__do_write_check(int fd,const void * data,size_t size)30 __do_write_check(int fd, const void *data, size_t size)
31 {
32 ssize_t ret;
33
34 ret = __do_write(fd, data, size);
35 if (ret < 0)
36 return ret;
37 if (ret != size)
38 return -1;
39
40 return 0;
41 }
42
43 #endif /* _TRACE_WRITE_LOCAL_H */
44