]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/safe_io.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / safe_io.h
CommitLineData
7c673cae
FG
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
7c673cae
FG
18#include "common/compiler_extensions.h"
19#include <sys/types.h>
20
21#ifdef __cplusplus
22extern "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).
f67539c2
TL
29 *
30 * On Windows, only recv/send work with sockets.
7c673cae
FG
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;
f67539c2
TL
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;
7c673cae
FG
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;
f67539c2
TL
63 ssize_t safe_recv_exact(int fd, void *buf, size_t count)
64 WARN_UNUSED_RESULT;
7c673cae
FG
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,
eafe8130
TL
73 const char *val, size_t vallen,
74 unsigned mode);
7c673cae 75 int safe_read_file(const char *base, const char *file,
eafe8130 76 char *val, size_t vallen);
7c673cae
FG
77
78#ifdef __cplusplus
79}
80#endif
81
82#endif