~ubuntu-branches/ubuntu/quantal/open-iscsi/quantal-proposed

« back to all changes in this revision

Viewing changes to usr/strings.c

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-07-10 13:53:52 UTC
  • mfrom: (1.1.5) (4.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20120710135352-8pw2po02ka51y2g2
Tags: 2.0.873-3ubuntu1
* Merge from Debian. Remaining changes: (LP: #961114, LP: #677333)
  - Add upstart job iscsi-network-interface
  - Migrate from /var/run and /lib/init/rw to /run, from /var/lock to
    /run/lock.
* Turn open-iscsi-utils into a transitional package

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "strings.h"
27
27
#include "log.h"
28
28
 
29
 
int
30
 
init_string_buffer(struct string_buffer *s, size_t initial_allocation)
 
29
int str_init_buffer(struct str_buffer *s, size_t initial_allocation)
31
30
{
32
31
        if (s) {
33
32
                memset(s, 0, sizeof (*s));
46
45
        return 0;
47
46
}
48
47
 
49
 
struct string_buffer *
50
 
alloc_string_buffer(size_t initial_allocation)
 
48
struct str_buffer *str_alloc_buffer(size_t initial_allocation)
51
49
{
52
 
        struct string_buffer *s = calloc(1, sizeof (*s));
 
50
        struct str_buffer *s = calloc(1, sizeof (*s));
53
51
 
54
 
        if (s) {
55
 
                init_string_buffer(s, initial_allocation);
56
 
        }
 
52
        if (s)
 
53
                str_init_buffer(s, initial_allocation);
57
54
 
58
55
        return s;
59
56
}
60
57
 
61
 
void
62
 
free_string_buffer(struct string_buffer *s)
 
58
void str_free_buffer(struct str_buffer *s)
63
59
{
64
60
        if (s) {
65
61
                if (s->buffer) {
71
67
        }
72
68
}
73
69
 
74
 
void
75
 
enlarge_data(struct string_buffer *s, int length)
 
70
int str_enlarge_data(struct str_buffer *s, int length)
76
71
{
77
72
        void *new_buf;
78
73
 
88
83
                                          "bytes, with only %d bytes of buffer "
89
84
                                          "space", s, (int)s->data_length,
90
85
                                           (int)s->allocated_length);
91
 
                                exit(1);
 
86
                                return ENOMEM;
92
87
                        }
93
88
                        s->buffer = new_buf;
94
89
                        memset(s->buffer + s->allocated_length, 0,
96
91
                        s->allocated_length = s->data_length;
97
92
                }
98
93
        }
 
94
 
 
95
        return 0;
99
96
}
100
97
 
101
 
void
102
 
remove_initial(struct string_buffer *s, int length)
 
98
void str_remove_initial(struct str_buffer *s, int length)
103
99
{
104
 
        char *remaining = s->buffer + length;
105
 
        int amount = s->data_length - length;
 
100
        char *remaining;
 
101
        int amount;
106
102
 
107
103
        if (s && length) {
108
 
                memmove(s->buffer, remaining, amount);
 
104
                remaining = s->buffer + length;
 
105
                amount = s->data_length - length;
 
106
 
 
107
                if (amount < 0)
 
108
                        amount = 0;
 
109
                if (amount)
 
110
                        memmove(s->buffer, remaining, amount);
109
111
                s->data_length = amount;
110
112
                s->buffer[amount] = '\0';
111
113
        }
112
114
}
113
115
 
114
116
/* truncate the data length down */
115
 
void
116
 
truncate_buffer(struct string_buffer *s, size_t length)
 
117
void str_truncate_buffer(struct str_buffer *s, size_t length)
117
118
{
118
119
        if (s) {
119
120
                if (!s->data_length)
137
138
        }
138
139
}
139
140
 
140
 
char *
141
 
buffer_data(struct string_buffer *s)
 
141
char *str_buffer_data(struct str_buffer *s)
142
142
{
143
143
        if (s)
144
144
                return s->buffer;
146
146
                return NULL;
147
147
}
148
148
 
149
 
size_t
150
 
data_length(struct string_buffer * s)
 
149
size_t str_data_length(struct str_buffer * s)
151
150
{
152
151
        if (s)
153
152
                return s->data_length;
155
154
                return 0;
156
155
}
157
156
 
158
 
size_t
159
 
unused_length(struct string_buffer * s)
 
157
size_t str_unused_length(struct str_buffer * s)
160
158
{
161
159
        if (s)
162
160
                return s->allocated_length - s->data_length;