1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2007. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #if HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <stdarg.h> |
---|
15 | |
---|
16 | #include <errno.h> |
---|
17 | #include <fcntl.h> |
---|
18 | #include <pthread.h> |
---|
19 | #include <semaphore.h> |
---|
20 | #include <limits.h> |
---|
21 | |
---|
22 | #include <rtems/system.h> |
---|
23 | #include <rtems/score/object.h> |
---|
24 | #include <rtems/posix/semaphore.h> |
---|
25 | #include <rtems/posix/time.h> |
---|
26 | #include <rtems/seterr.h> |
---|
27 | |
---|
28 | /* |
---|
29 | * sem_unlink |
---|
30 | * |
---|
31 | * Unlinks a named semaphore, sem_close must also be called to remove |
---|
32 | * the semaphore. |
---|
33 | * |
---|
34 | * 11.2.5 Remove a Named Semaphore, P1003.1b-1993, p.225 |
---|
35 | */ |
---|
36 | |
---|
37 | int sem_unlink( |
---|
38 | const char *name |
---|
39 | ) |
---|
40 | { |
---|
41 | int status; |
---|
42 | register POSIX_Semaphore_Control *the_semaphore; |
---|
43 | Objects_Id the_semaphore_id; |
---|
44 | size_t name_len; |
---|
45 | |
---|
46 | _Thread_Disable_dispatch(); |
---|
47 | |
---|
48 | status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len ); |
---|
49 | if ( status != 0 ) { |
---|
50 | _Thread_Enable_dispatch(); |
---|
51 | rtems_set_errno_and_return_minus_one( status ); |
---|
52 | } |
---|
53 | |
---|
54 | the_semaphore = (POSIX_Semaphore_Control *) _Objects_Get_local_object( |
---|
55 | &_POSIX_Semaphore_Information, |
---|
56 | _Objects_Get_index( the_semaphore_id ) |
---|
57 | ); |
---|
58 | |
---|
59 | the_semaphore->linked = false; |
---|
60 | _POSIX_Semaphore_Namespace_remove( the_semaphore ); |
---|
61 | _POSIX_Semaphore_Delete( the_semaphore ); |
---|
62 | |
---|
63 | _Thread_Enable_dispatch(); |
---|
64 | return 0; |
---|
65 | } |
---|