1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** POSIX wrapper for THREADX */ 16 /** */ 17 /** */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 /* Include necessary system files. */ 23 24 #include "tx_api.h" /* Threadx API */ 25 #include "pthread.h" /* Posix API */ 26 #include "px_int.h" /* Posix helper functions */ 27 28 29 /**************************************************************************/ 30 /* */ 31 /* FUNCTION RELEASE */ 32 /* */ 33 /* mq_unlink PORTABLE C */ 34 /* 6.1.7 */ 35 /* AUTHOR */ 36 /* */ 37 /* William E. Lamie, Microsoft Corporation */ 38 /* */ 39 /* DESCRIPTION */ 40 /* */ 41 /* This routine removes the named message queue */ 42 /* */ 43 /* INPUT */ 44 /* */ 45 /* const CHAR * mqName Message Queue name. */ 46 /* */ 47 /* OUTPUT */ 48 /* */ 49 /* OK If successful */ 50 /* ERROR IF fails */ 51 /* */ 52 /* CALLS */ 53 /* */ 54 /* posix_internal_error Generic error handler */ 55 /* posix_find_queue Finds the required queue */ 56 /* posix_queue_delete Deletes specific queue */ 57 /* */ 58 /* CALLED BY */ 59 /* */ 60 /* Application Code */ 61 /* */ 62 /* RELEASE HISTORY */ 63 /* */ 64 /* DATE NAME DESCRIPTION */ 65 /* */ 66 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ 67 /* */ 68 /**************************************************************************/ mq_unlink(const CHAR * mqName)69INT mq_unlink(const CHAR * mqName) 70 { 71 72 POSIX_MSG_QUEUE *q_ptr; 73 ULONG len; 74 ULONG temp1; 75 76 /* Checking for the invalid length. */ 77 len = strlen(mqName); 78 if(len > 10) 79 { 80 /* Return appropriate error. */ 81 posix_errno = ENAMETOOLONG; 82 posix_set_pthread_errno(ENAMETOOLONG); 83 84 /* Return Error. */ 85 return(ERROR); 86 } 87 88 /* For checking the name. */ 89 if(!(q_ptr = posix_find_queue(mqName))) 90 { 91 /* Set Posix error if name exist. */ 92 posix_errno = EEXIST; 93 posix_set_pthread_errno(EEXIST); 94 95 /* Return error. */ 96 return(ERROR); 97 } 98 99 if(q_ptr) 100 /* Unlinks the message Queue. */ 101 q_ptr->unlink_flag = TX_TRUE; 102 103 /* check if the message queue is not open in any task. */ 104 if(q_ptr->open_count == 0) 105 { 106 /* Free the system resource allocated by open call. */ 107 temp1 = posix_queue_delete( q_ptr ); 108 109 if( temp1 != TX_SUCCESS) 110 { 111 /*. Return generic error. */ 112 posix_internal_error(100); 113 114 /* Return error. */ 115 return(ERROR); 116 } 117 } 118 return(OK); 119 } 120