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