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 /*    mq_unlink                                           PORTABLE C      */
35 /*                                                           6.1.7        */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    William E. Lamie, Microsoft Corporation                             */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This routine removes the named message queue                        */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    const CHAR * mqName           Message Queue name.                   */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*    OK                            If successful                         */
51 /*    ERROR                         IF fails                              */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    posix_internal_error          Generic error handler                 */
56 /*    posix_find_queue              Finds the required queue              */
57 /*    posix_queue_delete            Deletes specific queue                */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    Application Code                                                    */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  06-02-2021     William E. Lamie         Initial Version 6.1.7         */
68 /*                                                                        */
69 /**************************************************************************/
mq_unlink(const CHAR * mqName)70 INT  mq_unlink(const CHAR * mqName)
71 {
72 
73 POSIX_MSG_QUEUE    *q_ptr;
74 ULONG               len;
75 ULONG               temp1;
76 
77     /* Checking for the invalid length.  */
78     len = strlen(mqName);
79     if(len > 10)
80     {
81         /* Return appropriate error.  */
82         posix_errno = ENAMETOOLONG;
83 	    posix_set_pthread_errno(ENAMETOOLONG);
84 
85         /* Return Error.  */
86         return(ERROR);
87     }
88 
89     /* For checking the name.  */
90     if(!(q_ptr = posix_find_queue(mqName)))
91     {
92         /* Set Posix error if name exist.  */
93         posix_errno = EEXIST;
94 	    posix_set_pthread_errno(EEXIST);
95 
96         /* Return error.  */
97         return(ERROR);
98     }
99 
100     if(q_ptr)
101         /* Unlinks the message Queue.  */
102         q_ptr->unlink_flag = TX_TRUE;
103 
104     /* check if the message queue is not open in any task.  */
105     if(q_ptr->open_count == 0)
106     {
107         /* Free the system resource allocated by open call.  */
108         temp1 = posix_queue_delete( q_ptr );
109 
110         if( temp1 != TX_SUCCESS)
111         {
112             /*. Return generic error.  */
113             posix_internal_error(100);
114 
115             /* Return error.  */
116             return(ERROR);
117         }
118     }
119     return(OK);
120 }
121