Advertisement
kelleynnn

Skanky READ_WRITE_EXACTLY fix

Nov 11th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. 364 #define READ_WRITE_EXACTLY(rw, zero_is_eof, constdata) \
  2. 365 \
  3. 366 int libxl_##rw##_exactly(libxl_ctx *ctx, int fd, \
  4. 367 constdata void *data, ssize_t sz, \
  5. 368 const char *source, const char *what) { \
  6. 369 GC_INIT(ctx); \
  7. 370 ssize_t got; \
  8. 371 int ret = 0; \
  9. 372 \
  10. 373 while (sz > 0) { \
  11. 374 got = rw(fd, data, sz); \
  12. 375 if (got == -1) { \
  13. 376 if (errno == EINTR) continue; \
  14. 377 if (!ctx) \
  15. 378 { \
  16. 379 ret = errno; \
  17. 380 goto out; \
  18. 381 } \
  19. 382 LOGE(ERROR, "failed to " #rw " %s%s%s", \
  20. 383 what?what:"", what?" from ":"", source); \
  21. 384 ret = errno; \
  22. 385 goto out; \
  23. 386 } \
  24. 387 if (got == 0) { \
  25. 388 if (!ctx) \
  26. 389 { \
  27. 390 ret = EPROTO; \
  28. 391 goto out; \
  29. 392 } \
  30. 393 LOG(ERROR, \
  31. 394 zero_is_eof \
  32. 395 ? "file/stream truncated reading %s%s%s" \
  33. 396 : "file/stream write returned 0! writing %s%s%s", \
  34. 397 what?what:"", what?" from ":"", source); \
  35. 398 ret = EPROTO; \
  36. 399 goto out; \
  37. 400 } \
  38. 401 sz -= got; \
  39. 402 data = (char*)data + got; \
  40. 403 } \
  41. 404 return 0; \
  42. 405 \
  43. 406 out: \
  44. 407 GC_FREE; \
  45. 408 return ret; \
  46. 409 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement