src/common: use single Makefile for parallel builds
[lttng-tools.git] / src / common / fs-handle.cpp
1 /*
2 * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #include <common/fs-handle-internal.h>
9 #include <common/fs-handle.h>
10 #include <common/readwrite.h>
11
12 int fs_handle_get_fd(struct fs_handle *handle)
13 {
14 return handle->get_fd(handle);
15 }
16
17 void fs_handle_put_fd(struct fs_handle *handle)
18 {
19 return handle->put_fd(handle);
20 }
21
22 int fs_handle_unlink(struct fs_handle *handle)
23 {
24 return handle->unlink(handle);
25 }
26
27 int fs_handle_close(struct fs_handle *handle)
28 {
29 return handle->close(handle);
30 }
31
32 ssize_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);
44 end:
45 return ret;
46 }
47
48 ssize_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);
60 end:
61 return ret;
62 }
63
64 int fs_handle_truncate(struct fs_handle *handle, off_t offset)
65 {
66 int 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 = ftruncate(fd, offset);
75 fs_handle_put_fd(handle);
76 end:
77 return ret;
78 }
79
80 off_t fs_handle_seek(struct fs_handle *handle, off_t offset, int whence)
81 {
82 off_t ret;
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);
92 end:
93 return ret;
94 }
This page took 0.031193 seconds and 4 git commands to generate.