Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. void write_cont_blocks(char *filename)
  2. {
  3. struct iovec iov[4];
  4. struct s1 one;
  5. struct s2 two;
  6. int three;
  7. float four;
  8.  
  9. int num_written;
  10.  
  11. int fd = open(filename, O_RDONLY);
  12. if (fd == -1) {
  13. printf("Error opening file: %s\n", filename);
  14. printf("Error: %s\n", strerror(errno));
  15. return;
  16. }
  17.  
  18. // Manipulate the buffers to hold info
  19.  
  20. // Build buffers to write
  21. iov[0].iov_base = &one;
  22. iov[0].iov_len = sizeof(struct s1);
  23.  
  24. iov[1].iov_base = &two;
  25. iov[1].iov_len = sizeof(struct s2);
  26.  
  27. iov[2].iov_base = &three;
  28. iov[2].iov_len = sizeof(three);
  29.  
  30. iov[3].iov_base = &four;
  31. iov[3].iov_len = sizeof(four);
  32.  
  33. num_written = writev(fd, iov, 4);
  34. if (num_written == -1) {
  35. printf("Error reading file: %s\n", filename);
  36. printf("Error: %s\n", strerror(errno));
  37. }
  38.  
  39. close(fd);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement