fullrw.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "fspr_file_io.h"
  17. APR_DECLARE(fspr_status_t) fspr_file_read_full(fspr_file_t *thefile, void *buf,
  18. fspr_size_t nbytes,
  19. fspr_size_t *bytes_read)
  20. {
  21. fspr_status_t status;
  22. fspr_size_t total_read = 0;
  23. do {
  24. fspr_size_t amt = nbytes;
  25. status = fspr_file_read(thefile, buf, &amt);
  26. buf = (char *)buf + amt;
  27. nbytes -= amt;
  28. total_read += amt;
  29. } while (status == APR_SUCCESS && nbytes > 0);
  30. if (bytes_read != NULL)
  31. *bytes_read = total_read;
  32. return status;
  33. }
  34. APR_DECLARE(fspr_status_t) fspr_file_write_full(fspr_file_t *thefile,
  35. const void *buf,
  36. fspr_size_t nbytes,
  37. fspr_size_t *bytes_written)
  38. {
  39. fspr_status_t status;
  40. fspr_size_t total_written = 0;
  41. do {
  42. fspr_size_t amt = nbytes;
  43. status = fspr_file_write(thefile, buf, &amt);
  44. buf = (char *)buf + amt;
  45. nbytes -= amt;
  46. total_written += amt;
  47. } while (status == APR_SUCCESS && nbytes > 0);
  48. if (bytes_written != NULL)
  49. *bytes_written = total_written;
  50. return status;
  51. }
  52. APR_DECLARE(fspr_status_t) fspr_file_writev_full(fspr_file_t *thefile,
  53. const struct iovec *vec,
  54. fspr_size_t nvec,
  55. fspr_size_t *bytes_written)
  56. {
  57. fspr_status_t rv = APR_SUCCESS;
  58. fspr_size_t i;
  59. fspr_size_t amt = 0;
  60. fspr_size_t total = 0;
  61. for (i = 0; i < nvec && rv == APR_SUCCESS; i++) {
  62. rv = fspr_file_write_full(thefile, vec[i].iov_base,
  63. vec[i].iov_len, &amt);
  64. total += amt;
  65. }
  66. if (bytes_written != NULL)
  67. *bytes_written = total;
  68. return rv;
  69. }