5
Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Copyright (c) 2016 Gedare Bloom. |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.org/license/LICENSE. |
---|
11 | */ |
---|
12 | |
---|
13 | #if HAVE_CONFIG_H |
---|
14 | #include "config.h" |
---|
15 | #endif |
---|
16 | |
---|
17 | #include <sys/mman.h> |
---|
18 | #include <errno.h> |
---|
19 | #include <rtems/seterr.h> |
---|
20 | |
---|
21 | #include <rtems/posix/shmimpl.h> |
---|
22 | |
---|
23 | int shm_unlink( const char *name ) |
---|
24 | { |
---|
25 | Objects_Get_by_name_error obj_err; |
---|
26 | int err = 0; |
---|
27 | POSIX_Shm_Control *shm; |
---|
28 | |
---|
29 | shm = _POSIX_Shm_Get_by_name( name, 0, &obj_err ); |
---|
30 | switch ( obj_err ) { |
---|
31 | case OBJECTS_GET_BY_NAME_INVALID_NAME: |
---|
32 | err = ENOENT; |
---|
33 | break; |
---|
34 | |
---|
35 | case OBJECTS_GET_BY_NAME_NAME_TOO_LONG: |
---|
36 | err = ENAMETOOLONG; |
---|
37 | break; |
---|
38 | |
---|
39 | case OBJECTS_GET_BY_NAME_NO_OBJECT: |
---|
40 | default: |
---|
41 | _Objects_Close( &_POSIX_Shm_Information, &shm->Object ); |
---|
42 | if ( shm->reference_count == 0 ) { |
---|
43 | /* Only remove the shm object if no references exist to it. Otherwise, |
---|
44 | * the shm object will be freed later in _POSIX_Shm_Attempt_delete */ |
---|
45 | _POSIX_Shm_Free( shm ); |
---|
46 | } |
---|
47 | break; |
---|
48 | } |
---|
49 | if ( err != 0 ) |
---|
50 | rtems_set_errno_and_return_minus_one( err ); |
---|
51 | return 0; |
---|
52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.