commit - fe53745c681607c82e450b8fde054420e267601b
commit + 344e474767f52e48fa8b238638b9507b2002f4d4
blob - d7501b5e7528fb846445be4afe893a956ec346a6
blob + 7dba862a0feb7f94085895c18ed8b65612694135
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
return NULL;
}
-static int
+static const struct got_error *
writepkt(int fd, char *buf, int nbuf)
{
char len[5];
int i;
+ ssize_t w;
if (snprintf(len, sizeof(len), "%04x", nbuf + 4) >= sizeof(len))
- return -1;
- if (write(fd, len, 4) != 4)
- return -1;
- if (write(fd, buf, nbuf) != nbuf)
- return -1;
+ return got_error(GOT_ERR_NO_SPACE);
+ w = write(fd, len, 4);
+ if (w == -1)
+ return got_error_from_errno("write");
+ if (w != 4)
+ return got_error(GOT_ERR_IO);
+ w = write(fd, buf, nbuf);
+ if (w == -1)
+ return got_error_from_errno("write");
+ if (w != nbuf)
+ return got_error(GOT_ERR_IO);
if (chattygit) {
fprintf(stderr, "writepkt: %s:\t", len);
fwrite(buf, 1, nbuf, stderr);
}
fputc('\n', stderr);
}
- return 0;
+ return NULL;
}
static const struct got_error *
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
- if (writepkt(fd, buf, n) == -1) {
- err = got_error_from_errno("writepkt");
+ err = writepkt(fd, buf, n);
+ if (err)
goto done;
- }
req = 1;
}
flushpkt(fd);
err = got_error(GOT_ERR_NO_SPACE);
goto done;
}
- if (writepkt(fd, buf, n + 1) == -1) {
- err = got_error_from_errno("writepkt");
+ err = writepkt(fd, buf, n + 1);
+ if (err)
goto done;
- }
}
if (!req) {
fprintf(stderr, "up to date\n");
flushpkt(fd);
}
n = snprintf(buf, sizeof(buf), "done\n");
- if (writepkt(fd, buf, n) == -1) {
- err = got_error_from_errno("writepkt");
+ err = writepkt(fd, buf, n);
+ if (err)
goto done;
- }
if (!req)
return 0;