iovecs don't print right
- From: nobody+cplusplus <nobody@xxxxxxxxxxxxxxxx>
- Date: Sat, 05 Jul 2008 03:51:06 +0930
Hi all,
Below is coded on linux. If you need specifics let me know. But the output
is all messed up.
//file revup.txt
Alpha centauri.
Centauri alpha.
pomato
//end revup.txt
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <unistd.h>
int main ( )
{
char a[16], b[16], c[7];
struct iovec iov[3];
ssize_t nr;
int fd, i;
fd = open ("revup.txt", O_RDONLY);
if (fd == -1) {
perror ("open");
return 1;
}
/* set up our iovec structures */
iov[0].iov_base = a;
iov[0].iov_len = sizeof (a);
iov[1].iov_base = b;
iov[1].iov_len = sizeof (b);
iov[2].iov_base = c;
iov[2].iov_len = sizeof (c);
/* read into the structures with a single call */
nr = readv (fd, iov, 3);
if (nr == -1) {
perror ("readv");
return 1;
}
for (i = 0; i < 3; i++){
printf ("len %d, %d: %s \n", (int) iov[i].iov_len, i, (char *) \
iov[i].iov_base );
}
if (close (fd)) {
perror ("close");
return 1;
}
return 0;
}
//output with
$ gcc -Wall vectoredIORead.c -o vectoredIORead
$ ./vectoredIORead
len 16, 0: Alpha centauri.
len 16, 1: Centauri alpha.
Alpha centauri.
len 7, 2: pomato
//end of output
It is a bit weird since "Alpha centauri" is being printed twice and that too
in iov[1]!!?? What wrong am i doing here? :/
Appreciate your help.
--
thanks
.
- Follow-Ups:
- Re: iovecs don't print right
- From: phil-news-nospam
- Re: iovecs don't print right
- From: Stephane CHAZELAS
- Re: iovecs don't print right
- Prev by Date: Re: dlopen dumps
- Next by Date: Re: iovecs don't print right
- Previous by thread: dlopen dumps
- Next by thread: Re: iovecs don't print right
- Index(es):