wrappers-io.hc (2192B)
1 // $Id$ --*- c -*-- 2 3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; version 2 of the License. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 19 #ifndef H_ENSC_IN_WRAPPERS_H 20 # error wrappers_handler.hc can not be used in this way 21 #endif 22 23 #include <stdbool.h> 24 25 inline static UNUSED bool 26 WwriteAll(int fd, void const *ptr_v, size_t len, int *err) 27 { 28 register char const *ptr = ptr_v; 29 30 if (err) *err = 0; 31 32 while (len>0) { 33 ssize_t res = TEMP_FAILURE_RETRY(write(fd, ptr, len)); 34 if (res<=0) { 35 if (err) *err = errno; 36 return false; 37 } 38 39 ptr += res; 40 len -= res; 41 } 42 return true; 43 } 44 45 inline static UNUSED void 46 EwriteAll(int fd, void const *ptr_v, size_t len) 47 { 48 register char const *ptr = ptr_v; 49 50 while (len>0) { 51 ssize_t res = TEMP_FAILURE_RETRY(write(fd, ptr, len)); 52 FatalErrnoError(res==-1, "write()"); 53 54 ptr += res; 55 len -= res; 56 } 57 } 58 59 60 inline static UNUSED bool 61 WreadAll(int fd, void *ptr_v, size_t len, int *err) 62 { 63 register char *ptr = ptr_v; 64 65 if (err) *err = 0; 66 67 while (len>0) { 68 ssize_t res = TEMP_FAILURE_RETRY(read(fd, ptr, len)); 69 if (res==-1) { 70 if (err) *err = errno; 71 return false; 72 } 73 74 if (res==0) return false; 75 76 ptr += res; 77 len -= res; 78 } 79 return true; 80 } 81 82 inline static UNUSED bool 83 EreadAll(int fd, void *ptr_v, size_t len) 84 { 85 register char *ptr = ptr_v; 86 87 while (len>0) { 88 ssize_t res = TEMP_FAILURE_RETRY(read(fd, ptr, len)); 89 FatalErrnoError(res==-1, "read()"); 90 91 if (res==0) return false; 92 93 ptr += res; 94 len -= res; 95 } 96 97 return true; 98 }