c - why after writing with memcpy in a portion of memory mmaped, I don't see in the file? -


when open file after run of program, saw first phrase.

void writeinfilemmaped(){  void* file_memory=null; char* path="/home/testfile"; int fdtest=0; struct stat buftest;  char *phrase= "hi, i'm phrase";  //make file 20m system("truncate -s 20m /home/testfile");  //open testfile if((fdtest=open(path,o_rdwr))==-1){     perror("open testfile");     exit(exit_failure); }  if(fstat(fdtest,&buftest)==-1){     perror("stat"); }  file_memory=mmap(0, buftest.st_size, prot_read|prot_write, map_shared, fdtest,0);  if(file_memory==map_failed){     close(fdtest);     perror("error mapping file");     exit(exit_failure); } memcpy(file_memory,phrase,strlen(phrase)); printf("%sn",file_memory); memcpy(file_memory+100, phrase,strlen(phrase)); printf("%sn",file_memory+100); 

}

the output good, in file appears "hi, i'm phrase" try sprintf , result same. think problem null


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -