nfs4acls: Introduce a helper variable
[Samba.git] / source3 / lib / sys_rw.c
blob6d8f149f1ce7f383444b2396fb65ef86cdd7f43c
1 /*
2 * Unix SMB/CIFS implementation.
3 * Samba system utilities
4 * Copyright (C) Andrew Tridgell 1992-1998
5 * Copyright (C) Jeremy Allison 1998-2005
6 * Copyright (C) Timur Bakeyev 2005
7 * Copyright (C) Bjoern Jacke 2006-2007
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "replace.h"
24 #include "system/filesys.h"
25 #include "lib/sys_rw.h"
27 /*******************************************************************
28 A read wrapper that will deal with EINTR/EWOULDBLOCK
29 ********************************************************************/
31 ssize_t sys_read(int fd, void *buf, size_t count)
33 ssize_t ret;
35 do {
36 ret = read(fd, buf, count);
37 } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
38 errno == EWOULDBLOCK));
40 return ret;
43 /*******************************************************************
44 A write wrapper that will deal with EINTR/EWOULDBLOCK.
45 ********************************************************************/
47 ssize_t sys_write(int fd, const void *buf, size_t count)
49 ssize_t ret;
51 do {
52 ret = write(fd, buf, count);
53 } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
54 errno == EWOULDBLOCK));
56 return ret;
59 /*******************************************************************
60 A writev wrapper that will deal with EINTR.
61 ********************************************************************/
63 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
65 ssize_t ret;
67 do {
68 ret = writev(fd, iov, iovcnt);
69 } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
70 errno == EWOULDBLOCK));
72 return ret;
75 /*******************************************************************
76 A pread wrapper that will deal with EINTR
77 ********************************************************************/
79 ssize_t sys_pread(int fd, void *buf, size_t count, off_t off)
81 ssize_t ret;
83 do {
84 ret = pread(fd, buf, count, off);
85 } while (ret == -1 && errno == EINTR);
86 return ret;
89 /*******************************************************************
90 A write wrapper that will deal with EINTR
91 ********************************************************************/
93 ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off)
95 ssize_t ret;
97 do {
98 ret = pwrite(fd, buf, count, off);
99 } while (ret == -1 && errno == EINTR);
100 return ret;