]>
git.proxmox.com Git - ceph.git/blob - 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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
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.
18 #include "common/compiler_extensions.h"
19 #include <sys/types.h>
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).
30 * On Windows, only recv/send work with sockets.
32 ssize_t
safe_read(int fd
, void *buf
, size_t count
)
34 ssize_t
safe_write(int fd
, const void *buf
, size_t count
)
36 ssize_t
safe_recv(int fd
, void *buf
, size_t count
)
38 ssize_t
safe_send(int fd
, const void *buf
, size_t count
)
40 ssize_t
safe_pread(int fd
, void *buf
, size_t count
, off_t offset
)
42 ssize_t
safe_pwrite(int fd
, const void *buf
, size_t count
, off_t offset
)
44 #ifdef CEPH_HAVE_SPLICE
46 * Similar to the above (non-exact version) and below (exact version).
47 * See splice(2) for parameter descriptions.
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
)
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
)
58 * Same as the above functions, but return -EDOM unless exactly the requested
59 * number of bytes can be read.
61 ssize_t
safe_read_exact(int fd
, void *buf
, size_t count
)
63 ssize_t
safe_recv_exact(int fd
, void *buf
, size_t count
)
65 ssize_t
safe_pread_exact(int fd
, void *buf
, size_t count
, off_t offset
)
70 * Safe functions to read and write an entire file.
72 int safe_write_file(const char *base
, const char *file
,
73 const char *val
, size_t vallen
,
75 int safe_read_file(const char *base
, const char *file
,
76 char *val
, size_t vallen
);