Apache-Mmap
view release on metacpan or search on metacpan
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
*
* See the files 'Copying' or 'Artistic' for conditions of use.
*
* Portions based on Mmap module's Mmap.xs
* which are Copyright (c) 1996 by Malcolm Beattie
*
*/
/*
* $Id: Mmap.xs,v 1.3 1997/09/15 06:20:56 fletch Exp $
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
#include <sys/mman.h>
#include <string.h>
#ifndef MMAP_RETTYPE
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199309
#endif /* !_POSIX_C_SOURCE */
#ifdef _POSIX_VERSION
#if _POSIX_VERSION >= 199309
#define MMAP_RETTYPE void *
#endif /* _POSIX_VERSION >= 199309 */
#endif /* _POSIX_VERSION */
#endif /* !MMAP_RETTYPE */
#ifndef MMAP_RETTYPE
#define MMAP_RETTYPE caddr_t
#endif /* !MMAP_RETTYPE */
#ifndef MAP_FAILED
#define MAP_FAILED ((caddr_t)-1)
#endif /* !MAP_FAILED */
/* Define struct to represent a mapped region */
struct _Mmap {
MMAP_RETTYPE addr; /* Address of memory returned by mmap(2) */
size_t len; /* Length of mapped buffer */
size_t cur; /* Current length of string in buffer */
off_t off; /* Offset in file mapped */
int prot, flags; /* Protection and flags passed to mmap(2) */
};
typedef struct _Mmap Mmap;
static void
dump_Mmap( m )
Mmap *m;
{
if( m != NULL )
fprintf( stderr,
"Apache::Mmap %x:\naddr: %x\tlen: %d\tcur: %d\noff: %d\tprot: %d\tflags: %d\n",
m, m->addr, m->len, m->cur, m->off, m->prot, m->flags );
}
static int
not_here(s)
char *s;
{
croak("%s not implemented on this architecture", s);
return -1;
}
static double
constant(name, arg)
char *name;
int arg;
{
errno = 0;
switch (*name) {
case 'M':
if (strEQ(name, "MAP_ANON"))
#ifdef MAP_ANON
return MAP_ANON;
#else
goto not_there;
#endif
if (strEQ(name, "MAP_ANONYMOUS"))
#ifdef MAP_ANONYMOUS
return MAP_ANONYMOUS;
#else
goto not_there;
#endif
if (strEQ(name, "MAP_FILE"))
#ifdef MAP_FILE
return MAP_FILE;
#else
goto not_there;
#endif
if (strEQ(name, "MAP_PRIVATE"))
#ifdef MAP_PRIVATE
return MAP_PRIVATE;
#else
goto not_there;
#endif
if (strEQ(name, "MAP_SHARED"))
#ifdef MAP_SHARED
return MAP_SHARED;
#else
goto not_there;
#endif
break;
case 'P':
if (strEQ(name, "PROT_EXEC"))
#ifdef PROT_EXEC
return PROT_EXEC;
#else
goto not_there;
#endif
if (strEQ(name, "PROT_NONE"))
#ifdef PROT_NONE
( run in 2.446 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )