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

aremmell / libsir / 1133

24 Jul 2023 03:46PM UTC coverage: 94.77% (+0.004%) from 94.766%
1133

Pull #193

travis-ci

web-flow
Merge 1e7b2131c into 13f9deedb
Pull Request #193: Add linting script

4 of 4 new or added lines in 1 file covered. (100.0%)

3044 of 3212 relevant lines covered (94.77%)

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

37
    return retval;
600✔
38
}
39

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

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

47
        _sir_safefree(node);
600✔
48
    }
49

50
    return valid;
600✔
51
}
52

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

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

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

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

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

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

78
        _sir_safefree(q);
21✔
79
    }
80

81
    return valid;
21✔
82
}
83

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

88
    sir_queue_node* next = q->head->next;
600✔
89
    size_t idx           = 1;
510✔
90
    while (next) {
7,432✔
91
        idx++;
6,832✔
92
        next = next->next;
6,832✔
93
    }
94

95
    return idx;
510✔
96
}
97

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

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

105
    if (_sir_validptr(q)) {
600✔
106
        if (!q->head) {
600✔
107
            q->head = _sir_queue_node_create(data);
71✔
108
            retval = NULL != q->head;
71✔
109
        } else {
110
            sir_queue_node* next = q->head;
447✔
111
            while (next) {
6,832✔
112
                if (!next->next) {
6,832✔
113
                    next->next = _sir_queue_node_create(data);
529✔
114
                    if (next->next) {
529✔
115
                        retval = true;
447✔
116
                        break;
447✔
117
                    }
118
                }
119
                next = next->next;
6,303✔
120
            }
121
        }
122
    }
123

124
    return retval;
600✔
125
}
126

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

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

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

137
    return retval;
149✔
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