lib: Pass in "strv_len" to strv_valid_entry
[samba.git] / lib / util / sys_rw.c
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
8  *
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.
13  *
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.
18  *
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/>.
21  */
22
23 #include "replace.h"
24 #include "system/filesys.h"
25 #include "lib/util/sys_rw.h"
26
27 /*******************************************************************
28 A read wrapper that will deal with EINTR/EWOULDBLOCK
29 ********************************************************************/
30
31 ssize_t sys_read(int fd, void *buf, size_t count)
32 {
33         ssize_t ret;
34
35         do {
36                 ret = read(fd, buf, count);
37         } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
38                                errno == EWOULDBLOCK));
39
40         return ret;
41 }
42
43 /**
44  * read wrapper, void variant:
45  * This is intended to be used as a void variant of
46  * read in situations where the caller wants to ignore
47  * the result. Hence not checking for EAGAIN|EWOULDBLOCK.
48  */
49 void sys_read_v(int fd, void *buf, size_t count)
50 {
51         ssize_t ret;
52
53         do {
54                 ret = read(fd, buf, count);
55         } while (ret == -1 && errno == EINTR);
56 }
57
58
59 /*******************************************************************
60 A write wrapper that will deal with EINTR/EWOULDBLOCK.
61 ********************************************************************/
62
63 ssize_t sys_write(int fd, const void *buf, size_t count)
64 {
65         ssize_t ret;
66
67         do {
68                 ret = write(fd, buf, count);
69         } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
70                                errno == EWOULDBLOCK));
71
72         return ret;
73 }
74
75 /**
76  * write wrapper to deal with EINTR and friends.
77  * void-variant that ignores the number of bytes written.
78  * This is intended to be used as a void variant of
79  * write in situations where the caller wants to ignore
80  * the result. Hence not checking for EAGAIN|EWOULDBLOCK.
81  */
82 void sys_write_v(int fd, const void *buf, size_t count)
83 {
84         ssize_t ret;
85
86         do {
87                 ret = write(fd, buf, count);
88         } while (ret == -1 && errno == EINTR);
89 }
90
91
92 /*******************************************************************
93 A writev wrapper that will deal with EINTR.
94 ********************************************************************/
95
96 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
97 {
98         ssize_t ret;
99
100         do {
101                 ret = writev(fd, iov, iovcnt);
102         } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
103                                errno == EWOULDBLOCK));
104
105         return ret;
106 }
107
108 /*******************************************************************
109 A pread wrapper that will deal with EINTR
110 ********************************************************************/
111
112 ssize_t sys_pread(int fd, void *buf, size_t count, off_t off)
113 {
114         ssize_t ret;
115
116         do {
117                 ret = pread(fd, buf, count, off);
118         } while (ret == -1 && errno == EINTR);
119         return ret;
120 }
121
122 /*******************************************************************
123 A write wrapper that will deal with EINTR
124 ********************************************************************/
125
126 ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off)
127 {
128         ssize_t ret;
129
130         do {
131                 ret = pwrite(fd, buf, count, off);
132         } while (ret == -1 && errno == EINTR);
133         return ret;
134 }