Sync ax_have_epoll.m4 with autoconf-archive
[lttng-tools.git] / src / common / fs-handle.c
1 /*
2 * Copyright (C) 2020 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by the
6 * Free Software Foundation; version 2.1 of the License.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #include <common/fs-handle-internal.h>
19 #include <common/fs-handle.h>
20 #include <common/readwrite.h>
21
22 LTTNG_HIDDEN
23 int fs_handle_get_fd(struct fs_handle *handle)
24 {
25 return handle->get_fd(handle);
26 }
27
28 LTTNG_HIDDEN
29 void fs_handle_put_fd(struct fs_handle *handle)
30 {
31 return handle->put_fd(handle);
32 }
33
34 LTTNG_HIDDEN
35 int fs_handle_unlink(struct fs_handle *handle)
36 {
37 return handle->unlink(handle);
38 }
39
40 LTTNG_HIDDEN
41 int fs_handle_close(struct fs_handle *handle)
42 {
43 return handle->close(handle);
44 }
45
46 LTTNG_HIDDEN
47 ssize_t fs_handle_read(struct fs_handle *handle, void *buf, size_t count)
48 {
49 ssize_t ret;
50 const int fd = fs_handle_get_fd(handle);
51
52 if (fd < 0) {
53 ret = -1;
54 goto end;
55 }
56
57 ret = lttng_read(fd, buf, count);
58 fs_handle_put_fd(handle);
59 end:
60 return ret;
61 }
62
63 LTTNG_HIDDEN
64 ssize_t fs_handle_write(struct fs_handle *handle, const void *buf, size_t count)
65 {
66 ssize_t ret;
67 const int fd = fs_handle_get_fd(handle);
68
69 if (fd < 0) {
70 ret = -1;
71 goto end;
72 }
73
74 ret = lttng_write(fd, buf, count);
75 fs_handle_put_fd(handle);
76 end:
77 return ret;
78 }
79
80 LTTNG_HIDDEN
81 int fs_handle_truncate(struct fs_handle *handle, off_t offset)
82 {
83 int ret;
84 const int fd = fs_handle_get_fd(handle);
85
86 if (fd < 0) {
87 ret = -1;
88 goto end;
89 }
90
91 ret = ftruncate(fd, offset);
92 fs_handle_put_fd(handle);
93 end:
94 return ret;
95 }
96
97 LTTNG_HIDDEN
98 int fs_handle_seek(struct fs_handle *handle, off_t offset, int whence)
99 {
100 int ret;
101 const int fd = fs_handle_get_fd(handle);
102
103 if (fd < 0) {
104 ret = -1;
105 goto end;
106 }
107
108 ret = lseek(fd, offset, whence);
109 fs_handle_put_fd(handle);
110 end:
111 return ret;
112 }
This page took 0.031136 seconds and 4 git commands to generate.