summaryrefslogtreecommitdiff
path: root/utility/rtos_compatibility_layers/posix/px_mq_unlink.c
blob: e3e5f68372039ae93dfd624bccee62935dcf9528 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** POSIX wrapper for THREADX                                             */
/**                                                                       */
/**                                                                       */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

/* Include necessary system files.  */

#include "tx_api.h"     /* Threadx API */
#include "pthread.h"    /* Posix API */
#include "px_int.h"     /* Posix helper functions */


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    mq_unlink                                           PORTABLE C      */
/*                                                           6.1.7        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    William E. Lamie, Microsoft Corporation                             */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This routine removes the named message queue                        */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    const CHAR * mqName           Message Queue name.                   */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    OK                            If successful                         */
/*    ERROR                         IF fails                              */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    posix_internal_error          Generic error handler                 */
/*    posix_find_queue              Finds the required queue              */
/*    posix_queue_delete            Deletes specific queue                */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Application Code                                                    */
/*                                                                        */
/**************************************************************************/
INT  mq_unlink(const CHAR * mqName)
{

POSIX_MSG_QUEUE    *q_ptr;
ULONG               len;
ULONG               temp1;

    /* Checking for the invalid length.  */
    len = strlen(mqName);
    if(len > 10)
    {
        /* Return appropriate error.  */
        posix_errno = ENAMETOOLONG;
	    posix_set_pthread_errno(ENAMETOOLONG);

        /* Return Error.  */
        return(ERROR);
    }

    /* For checking the name.  */
    if(!(q_ptr = posix_find_queue(mqName)))
    {
        /* Set Posix error if name exist.  */
        posix_errno = EEXIST;
	    posix_set_pthread_errno(EEXIST);

        /* Return error.  */
        return(ERROR);
    }

    if(q_ptr)
        /* Unlinks the message Queue.  */
        q_ptr->unlink_flag = TX_TRUE;

    /* check if the message queue is not open in any task.  */
    if(q_ptr->open_count == 0)
    {
        /* Free the system resource allocated by open call.  */
        temp1 = posix_queue_delete( q_ptr );

        if( temp1 != TX_SUCCESS)
        {
            /*. Return generic error.  */
            posix_internal_error(100);

            /* Return error.  */
            return(ERROR);
        }
    }
    return(OK);
}