| 1096 | bytes read if successful, -1 (setting errno) on failure. */ |
| 1097 | |
| 1098 | static ssize_t |
| 1099 | iread (int fd, char *buf, idx_t size) |
| 1100 | { |
| 1101 | ssize_t nread; |
| 1102 | static ssize_t prev_nread; |
| 1103 | |
| 1104 | do |
| 1105 | { |
| 1106 | process_signals (); |
| 1107 | nread = read (fd, buf, size); |
| 1108 | /* Ignore final read error with iflag=direct as that |
| 1109 | returns EINVAL due to the non aligned file offset. */ |
| 1110 | if (nread == -1 && errno == EINVAL |
| 1111 | && 0 < prev_nread && prev_nread < size |
| 1112 | && (input_flags & O_DIRECT)) |
| 1113 | { |
| 1114 | errno = 0; |
| 1115 | nread = 0; |
| 1116 | } |
| 1117 | } |
| 1118 | while (nread < 0 && errno == EINTR); |
| 1119 | |
| 1120 | /* Short read may be due to received signal. */ |
| 1121 | if (0 < nread && nread < size) |
| 1122 | process_signals (); |
| 1123 | |
| 1124 | if (0 < nread && warn_partial_read) |
| 1125 | { |
| 1126 | if (0 < prev_nread && prev_nread < size) |
| 1127 | { |
| 1128 | idx_t prev = prev_nread; |
| 1129 | if (status_level != STATUS_NONE) |
| 1130 | diagnose (0, ngettext (("warning: partial read (%td byte); " |
| 1131 | "suggest iflag=fullblock"), |
| 1132 | ("warning: partial read (%td bytes); " |
| 1133 | "suggest iflag=fullblock"), |
| 1134 | select_plural (prev)), |
| 1135 | prev); |
| 1136 | warn_partial_read = false; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | prev_nread = nread; |
| 1141 | return nread; |
| 1142 | } |
| 1143 | |
| 1144 | /* Wrapper around iread function to accumulate full blocks. */ |
| 1145 | static ssize_t |
no test coverage detected