1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** POSIX wrapper for THREADX */
17 /** */
18 /** */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 /* Include necessary system files. */
24
25 #include "tx_api.h" /* Threadx API */
26 #include "pthread.h" /* Posix API */
27 #include "px_int.h" /* Posix helper functions */
28
29
30 /**************************************************************************/
31 /* */
32 /* FUNCTION RELEASE */
33 /* */
34 /* sem_unlink PORTABLE C */
35 /* 6.2.0 */
36 /* AUTHOR */
37 /* */
38 /* William E. Lamie, Microsoft Corporation */
39 /* */
40 /* DESCRIPTION */
41 /* */
42 /* This routine removes the string from the semaphore name table ,and */
43 /* marks the corresponding semaphore for destruction. */
44 /* */
45 /* INPUT */
46 /* */
47 /* name Semaphore name. */
48 /* */
49 /* OUTPUT */
50 /* */
51 /* OK If successful */
52 /* ERROR IF fails */
53 /* */
54 /* CALLS */
55 /* */
56 /* posix_find_sem checks the name of semaphore with the names */
57 /* of the already created semaphore. */
58 /* posix_sem_reset Resets the semaphore structure */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application Code */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
69 /* 10-31-2022 Scott Larson Remove double parenthesis, */
70 /* resulting in version 6.2.0 */
71 /* */
72 /**************************************************************************/
sem_unlink(const CHAR * name)73 INT sem_unlink(const CHAR * name)
74 {
75
76
77 struct POSIX_SEMAPHORE_STRUCT * sem;
78 ULONG len;
79
80
81 /* Checking for the invalid length. */
82 len = strlen(name);
83
84 if(len > SEM_NAME_MAX)
85 {
86 /* Return appropriate error. */
87 posix_errno=ENAMETOOLONG;
88 posix_set_pthread_errno(ENAMETOOLONG);
89 /* Return error. */
90 return(ERROR);
91 }
92
93 if(!(sem=posix_find_sem(name)))
94 {
95 /* Set error in global variable. */
96 posix_errno = ENOENT;
97 posix_set_pthread_errno(ENOENT);
98
99 /* Return Error. */
100 return(ERROR);
101 }
102 if(sem)
103
104 sem->unlink_flag =TX_TRUE;
105
106 /* Check for the count. */
107 if(sem->count == 0)
108 {
109 posix_sem_reset(sem );
110 sem = NULL;
111 }
112
113 return(OK);
114 }
115