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

aremmell / libsir / 423

04 Sep 2023 05:24PM UTC coverage: 94.617% (-0.2%) from 94.865%
423

Pull #257

gitlab-ci

johnsonjh
Appease ShellCheck

Signed-off-by: Jeffrey H. Johnson <trnsz@pobox.com>
Pull Request #257: WIP

260 of 260 new or added lines in 12 files covered. (100.0%)

3041 of 3214 relevant lines covered (94.62%)

622949.94 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) {
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 = _sir_validptrptr(node) && _sir_validptr(*node);
600✔
42

43
    if (valid) {
510✔
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
    bool valid = _sir_validptrptr(q);
21✔
55

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

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

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

68
    if (valid) {
18✔
69
        sir_queue_node* next = (*q)->head;
21✔
70
        while (next) {
461✔
71
            sir_queue_node* this_node = next;
440✔
72
            void* data                = NULL;
440✔
73
            next                      = this_node->next;
440✔
74

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

79
        _sir_safefree(q);
21✔
80
    }
81

82
    return valid;
21✔
83
}
84

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

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

96
    return idx;
510✔
97
}
98

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

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

106
    if (_sir_validptr(q)) {
600✔
107
        if (!q->head) {
600✔
108
            q->head = _sir_queue_node_create(data);
95✔
109
            retval = NULL != q->head;
95✔
110
        } else {
111
            sir_queue_node* next = q->head;
429✔
112
            while (next) {
6,510✔
113
                if (!next->next) {
6,510✔
114
                    next->next = _sir_queue_node_create(data);
505✔
115
                    if (next->next) {
505✔
116
                        retval = true;
429✔
117
                        break;
429✔
118
                    }
119
                }
120
                next = next->next;
6,005✔
121
            }
122
        }
123
    }
124

125
    return retval;
600✔
126
}
127

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

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

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

138
    return retval;
160✔
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

© 2025 Coveralls, Inc