os/ossrv/genericopenlibs/posixrealtimeextensions/src/posixshm.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 * Copyright 2000 Massachusetts Institute of Technology
sl@0
     3
 *
sl@0
     4
 * Permission to use, copy, modify, and distribute this software and
sl@0
     5
 * its documentation for any purpose and without fee is hereby
sl@0
     6
 * granted, provided that both the above copyright notice and this
sl@0
     7
 * permission notice appear in all copies, that both the above
sl@0
     8
 * copyright notice and this permission notice appear in all
sl@0
     9
 * supporting documentation, and that the name of M.I.T. not be used
sl@0
    10
 * in advertising or publicity pertaining to distribution of the
sl@0
    11
 * software without specific, written prior permission.  M.I.T. makes
sl@0
    12
 * no representations about the suitability of this software for any
sl@0
    13
 * purpose.  It is provided "as is" without express or implied
sl@0
    14
 * warranty.
sl@0
    15
 *
sl@0
    16
 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
sl@0
    17
 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
sl@0
    18
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
sl@0
    19
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
sl@0
    20
 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
sl@0
    21
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
sl@0
    22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
sl@0
    23
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
sl@0
    24
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
sl@0
    25
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
sl@0
    26
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
sl@0
    27
 * SUCH DAMAGE.
sl@0
    28
 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
sl@0
    29
 */
sl@0
    30
sl@0
    31
#include <sys/cdefs.h>
sl@0
    32
#ifndef __SYMBIAN32__
sl@0
    33
__FBSDID("$FreeBSD: src/lib/libc/gen/posixshm.c,v 1.4 2002/02/01 00:57:29 obrien Exp $");
sl@0
    34
#endif
sl@0
    35
sl@0
    36
#include <sys/types.h>
sl@0
    37
#include <sys/fcntl.h>
sl@0
    38
#include <sys/mman.h>
sl@0
    39
#include <sys/stat.h>
sl@0
    40
#include <errno.h>
sl@0
    41
#include <unistd.h>
sl@0
    42
#ifdef __SYMBIAN32__
sl@0
    43
#include <string.h>
sl@0
    44
#include <sys/syslimits.h>
sl@0
    45
#endif//__SYMBIAN32__
sl@0
    46
sl@0
    47
EXPORT_C int
sl@0
    48
shm_open(const char *path, int flags, mode_t mode)
sl@0
    49
	{
sl@0
    50
#ifndef SYMBIAN_OE_LIBRT
sl@0
    51
	path = path;
sl@0
    52
	flags = flags;
sl@0
    53
	mode = mode;
sl@0
    54
	errno = ENOSYS;
sl@0
    55
	return -1;
sl@0
    56
#else//SYMBIAN_OE_LIBRT
sl@0
    57
	int fd;
sl@0
    58
	struct stat stab;
sl@0
    59
#ifdef __SYMBIAN32__
sl@0
    60
	if (!path)
sl@0
    61
		{
sl@0
    62
		errno = EFAULT;
sl@0
    63
		return -1;
sl@0
    64
		}
sl@0
    65
	if (strlen(path) == 0)
sl@0
    66
		{
sl@0
    67
		errno = EINVAL;
sl@0
    68
		return -1;
sl@0
    69
		}
sl@0
    70
	if (strlen(path) >= PATH_MAX)
sl@0
    71
		{
sl@0
    72
		errno = ENAMETOOLONG;
sl@0
    73
		return -1;
sl@0
    74
		}
sl@0
    75
	while (*path == '/')
sl@0
    76
		{
sl@0
    77
		path++;
sl@0
    78
		}
sl@0
    79
#endif//__SYMBIAN32__
sl@0
    80
	if ((flags & O_ACCMODE) == O_WRONLY)
sl@0
    81
		{
sl@0
    82
		errno = EINVAL;
sl@0
    83
		return -1;
sl@0
    84
		}		
sl@0
    85
	fd = open(path, flags|O_SHMFLG, mode);
sl@0
    86
	if (fd != -1) 
sl@0
    87
		{
sl@0
    88
		if (fstat(fd, &stab) != 0 || !S_ISREG(stab.st_mode)) 
sl@0
    89
			{
sl@0
    90
			close(fd);
sl@0
    91
			errno = EINVAL;
sl@0
    92
			return (-1);
sl@0
    93
			}
sl@0
    94
sl@0
    95
		if (fcntl(fd, F_SETFL, (int)FPOSIXSHM) != 0) 
sl@0
    96
			{
sl@0
    97
			close(fd);
sl@0
    98
			return (-1);
sl@0
    99
			}
sl@0
   100
		}
sl@0
   101
		return (fd);
sl@0
   102
#endif//SYMBIAN_OE_LIBRT
sl@0
   103
	}
sl@0
   104
sl@0
   105
EXPORT_C int
sl@0
   106
shm_unlink(const char *path)
sl@0
   107
	{
sl@0
   108
#ifndef SYMBIAN_OE_LIBRT
sl@0
   109
	path = path;
sl@0
   110
	errno = ENOSYS;
sl@0
   111
	return -1;
sl@0
   112
#else//SYMBIAN_OE_LIBRT
sl@0
   113
#ifdef __SYMBIAN32__
sl@0
   114
	if (!path)
sl@0
   115
		{
sl@0
   116
		errno = EFAULT;
sl@0
   117
		return -1;
sl@0
   118
		}
sl@0
   119
	if (strlen(path) == 0)
sl@0
   120
		{
sl@0
   121
		errno = ENOENT;
sl@0
   122
		return -1;
sl@0
   123
		}
sl@0
   124
	if (strlen(path) >= PATH_MAX)
sl@0
   125
		{
sl@0
   126
		errno = ENAMETOOLONG;
sl@0
   127
		return -1;
sl@0
   128
		}
sl@0
   129
#endif//__SYMBIAN32__
sl@0
   130
	return (unlink(path));
sl@0
   131
#endif//SYMBIAN_OE_LIBRT
sl@0
   132
	}