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

aremmell / libsir / 1126

24 Jul 2023 02:41PM UTC coverage: 87.837% (-6.9%) from 94.766%
1126

push

travis-ci

aremmell
add newer windows SDK

2831 of 3223 relevant lines covered (87.84%)

1496330.38 hits per line

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

95.31
/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.1
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) {
90✔
31
    sir_queue_node* retval = calloc(1, sizeof(sir_queue_node));
90✔
32
    if (!retval)
90✔
33
        _sir_handleerr(errno);
×
34
    else
35
        retval->data = data;
90✔
36

37
    return retval;
90✔
38
}
39

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

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

47
        _sir_safefree(node);
90✔
48
    }
49

50
    return valid;
90✔
51
}
52

53
bool _sir_queue_create(sir_queue** q) {
3✔
54

55
    if (_sir_validptrptr(q)) {
3✔
56
        *q = calloc(1, sizeof(sir_queue));
3✔
57
        if (!*q)
3✔
58
            _sir_handleerr(errno);
×
59
    }
60

61
    return q && *q;
3✔
62
}
63

64
bool _sir_queue_destroy(sir_queue** q) {
3✔
65
    bool valid = q && *q;
3✔
66

67
    if (valid) {
3✔
68
        sir_queue_node* next = (*q)->head;
3✔
69
        while (next) {
71✔
70
            sir_queue_node* this_node = next;
68✔
71
            void* data                = NULL;
68✔
72
            next                      = this_node->next;
68✔
73

74
            if (_sir_queue_node_destroy(&this_node, &data))
68✔
75
                _sir_safefree(&data);
68✔
76
        }
77

78
        _sir_safefree(q);
3✔
79
    }
80

81
    return valid;
3✔
82
}
83

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

88
    sir_queue_node* next = q->head->next;
90✔
89
    size_t idx           = 1;
90✔
90
    while (next) {
1,119✔
91
        idx++;
1,029✔
92
        next = next->next;
1,029✔
93
    }
94

95
    return idx;
90✔
96
}
97

98
bool _sir_queue_isempty(sir_queue* q) {
164✔
99
    return !q || !q->head;
164✔
100
}
101

102
bool _sir_queue_push(sir_queue* q, void* data) {
90✔
103
    bool retval = false;
90✔
104

105
    if (_sir_validptr(q)) {
90✔
106
        if (!q->head) {
90✔
107
            q->head = _sir_queue_node_create(data);
12✔
108
            retval = NULL != q->head;
12✔
109
        } else {
110
            sir_queue_node* next = q->head;
78✔
111
            while (next) {
1,029✔
112
                if (!next->next) {
1,029✔
113
                    next->next = _sir_queue_node_create(data);
78✔
114
                    if (next->next) {
78✔
115
                        retval = true;
78✔
116
                        break;
78✔
117
                    }
118
                }
119
                next = next->next;
951✔
120
            }
121
        }
122
    }
123

124
    return retval;
90✔
125
}
126

127
bool _sir_queue_pop(sir_queue* q, void** data) {
22✔
128
    bool retval = false;
22✔
129

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

134
        retval = _sir_queue_node_destroy(&old_head, data);
22✔
135
    }
136

137
    return retval;
22✔
138
}
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