]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/safe_io.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / common / safe_io.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_SAFE_IO
16 #define CEPH_SAFE_IO
17
18 #include "common/compiler_extensions.h"
19 #include <sys/types.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /*
26 * Safe functions wrapping the raw read() and write() libc functions.
27 * These retry on EINTR, and on error return -errno instead of returning
28 * -1 and setting errno).
29 *
30 * On Windows, only recv/send work with sockets.
31 */
32 ssize_t safe_read(int fd, void *buf, size_t count)
33 WARN_UNUSED_RESULT;
34 ssize_t safe_write(int fd, const void *buf, size_t count)
35 WARN_UNUSED_RESULT;
36 ssize_t safe_recv(int fd, void *buf, size_t count)
37 WARN_UNUSED_RESULT;
38 ssize_t safe_send(int fd, const void *buf, size_t count)
39 WARN_UNUSED_RESULT;
40 ssize_t safe_pread(int fd, void *buf, size_t count, off_t offset)
41 WARN_UNUSED_RESULT;
42 ssize_t safe_pwrite(int fd, const void *buf, size_t count, off_t offset)
43 WARN_UNUSED_RESULT;
44 #ifdef CEPH_HAVE_SPLICE
45 /*
46 * Similar to the above (non-exact version) and below (exact version).
47 * See splice(2) for parameter descriptions.
48 */
49 ssize_t safe_splice(int fd_in, off_t *off_in, int fd_out, off_t *off_out,
50 size_t len, unsigned int flags)
51 WARN_UNUSED_RESULT;
52 ssize_t safe_splice_exact(int fd_in, off_t *off_in, int fd_out,
53 off_t *off_out, size_t len, unsigned int flags)
54 WARN_UNUSED_RESULT;
55 #endif
56
57 /*
58 * Same as the above functions, but return -EDOM unless exactly the requested
59 * number of bytes can be read.
60 */
61 ssize_t safe_read_exact(int fd, void *buf, size_t count)
62 WARN_UNUSED_RESULT;
63 ssize_t safe_recv_exact(int fd, void *buf, size_t count)
64 WARN_UNUSED_RESULT;
65 ssize_t safe_pread_exact(int fd, void *buf, size_t count, off_t offset)
66 WARN_UNUSED_RESULT;
67
68
69 /*
70 * Safe functions to read and write an entire file.
71 */
72 int safe_write_file(const char *base, const char *file,
73 const char *val, size_t vallen,
74 unsigned mode);
75 int safe_read_file(const char *base, const char *file,
76 char *val, size_t vallen);
77
78 #ifdef __cplusplus
79 }
80 #endif
81
82 #endif