subr_sbuf.c (88950) | subr_sbuf.c (89121) |
---|---|
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 88950 2002-01-06 08:38:23Z kbyanc $ | 28 * $FreeBSD: head/sys/kern/subr_sbuf.c 89121 2002-01-09 07:29:28Z kbyanc $ |
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> --- 7 unchanged lines hidden (view full) --- 44#include <stdlib.h> 45#include <string.h> 46#endif /* _KERNEL */ 47 48#include <sys/sbuf.h> 49 50#ifdef _KERNEL 51MALLOC_DEFINE(M_SBUF, "sbuf", "string buffers"); | 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> --- 7 unchanged lines hidden (view full) --- 44#include <stdlib.h> 45#include <string.h> 46#endif /* _KERNEL */ 47 48#include <sys/sbuf.h> 49 50#ifdef _KERNEL 51MALLOC_DEFINE(M_SBUF, "sbuf", "string buffers"); |
52#define SBMALLOC(size) malloc(size, M_SBUF, M_WAITOK) 53#define SBFREE(buf) free(buf, M_SBUF) | 52#define SBMALLOC(size) malloc(size, M_SBUF, M_WAITOK) 53#define SBFREE(buf) free(buf, M_SBUF) |
54#else /* _KERNEL */ | 54#else /* _KERNEL */ |
55#define KASSERT(e, m) 56#define SBMALLOC(size) malloc(size) 57#define SBFREE(buf) free(buf) 58#define min(x,y) MIN(x,y) | 55#define KASSERT(e, m) 56#define SBMALLOC(size) malloc(size) 57#define SBFREE(buf) free(buf) 58#define min(x,y) MIN(x,y) |
59#endif /* _KERNEL */ 60 61/* 62 * Predicates 63 */ | 59#endif /* _KERNEL */ 60 61/* 62 * Predicates 63 */ |
64#define SBUF_ISDYNAMIC(s) ((s)->s_flags & SBUF_DYNAMIC) 65#define SBUF_ISDYNSTRUCT(s) ((s)->s_flags & SBUF_DYNSTRUCT) 66#define SBUF_ISFINISHED(s) ((s)->s_flags & SBUF_FINISHED) 67#define SBUF_HASOVERFLOWED(s) ((s)->s_flags & SBUF_OVERFLOWED) 68#define SBUF_HASROOM(s) ((s)->s_len < (s)->s_size - 1) | 64#define SBUF_ISDYNAMIC(s) ((s)->s_flags & SBUF_DYNAMIC) 65#define SBUF_ISDYNSTRUCT(s) ((s)->s_flags & SBUF_DYNSTRUCT) 66#define SBUF_ISFINISHED(s) ((s)->s_flags & SBUF_FINISHED) 67#define SBUF_HASOVERFLOWED(s) ((s)->s_flags & SBUF_OVERFLOWED) 68#define SBUF_HASROOM(s) ((s)->s_len < (s)->s_size - 1) |
69#define SBUF_FREESPACE(s) ((s)->s_size - (s)->s_len - 1) 70#define SBUF_CANEXTEND(s) ((s)->s_flags & SBUF_AUTOEXTEND) 71 72/* 73 * Set / clear flags 74 */ | 69#define SBUF_FREESPACE(s) ((s)->s_size - (s)->s_len - 1) 70#define SBUF_CANEXTEND(s) ((s)->s_flags & SBUF_AUTOEXTEND) 71 72/* 73 * Set / clear flags 74 */ |
75#define SBUF_SETFLAG(s, f) do { (s)->s_flags |= (f); } while (0) 76#define SBUF_CLEARFLAG(s, f) do { (s)->s_flags &= ~(f); } while (0) | 75#define SBUF_SETFLAG(s, f) do { (s)->s_flags |= (f); } while (0) 76#define SBUF_CLEARFLAG(s, f) do { (s)->s_flags &= ~(f); } while (0) |
77 | 77 |
78#define SBUF_MINEXTENDSIZE 16 /* Should be power of 2. */ 79#define SBUF_MAXEXTENDSIZE PAGE_SIZE 80#define SBUF_MAXEXTENDINCR PAGE_SIZE | 78#define SBUF_MINEXTENDSIZE 16 /* Should be power of 2. */ 79#define SBUF_MAXEXTENDSIZE PAGE_SIZE 80#define SBUF_MAXEXTENDINCR PAGE_SIZE |
81 82/* 83 * Debugging support 84 */ 85#if defined(_KERNEL) && defined(INVARIANTS) 86static void 87_assert_sbuf_integrity(char *fun, struct sbuf *s) 88{ --- 7 unchanged lines hidden (view full) --- 96 97static void 98_assert_sbuf_state(char *fun, struct sbuf *s, int state) 99{ 100 KASSERT((s->s_flags & SBUF_FINISHED) == state, 101 ("%s called with %sfinished or corrupt sbuf", fun, 102 (state ? "un" : ""))); 103} | 81 82/* 83 * Debugging support 84 */ 85#if defined(_KERNEL) && defined(INVARIANTS) 86static void 87_assert_sbuf_integrity(char *fun, struct sbuf *s) 88{ --- 7 unchanged lines hidden (view full) --- 96 97static void 98_assert_sbuf_state(char *fun, struct sbuf *s, int state) 99{ 100 KASSERT((s->s_flags & SBUF_FINISHED) == state, 101 ("%s called with %sfinished or corrupt sbuf", fun, 102 (state ? "un" : ""))); 103} |
104#define assert_sbuf_integrity(s) _assert_sbuf_integrity(__func__, (s)) 105#define assert_sbuf_state(s, i) _assert_sbuf_state(__func__, (s), (i)) | 104#define assert_sbuf_integrity(s) _assert_sbuf_integrity(__func__, (s)) 105#define assert_sbuf_state(s, i) _assert_sbuf_state(__func__, (s), (i)) |
106#else /* _KERNEL && INVARIANTS */ | 106#else /* _KERNEL && INVARIANTS */ |
107#define assert_sbuf_integrity(s) do { } while (0) 108#define assert_sbuf_state(s, i) do { } while (0) | 107#define assert_sbuf_integrity(s) do { } while (0) 108#define assert_sbuf_state(s, i) do { } while (0) |
109#endif /* _KERNEL && INVARIANTS */ 110 111static int 112sbuf_extendsize(int size) 113{ 114 int newsize; 115 116 newsize = SBUF_MINEXTENDSIZE; --- 444 unchanged lines hidden --- | 109#endif /* _KERNEL && INVARIANTS */ 110 111static int 112sbuf_extendsize(int size) 113{ 114 int newsize; 115 116 newsize = SBUF_MINEXTENDSIZE; --- 444 unchanged lines hidden --- |