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 /* FUNCTION RELEASE */ 31 /* */ 32 /* posix_find_queue PORTABLE C */ 33 /* 6.1.7 */ 34 /* AUTHOR */ 35 /* */ 36 /* William E. Lamie, Microsoft Corporation */ 37 /* */ 38 /* DESCRIPTION */ 39 /* */ 40 /* This routine returns queue descriptor indicating that name of */ 41 /* in the message queue.exists. */ 42 /* */ 43 /* INPUT */ 44 /* */ 45 /* const char * mq_name Name of the message queue */ 46 /* */ 47 /* OUTPUT */ 48 /* */ 49 /* q_ptr If successful */ 50 /* */ 51 /* CALLS */ 52 /* */ 53 /* None */ 54 /* */ 55 /* CALLED BY */ 56 /* */ 57 /* POSIX internal Code */ 58 /* */ 59 /* RELEASE HISTORY */ 60 /* */ 61 /* DATE NAME DESCRIPTION */ 62 /* */ 63 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ 64 /* */ 65 /**************************************************************************/ posix_find_queue(const CHAR * mq_name)66POSIX_MSG_QUEUE * posix_find_queue(const CHAR *mq_name) 67 { 68 69 POSIX_MSG_QUEUE *q_ptr; 70 ULONG index; 71 ULONG match; 72 CHAR *dummy_name; 73 CHAR *dummy_queue_name; 74 ULONG namelength; 75 76 q_ptr = (POSIX_MSG_QUEUE*)NULL; 77 78 /* For checking the name. */ 79 for(index = 0,q_ptr = posix_queue_pool;index < POSIX_MAX_QUEUES ;index ++,q_ptr ++) 80 { 81 /* Assume the worst case. */ 82 match = TX_FALSE; 83 if(q_ptr->in_use == TX_TRUE) 84 { 85 dummy_queue_name = q_ptr->name; 86 for(namelength = 0 ,dummy_name = (CHAR *) mq_name ; namelength < PATH_MAX ; 87 namelength ++, dummy_name++,dummy_queue_name ++) 88 { 89 /* Copy name. */ 90 if (*dummy_name == *dummy_queue_name) 91 { 92 /* End of the string. */ 93 if(*dummy_name == '\0') 94 { 95 match = TX_TRUE; 96 break; 97 } 98 }/* Copy name. */ 99 else 100 break; 101 } 102 } 103 if(match==TX_TRUE) 104 break; 105 } 106 /* For each message queue. */ 107 if(match==TX_TRUE) 108 return(q_ptr); 109 /* Returns NULL if match not found. */ 110 q_ptr = (POSIX_MSG_QUEUE*)NULL; 111 return (q_ptr); 112 } 113