2011-02-10 13:47:08 +00:00
|
|
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
|
|
|
// vim: ts=8 sw=2 smarttab
|
|
|
|
/*
|
|
|
|
* Ceph - scalable distributed file system
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 New Dream Network
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software
|
|
|
|
* Foundation. See file COPYING.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-07 19:54:38 +00:00
|
|
|
#ifndef CEPH_SAFE_IO
|
|
|
|
#define CEPH_SAFE_IO
|
|
|
|
|
2011-06-27 22:07:57 +00:00
|
|
|
#include "common/compiler_extensions.h"
|
2012-02-17 17:14:56 +00:00
|
|
|
#include <sys/types.h>
|
2011-02-07 19:54:38 +00:00
|
|
|
|
2011-02-10 13:47:08 +00:00
|
|
|
#ifdef __cplusplus
|
2011-02-07 20:12:51 +00:00
|
|
|
extern "C" {
|
2011-02-10 13:47:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Safe functions wrapping the raw read() and write() libc functions.
|
|
|
|
* These retry on EINTR, and on error return -errno instead of returning
|
2011-06-17 17:18:32 +00:00
|
|
|
* -1 and setting errno).
|
2011-02-10 13:47:08 +00:00
|
|
|
*/
|
2011-02-10 14:02:46 +00:00
|
|
|
ssize_t safe_read(int fd, void *buf, size_t count)
|
2011-06-27 22:07:57 +00:00
|
|
|
WARN_UNUSED_RESULT;
|
2011-02-10 14:02:46 +00:00
|
|
|
ssize_t safe_write(int fd, const void *buf, size_t count)
|
2011-06-27 22:07:57 +00:00
|
|
|
WARN_UNUSED_RESULT;
|
2011-02-10 14:02:46 +00:00
|
|
|
ssize_t safe_pread(int fd, void *buf, size_t count, off_t offset)
|
2011-06-27 22:07:57 +00:00
|
|
|
WARN_UNUSED_RESULT;
|
2011-02-10 14:02:46 +00:00
|
|
|
ssize_t safe_pwrite(int fd, const void *buf, size_t count, off_t offset)
|
2011-06-27 22:07:57 +00:00
|
|
|
WARN_UNUSED_RESULT;
|
2011-02-10 13:47:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Same as the above functions, but return -EDOM unless exactly the requested
|
|
|
|
* number of bytes can be read.
|
|
|
|
*/
|
2011-02-10 14:02:46 +00:00
|
|
|
ssize_t safe_read_exact(int fd, void *buf, size_t count)
|
2011-06-27 22:07:57 +00:00
|
|
|
WARN_UNUSED_RESULT;
|
2011-02-10 14:02:46 +00:00
|
|
|
ssize_t safe_pread_exact(int fd, void *buf, size_t count, off_t offset)
|
2011-06-27 22:07:57 +00:00
|
|
|
WARN_UNUSED_RESULT;
|
2011-02-10 13:47:08 +00:00
|
|
|
|
2013-09-27 00:42:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Safe functions to read and write an entire file.
|
|
|
|
*/
|
|
|
|
int safe_write_file(const char *base, const char *file,
|
|
|
|
const char *val, size_t vallen);
|
|
|
|
int safe_read_file(const char *base, const char *file,
|
|
|
|
char *val, size_t vallen);
|
|
|
|
|
2011-02-10 13:47:08 +00:00
|
|
|
#ifdef __cplusplus
|
2011-02-07 19:54:38 +00:00
|
|
|
}
|
2011-02-10 13:47:08 +00:00
|
|
|
#endif
|
2011-02-07 19:54:38 +00:00
|
|
|
|
|
|
|
#endif
|