docs: Add supported versions and fix-backport policy
[lttng-tools.git] / src / common / fs-handle.cpp
CommitLineData
f5ea0241 1/*
ab5be9fa 2 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
f5ea0241 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
f5ea0241 5 *
f5ea0241
JG
6 */
7
c9e313bc
SM
8#include <common/fs-handle-internal.hpp>
9#include <common/fs-handle.hpp>
10#include <common/readwrite.hpp>
f5ea0241 11
f5ea0241
JG
12int fs_handle_get_fd(struct fs_handle *handle)
13{
14 return handle->get_fd(handle);
15}
16
f5ea0241
JG
17void fs_handle_put_fd(struct fs_handle *handle)
18{
19 return handle->put_fd(handle);
20}
21
f5ea0241
JG
22int fs_handle_unlink(struct fs_handle *handle)
23{
24 return handle->unlink(handle);
25}
26
f5ea0241
JG
27int fs_handle_close(struct fs_handle *handle)
28{
29 return handle->close(handle);
30}
8bb66c3c 31
8bb66c3c
JG
32ssize_t fs_handle_read(struct fs_handle *handle, void *buf, size_t count)
33{
34 ssize_t ret;
35 const int fd = fs_handle_get_fd(handle);
36
37 if (fd < 0) {
38 ret = -1;
39 goto end;
40 }
41
42 ret = lttng_read(fd, buf, count);
43 fs_handle_put_fd(handle);
44end:
45 return ret;
46}
47
8bb66c3c
JG
48ssize_t fs_handle_write(struct fs_handle *handle, const void *buf, size_t count)
49{
50 ssize_t ret;
51 const int fd = fs_handle_get_fd(handle);
52
53 if (fd < 0) {
54 ret = -1;
55 goto end;
56 }
57
58 ret = lttng_write(fd, buf, count);
59 fs_handle_put_fd(handle);
60end:
61 return ret;
62}
63
8bb66c3c
JG
64int fs_handle_truncate(struct fs_handle *handle, off_t offset)
65{
3e778ab0 66 int ret;
8bb66c3c
JG
67 const int fd = fs_handle_get_fd(handle);
68
69 if (fd < 0) {
70 ret = -1;
71 goto end;
72 }
73
74 ret = ftruncate(fd, offset);
75 fs_handle_put_fd(handle);
76end:
77 return ret;
78}
79
3e778ab0 80off_t fs_handle_seek(struct fs_handle *handle, off_t offset, int whence)
8bb66c3c 81{
3e778ab0 82 off_t ret;
8bb66c3c
JG
83 const int fd = fs_handle_get_fd(handle);
84
85 if (fd < 0) {
86 ret = -1;
87 goto end;
88 }
89
90 ret = lseek(fd, offset, whence);
91 fs_handle_put_fd(handle);
92end:
93 return ret;
94}
This page took 0.056413 seconds and 4 git commands to generate.