8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libc / port / rt / shm.c
blob87f2cfae44635980e8e490934086d37192e2fc4e
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "lint.h"
30 #include <sys/types.h>
31 #include <sys/mman.h>
32 #include <fcntl.h>
33 #include <limits.h>
34 #include <errno.h>
35 #include "pos4obj.h"
37 int
38 shm_open(const char *path, int oflag, mode_t mode)
40 int crflag;
41 int fd;
42 int flags;
44 if (__pos4obj_check(path) == -1)
45 return (-1);
47 /* acquire semaphore lock to have atomic operation */
48 if (__pos4obj_lock(path, SHM_LOCK_TYPE) < 0)
49 return (-1);
51 fd = __pos4obj_open(path, SHM_DATA_TYPE, oflag, mode, &crflag);
53 if (fd < 0) {
54 (void) __pos4obj_unlock(path, SHM_LOCK_TYPE);
55 return (-1);
58 if ((flags = fcntl(fd, F_GETFD)) < 0 ||
59 fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
60 (void) __pos4obj_unlock(path, SHM_LOCK_TYPE);
61 (void) __close_nc(fd);
62 return (-1);
65 /* relase semaphore lock operation */
66 if (__pos4obj_unlock(path, SHM_LOCK_TYPE) < 0) {
67 (void) __close_nc(fd);
68 return (-1);
71 return (fd);
74 int
75 shm_unlink(const char *path)
77 int oerrno;
78 int err;
80 if (__pos4obj_check(path) < 0)
81 return (-1);
83 if (__pos4obj_lock(path, SHM_LOCK_TYPE) < 0)
84 return (-1);
86 err = __pos4obj_unlink(path, SHM_DATA_TYPE);
88 oerrno = errno;
90 (void) __pos4obj_unlock(path, SHM_LOCK_TYPE);
92 errno = oerrno;
93 return (err);