|
Prev: Why do I get an extra return in thie following case?
Next: Solaris 5.10 cpu hike --- _flockget --- possible deadlock?
From: nobody+cplusplus on 4 Jul 2008 14:21 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
From: Stephane CHAZELAS on 4 Jul 2008 14:46 2008-07-05, 03:51(+09), nobody+cplusplus: [...] > printf ("len %d, %d: %s \n", (int) iov[i].iov_len, i, (char *) \ > iov[i].iov_base ); [...] > What wrong am i doing here? :/ [...] You're using printf("%s") on something that is not a zero-terminated string. -- St�phane
From: phil-news-nospam on 4 Jul 2008 15:10 On Sat, 05 Jul 2008 03:51:06 +0930 nobody+cplusplus <nobody(a)discodance.id.au> wrote: | Below is coded on linux. If you need specifics let me know. But the output | is all messed up. Not knowing what the original requirements are, how would we know just what is wrong? Someone could write some code that does all kinds of goofy things, then copy the actual results and claim them to be the requirements, and have what appears to be a correct implementation of goofy requirements. FYI, I have had goofy project handed to me by an incapable manager. So I know what it's like. [code snipped] -- |WARNING: Due to extreme spam, googlegroups.com is blocked. Due to ignorance | | by the abuse department, bellsouth.net is blocked. If you post to | | Usenet from these places, find another Usenet provider ASAP. | | Phil Howard KA9WGN (email for humans: first name in lower case at ipal.net) |
From: nobody+cplusplus on 4 Jul 2008 16:12 Stephane CHAZELAS wrote: > 2008-07-05, 03:51(+09), nobody+cplusplus: > [...] >> printf ("len %d, %d: %s \n", (int) iov[i].iov_len, i, (char *) \ >> iov[i].iov_base ); > [...] >> What wrong am i doing here? :/ > [...] > > You're using printf("%s") on something that is not a > zero-terminated string. FYI, hence (void*)->(char*) for iov[i].iov_base anything else? -- thanks
From: nobody+cplusplus on 4 Jul 2008 16:17
phil-news-nospam(a)ipal.net wrote: > On Sat, 05 Jul 2008 03:51:06 +0930 nobody+cplusplus > <nobody(a)discodance.id.au> wrote: > > | Below is coded on linux. If you need specifics let me know. But the > | output is all messed up. > > Not knowing what the original requirements are, how would we know just > what is wrong? Someone could write some code that does all kinds of > goofy things, then copy the actual results and claim them to be the > requirements, and have what appears to be a correct implementation of > goofy requirements. The requirement is pretty clearly stated in the code. In any case, I wanted to printf() the file exactly the way it is after doing the vector read. > FYI, I have had goofy project handed to me by an incapable manager. > So I know what it's like. heh :) -- thanks |