• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aremmell / libsir / 446

05 Sep 2023 06:57AM UTC coverage: 94.738% (+0.009%) from 94.729%
446

push

gitlab-ci

aremmell
Merge remote-tracking branch 'origin/set-thread-names' into set-thread-names

3079 of 3250 relevant lines covered (94.74%)

622120.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.38
/src/sirqueue.c
1
/*
2
 * sirqueue.c
3
 *
4
 * Author:    Ryan M. Lederman <lederman@gmail.com>
5
 * Copyright: Copyright (c) 2018-2023
6
 * Version:   2.2.3
7
 * License:   The MIT License (MIT)
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
10
 * this software and associated documentation files (the "Software"), to deal in
11
 * the Software without restriction, including without limitation the rights to
12
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
 * the Software, and to permit persons to whom the Software is furnished to do so,
14
 * subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 */
26
#include "sir/queue.h"
27
#include "sir/helpers.h"
28
#include "sir/errors.h"
29

30
sir_queue_node* _sir_queue_node_create(void* data) {
630✔
31
    sir_queue_node* retval = calloc(1, sizeof(sir_queue_node));
630✔
32
    if (!retval)
630✔
33
        _sir_handleerr(errno);
×
34
    else
35
        retval->data = data;
630✔
36

37
    return retval;
630✔
38
}
39

40
bool _sir_queue_node_destroy(sir_queue_node** node, void** data) {
630✔
41
    bool valid = _sir_validptrptr(node) && _sir_validptr(*node);
630✔
42

43
    if (valid) {
540✔
44
        if (data)
630✔
45
            *data = (*node)->data;
630✔
46

47
        _sir_safefree(node);
630✔
48
    }
49

50
    return valid;
630✔
51
}
52

53
bool _sir_queue_create(sir_queue** q) {
22✔
54
    bool valid = _sir_validptrptr(q);
22✔
55

56
    if (valid) {
22✔
57
        *q = calloc(1, sizeof(sir_queue));
22✔
58
        if (!_sir_validptrnofail(*q))
22✔
59
            _sir_handleerr(errno);
×
60
    }
61

62
    return valid && _sir_validptrnofail(*q);
22✔
63
}
64

65
bool _sir_queue_destroy(sir_queue** q) {
22✔
66
    bool valid = _sir_validptrptr(q) && _sir_validptr(*q);
22✔
67

68
    if (valid) {
19✔
69
        sir_queue_node* next = (*q)->head;
22✔
70
        while (next) {
484✔
71
            sir_queue_node* this_node = next;
462✔
72
            void* data                = NULL;
462✔
73
            next                      = this_node->next;
462✔
74

75
            if (_sir_queue_node_destroy(&this_node, &data))
462✔
76
                _sir_safefree(&data);
462✔
77
        }
78

79
        _sir_safefree(q);
22✔
80
    }
81

82
    return valid;
22✔
83
}
84

85
size_t _sir_queue_size(sir_queue* q) {
630✔
86
    if (_sir_queue_isempty(q))
630✔
87
        return 0;
×
88

89
    sir_queue_node* next = q->head->next;
630✔
90
    size_t idx           = 1;
540✔
91
    while (next) {
7,456✔
92
        idx++;
6,826✔
93
        next = next->next;
6,826✔
94
    }
95

96
    return idx;
540✔
97
}
98

99
bool _sir_queue_isempty(sir_queue* q) {
1,186✔
100
    return !q || !q->head;
1,186✔
101
}
102

103
bool _sir_queue_push(sir_queue* q, void* data) {
630✔
104
    bool retval = false;
540✔
105

106
    if (_sir_validptr(q)) {
630✔
107
        if (!q->head) {
630✔
108
            q->head = _sir_queue_node_create(data);
104✔
109
            retval = NULL != q->head;
104✔
110
        } else {
111
            sir_queue_node* next = q->head;
451✔
112
            while (next) {
6,826✔
113
                if (!next->next) {
6,826✔
114
                    next->next = _sir_queue_node_create(data);
526✔
115
                    if (next->next) {
526✔
116
                        retval = true;
451✔
117
                        break;
451✔
118
                    }
119
                }
120
                next = next->next;
6,300✔
121
            }
122
        }
123
    }
124

125
    return retval;
630✔
126
}
127

128
bool _sir_queue_pop(sir_queue* q, void** data) {
168✔
129
    bool retval = false;
144✔
130

131
    if (!_sir_queue_isempty(q) && _sir_validptrptr(data)) {
168✔
132
        sir_queue_node* old_head = q->head;
168✔
133
        q->head                  = old_head->next;
168✔
134

135
        retval = _sir_queue_node_destroy(&old_head, data);
168✔
136
    }
137

138
    return retval;
168✔
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc