This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Breaking fwrite calls


Hi everyone,
I am using the below listed code
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
   char *obuf=NULL;
   FILE *stream=NULL;
   int i=0;
   stream=fopen("top","wb");
   obuf= (char*)malloc(8192);
   memset(obuf,'a',8192);
   while(i<50)
   {
      fwrite(obuf,sizeof(char),8192,stream);
      printf("single\n");
      i++;
   }
   fclose(stream);
   return 0;
}

And I am getting the following strace
....................
open("top", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xf702a000
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 8192) = 8192
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 221), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xf7029000
write(1, "single\n", 7)                 = 7
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "single\n", 7)                 = 7
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "single\n", 7)                 = 7
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "single\n", 7)                 = 7
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "single\n", 7)                 = 7
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "single\n", 7)                 = 7
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "single\n", 7)                 = 7
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
.................................

As you can see the first write call is of 8192 bytes but later on the
subsequent fwrite calls breaks in two calls of write of size 4096 and
4096 bytes. Can anyone explain me the reason behind this behaviour of
fwrite function???


Thanks and Regards
Mohit Katiyar
HCL Technologies
Ph: 9891988857



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]