smart memcpy

Michael Trimarchi trimarchi@gandalf.sssup.it
Thu Sep 15 13:20:00 GMT 2005


Hi all,
is it the only solution for a smart memcpy?


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>           /* For O_* constants */


int main (int argc, char **argv)
{
         char *s,*x;
         int i;
         int fd;
     int addr;
     int size=40960;
        
    
 //s=mmap(NULL,size,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0);
         fd=shm_open("memcpy",O_RDWR|O_CREAT,0600);
         ftruncate(fd,size);
         printf("s = %p\n",s);
         s = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
         memset(s, 'X', size);
        
         x = mmap(0,size,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
     
     if ((int)(x)!=-1) {
            printf("x = %p\n",x);
        *x='P';
            for (i=0;i<40; i++)
        printf("sval=%c;xval=%c;",*(x+i),*(s+i));     
     } else {
         printf("%s %d %x\n",strerror(errno),errno,x);


     }
     
         return 0;

}




More information about the Binutils mailing list