Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 364 #define READ_WRITE_EXACTLY(rw, zero_is_eof, constdata) \
- 365 \
- 366 int libxl_##rw##_exactly(libxl_ctx *ctx, int fd, \
- 367 constdata void *data, ssize_t sz, \
- 368 const char *source, const char *what) { \
- 369 GC_INIT(ctx); \
- 370 ssize_t got; \
- 371 int ret = 0; \
- 372 \
- 373 while (sz > 0) { \
- 374 got = rw(fd, data, sz); \
- 375 if (got == -1) { \
- 376 if (errno == EINTR) continue; \
- 377 if (!ctx) \
- 378 { \
- 379 ret = errno; \
- 380 goto out; \
- 381 } \
- 382 LOGE(ERROR, "failed to " #rw " %s%s%s", \
- 383 what?what:"", what?" from ":"", source); \
- 384 ret = errno; \
- 385 goto out; \
- 386 } \
- 387 if (got == 0) { \
- 388 if (!ctx) \
- 389 { \
- 390 ret = EPROTO; \
- 391 goto out; \
- 392 } \
- 393 LOG(ERROR, \
- 394 zero_is_eof \
- 395 ? "file/stream truncated reading %s%s%s" \
- 396 : "file/stream write returned 0! writing %s%s%s", \
- 397 what?what:"", what?" from ":"", source); \
- 398 ret = EPROTO; \
- 399 goto out; \
- 400 } \
- 401 sz -= got; \
- 402 data = (char*)data + got; \
- 403 } \
- 404 return 0; \
- 405 \
- 406 out: \
- 407 GC_FREE; \
- 408 return ret; \
- 409 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement