write_file does not allow incomplete writes. It loops internally * until len bytes are written or errno is set. Note that use_seek and * offset are only used in sparse processing (see write_sparse()). */
| 147 | * until len bytes are written or errno is set. Note that use_seek and |
| 148 | * offset are only used in sparse processing (see write_sparse()). */ |
| 149 | int write_file(int f, int use_seek, OFF_T offset, const char *buf, int len) |
| 150 | { |
| 151 | int ret = 0; |
| 152 | |
| 153 | while (len > 0) { |
| 154 | int r1; |
| 155 | if (sparse_files > 0) { |
| 156 | int len1 = MIN(len, SPARSE_WRITE_SIZE); |
| 157 | r1 = write_sparse(f, use_seek, offset, buf, len1); |
| 158 | offset += r1; |
| 159 | } else { |
| 160 | if (!wf_writeBuf) { |
| 161 | wf_writeBufSize = WRITE_SIZE * 8; |
| 162 | wf_writeBufCnt = 0; |
| 163 | wf_writeBuf = new_array(char, wf_writeBufSize); |
| 164 | } |
| 165 | r1 = (int)MIN((size_t)len, wf_writeBufSize - wf_writeBufCnt); |
| 166 | if (r1) { |
| 167 | memcpy(wf_writeBuf + wf_writeBufCnt, buf, r1); |
| 168 | wf_writeBufCnt += r1; |
| 169 | } |
| 170 | if (wf_writeBufCnt == wf_writeBufSize) { |
| 171 | if (flush_write_file(f) < 0) |
| 172 | return -1; |
| 173 | if (!r1 && len) |
| 174 | continue; |
| 175 | } |
| 176 | } |
| 177 | if (r1 <= 0) { |
| 178 | if (ret > 0) |
| 179 | return ret; |
| 180 | return r1; |
| 181 | } |
| 182 | len -= r1; |
| 183 | buf += r1; |
| 184 | ret += r1; |
| 185 | } |
| 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | /* An in-place update found identical data at an identical location. We either |
| 190 | * just seek past it, or (for an in-place sparse update), we give the data to |
no test coverage detected