Deleted Added
full compact
subr_sbuf.c (84097) subr_sbuf.c (87594)
1/*-
2 * Copyright (c) 2000 Poul-Henning Kamp and Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
1/*-
2 * Copyright (c) 2000 Poul-Henning Kamp and Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/kern/subr_sbuf.c 84097 2001-09-29 00:32:46Z des $
28 * $FreeBSD: head/sys/kern/subr_sbuf.c 87594 2001-12-10 05:51:45Z obrien $
29 */
30
31#include <sys/param.h>
32
33#ifdef _KERNEL
34#include <sys/ctype.h>
35#include <sys/kernel.h>
36#include <sys/malloc.h>

--- 51 unchanged lines hidden (view full) ---

88
89static void
90_assert_sbuf_state(char *fun, struct sbuf *s, int state)
91{
92 KASSERT((s->s_flags & SBUF_FINISHED) == state,
93 ("%s called with %sfinished or corrupt sbuf", fun,
94 (state ? "un" : "")));
95}
29 */
30
31#include <sys/param.h>
32
33#ifdef _KERNEL
34#include <sys/ctype.h>
35#include <sys/kernel.h>
36#include <sys/malloc.h>

--- 51 unchanged lines hidden (view full) ---

88
89static void
90_assert_sbuf_state(char *fun, struct sbuf *s, int state)
91{
92 KASSERT((s->s_flags & SBUF_FINISHED) == state,
93 ("%s called with %sfinished or corrupt sbuf", fun,
94 (state ? "un" : "")));
95}
96#define assert_sbuf_integrity(s) _assert_sbuf_integrity(__FUNCTION__, (s))
97#define assert_sbuf_state(s, i) _assert_sbuf_state(__FUNCTION__, (s), (i))
96#define assert_sbuf_integrity(s) _assert_sbuf_integrity(__func__, (s))
97#define assert_sbuf_state(s, i) _assert_sbuf_state(__func__, (s), (i))
98#else /* _KERNEL && INVARIANTS */
99#define assert_sbuf_integrity(s) do { } while (0)
100#define assert_sbuf_state(s, i) do { } while (0)
101#endif /* _KERNEL && INVARIANTS */
102
103/*
104 * Initialize an sbuf.
105 * If buf is non-NULL, it points to a static or already-allocated string
106 * big enough to hold at least length characters.
107 */
108struct sbuf *
109sbuf_new(struct sbuf *s, char *buf, int length, int flags)
110{
111 KASSERT(length >= 0,
112 ("attempt to create an sbuf of negative length (%d)", length));
113 KASSERT(flags == 0,
98#else /* _KERNEL && INVARIANTS */
99#define assert_sbuf_integrity(s) do { } while (0)
100#define assert_sbuf_state(s, i) do { } while (0)
101#endif /* _KERNEL && INVARIANTS */
102
103/*
104 * Initialize an sbuf.
105 * If buf is non-NULL, it points to a static or already-allocated string
106 * big enough to hold at least length characters.
107 */
108struct sbuf *
109sbuf_new(struct sbuf *s, char *buf, int length, int flags)
110{
111 KASSERT(length >= 0,
112 ("attempt to create an sbuf of negative length (%d)", length));
113 KASSERT(flags == 0,
114 (__FUNCTION__ " called with non-zero flags"));
114 ("%s called with non-zero flags", __func__));
115
116 if (s == NULL) {
117 s = (struct sbuf *)SBMALLOC(sizeof *s);
118 if (s == NULL)
119 return (NULL);
120 bzero(s, sizeof *s);
121 SBUF_SETFLAG(s, SBUF_DYNSTRUCT);
122 } else {

--- 17 unchanged lines hidden (view full) ---

140#ifdef _KERNEL
141/*
142 * Create an sbuf with uio data
143 */
144struct sbuf *
145sbuf_uionew(struct sbuf *s, struct uio *uio, int *error)
146{
147 KASSERT(uio != NULL,
115
116 if (s == NULL) {
117 s = (struct sbuf *)SBMALLOC(sizeof *s);
118 if (s == NULL)
119 return (NULL);
120 bzero(s, sizeof *s);
121 SBUF_SETFLAG(s, SBUF_DYNSTRUCT);
122 } else {

--- 17 unchanged lines hidden (view full) ---

140#ifdef _KERNEL
141/*
142 * Create an sbuf with uio data
143 */
144struct sbuf *
145sbuf_uionew(struct sbuf *s, struct uio *uio, int *error)
146{
147 KASSERT(uio != NULL,
148 (__FUNCTION__ " called with NULL uio pointer"));
148 ("%s called with NULL uio pointer", __func__));
149 KASSERT(error != NULL,
149 KASSERT(error != NULL,
150 (__FUNCTION__ " called with NULL error pointer"));
150 ("%s called with NULL error pointer", __func__));
151
152 s = sbuf_new(s, NULL, uio->uio_resid + 1, 0);
153 if (s == NULL) {
154 *error = ENOMEM;
155 return (NULL);
156 }
157 *error = uiomove(s->s_buf, uio->uio_resid, uio);
158 if (*error != 0) {

--- 173 unchanged lines hidden (view full) ---

332{
333 va_list ap;
334 int len;
335
336 assert_sbuf_integrity(s);
337 assert_sbuf_state(s, 0);
338
339 KASSERT(fmt != NULL,
151
152 s = sbuf_new(s, NULL, uio->uio_resid + 1, 0);
153 if (s == NULL) {
154 *error = ENOMEM;
155 return (NULL);
156 }
157 *error = uiomove(s->s_buf, uio->uio_resid, uio);
158 if (*error != 0) {

--- 173 unchanged lines hidden (view full) ---

332{
333 va_list ap;
334 int len;
335
336 assert_sbuf_integrity(s);
337 assert_sbuf_state(s, 0);
338
339 KASSERT(fmt != NULL,
340 (__FUNCTION__ " called with a NULL format string"));
340 ("%s called with a NULL format string", __func__));
341
342 if (SBUF_HASOVERFLOWED(s))
343 return (-1);
344
345 va_start(ap, fmt);
346 len = vsnprintf(&s->s_buf[s->s_len], s->s_size - s->s_len, fmt, ap);
347 va_end(ap);
348

--- 124 unchanged lines hidden ---
341
342 if (SBUF_HASOVERFLOWED(s))
343 return (-1);
344
345 va_start(ap, fmt);
346 len = vsnprintf(&s->s_buf[s->s_len], s->s_size - s->s_len, fmt, ap);
347 va_end(ap);
348

--- 124 unchanged lines hidden ---