This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
smart memcpy
- From: Michael Trimarchi <trimarchi at gandalf dot sssup dot it>
- To: binutils at sources dot redhat dot com
- Date: Thu, 15 Sep 2005 14:31:13 +0200
- Subject: smart memcpy
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;
}