Created
December 16, 2013 00:41
-
-
Save hfm/7980643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <sys/types.h> | |
| #include <sys/stat.h> | |
| #include <fcntl.h> | |
| #include <string.h> | |
| #include <sys/uio.h> | |
| #include <unistd.h> | |
| int main() | |
| { | |
| struct iovec iov[3]; | |
| ssize_t nr; | |
| int fd, i; | |
| char *buf[] = { | |
| "hello world.\n", | |
| "alice in wonderland.\n" | |
| "twitter.\n" | |
| }; | |
| fd = open("sample_writev.txt", O_WRONLY | O_CREAT | O_TRUNC); | |
| if (fd == -1) { | |
| perror("open"); | |
| return 1; | |
| } | |
| for (i = 0; i < 3; i++) { | |
| iov[i].iov_base = buf[i]; | |
| iov[i].iov_len = strlen(buf[i]); | |
| } | |
| nr = writev(fd, iov, 3); | |
| if (nr == -1) { | |
| perror("writev"); | |
| return 1; | |
| } | |
| printf("wrote %zd bytes\n", nr); | |
| if (close(fd)) { | |
| perror("close"); | |
| return 1; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment