*BSD News Article 25828


Return to BSD News archive

Newsgroups: comp.os.386bsd.questions
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!haven.umd.edu!news.umbc.edu!eff!news.kei.com!ub!csn!att-in!att!allegra!hgs
From: hgs@allegra.att.com (Henning G. Schulzrinne)
Subject: [NetBSD] mmap example?
Message-ID: <1994Jan10.224403.23503@allegra.att.com>
Organization: AT&T Bell Laboratories, Murray Hill, NJ
Date: Mon, 10 Jan 1994 22:44:03 GMT
Lines: 23

I'm trying to use mmap(), but without success. The code below always
fails with EINVAL. Any idea of why? (I can read/write to /dev/mem
using read()/write() and lseek().)

Thanks.

Henning Schulzrinne

  int fd;
  caddr_t at;
 
  fd = open("/dev/mem", O_RDWR, 0);
  if (fd < 0) {
    perror("/dev/mem");
    exit(1);
  }
 
  at = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);
  printf("mmap: %d\n", at);
  if ((int)at == -1) {
    perror("mmap");
  }