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

aremmell / libsir / 1153

25 Jul 2023 04:30AM UTC coverage: 80.118% (-14.7%) from 94.801%
1153

push

travis-ci

aremmell
fix ternary

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

2571 of 3209 relevant lines covered (80.12%)

24530.87 hits per line

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

84.62
/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 = _sir_validptrptr(node) && _sir_validptr(*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
    bool valid = _sir_validptrptr(q);
3✔
55

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

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

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

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

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

79
        _sir_safefree(q);
3✔
80
    }
81

82
    return valid;
3✔
83
}
84

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

89
    sir_queue_node* next = q->head->next;
90✔
90
    size_t idx           = 1;
×
91
    while (next) {
1,123✔
92
        idx++;
1,033✔
93
        next = next->next;
1,033✔
94
    }
95

96
    return idx;
×
97
}
98

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

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

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

125
    return retval;
90✔
126
}
127

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

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

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

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