--------------------- PatchSet 2986 Date: 2001/09/09 11:55:05 Author: serassio Branch: nt-2_3-tolsty Tag: (none) Log: Fixed indent problems Members: lib/GNUregex.c:1.1.1.1.42.1.2.1->1.1.1.1.42.1.2.2 lib/base64.c:1.1.1.1.40.1.2.1->1.1.1.1.40.1.2.2 lib/dlmalloc.c:1.1.1.1.44.2.2.1->1.1.1.1.44.2.2.2 lib/drand48.c:1.1.1.2.122.1->1.1.1.2.122.2 lib/encrypt.c:1.1.2.1.2.1->1.1.2.1.2.2 lib/hash.c:1.1.1.3.4.1.2.1.2.1->1.1.1.3.4.1.2.1.2.2 lib/html_quote.c:1.1.30.1.2.1.2.1->1.1.30.1.2.1.2.2 lib/md5-test.c:1.1.1.1.44.1.2.1->1.1.1.1.44.1.2.2 lib/md5.c:1.1.1.2.30.1.2.1->1.1.1.2.30.1.2.2 lib/radix.c:1.1.1.2.4.1.2.1.2.1->1.1.1.2.4.1.2.1.2.2 lib/readdir.c:1.1.78.1.2.1->1.1.78.1.2.2 lib/rfc1035.c:1.1.1.1.4.3.2.1.2.1->1.1.1.1.4.3.2.1.2.2 lib/rfc1738.c:1.1.1.2.4.1.2.2.2.1->1.1.1.2.4.1.2.2.2.2 lib/snprintf.c:1.1.1.3.30.1.2.1->1.1.1.3.30.1.2.2 lib/splay.c:1.1.1.2.2.1.2.1->1.1.1.2.2.1.2.2 lib/uudecode.c:1.1.1.1.44.1.2.1->1.1.1.1.44.1.2.2 Index: squid/lib/GNUregex.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/GNUregex.c,v retrieving revision 1.1.1.1.42.1.2.1 retrieving revision 1.1.1.1.42.1.2.2 diff -u -r1.1.1.1.42.1.2.1 -r1.1.1.1.42.1.2.2 --- squid/lib/GNUregex.c 27 Aug 2001 21:48:17 -0000 1.1.1.1.42.1.2.1 +++ squid/lib/GNUregex.c 9 Sep 2001 11:55:05 -0000 1.1.1.1.42.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: GNUregex.c,v 1.1.1.1.42.1.2.1 2001/08/27 21:48:17 tolsty Exp $ + * $Id: GNUregex.c,v 1.1.1.1.42.1.2.2 2001/09/09 11:55:05 serassio Exp $ */ /* Extended regular expression matching and search library, @@ -242,8 +242,7 @@ * So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of * `exactn' we use here must also be 1. */ -typedef enum -{ +typedef enum { no_op = 0, /* Followed by one byte giving n, then by n literal bytes. */ @@ -358,8 +357,9 @@ wordbound, /* Succeeds if at a word boundary. */ notwordbound /* Succeeds if not at a word boundary. */ + #ifdef emacs - , before_dot, /* Succeeds if before point. */ + ,before_dot, /* Succeeds if before point. */ at_dot, /* Succeeds if at point. */ after_dot, /* Succeeds if after point. */ @@ -370,8 +370,7 @@ /* Matches any character whose syntax is not that specified. */ notsyntaxspec #endif /* emacs */ -} -re_opcode_t; +} re_opcode_t; /* Common operations on the compiled pattern. */ @@ -787,7 +786,7 @@ reg_syntax_t re_set_syntax(syntax) -reg_syntax_t syntax; + reg_syntax_t syntax; { reg_syntax_t ret = re_syntax_options; @@ -798,7 +797,8 @@ /* This table gives an error message for each of the error codes listed * in regex.h. Obviously the order here has to be same as there. */ -static const char *re_error_msg[] = { NULL, /* REG_NOERROR */ +static const char *re_error_msg[] = +{NULL, /* REG_NOERROR */ "No match", /* REG_NOMATCH */ "Invalid regular expression", /* REG_BADPAT */ "Invalid collation character", /* REG_ECOLLATE */ @@ -960,24 +960,20 @@ * be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ typedef int pattern_offset_t; -typedef struct -{ +typedef struct { pattern_offset_t begalt_offset; pattern_offset_t fixup_alt_jump; pattern_offset_t inner_group_offset; pattern_offset_t laststart_offset; regnum_t regnum; -} -compile_stack_elt_t; +} compile_stack_elt_t; -typedef struct -{ +typedef struct { compile_stack_elt_t *stack; unsigned size; unsigned avail; /* Offset of next open position. */ -} -compile_stack_type; +} compile_stack_type; #define INIT_COMPILE_STACK_SIZE 32 @@ -1157,9 +1153,9 @@ { if ( /* If at start of pattern, it's an operator. */ p == pattern + 1 - /* If context independent, it's an operator. */ + /* If context independent, it's an operator. */ || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's come before. */ + /* Otherwise, depends on what's come before. */ || at_begline_loc_p(pattern, p, syntax)) BUF_PUSH(begline); else @@ -1172,9 +1168,9 @@ { if ( /* If at end of pattern, it's an operator. */ p == pend - /* If context independent, it's an operator. */ + /* If context independent, it's an operator. */ || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's next. */ + /* Otherwise, depends on what's next. */ || at_endline_loc_p(p, pend, syntax)) BUF_PUSH(endline); else @@ -1218,8 +1214,7 @@ PATFETCH(c); if (c == '*' - || (!(syntax & RE_BK_PLUS_QM) && (c == '+' - || c == '?'))); + || (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?'))); else if (syntax & RE_BK_PLUS_QM && c == '\\') { if (p == pend) @@ -1284,7 +1279,8 @@ * end of the buffer after this jump is inserted. */ GET_BUFFER_SPACE(3); INSERT_JUMP(keep_string_p ? on_failure_keep_string_jump - : on_failure_jump, laststart, b + 3); + : on_failure_jump, + laststart, b + 3); pending_exact = 0; b += 3; @@ -1338,7 +1334,8 @@ /* charset_not matches newline according to a syntax bit. */ if ((re_opcode_t) b[-2] == charset_not - && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) SET_LIST_BIT('\n'); + && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) + SET_LIST_BIT('\n'); /* Read in characters and ranges, setting map bits. */ for (;;) { @@ -1371,11 +1368,12 @@ * was a character: if this is a hyphen not at the * beginning or the end of a list, then it's the range * operator. */ - if (c == '-' && !(p - 2 >= pattern && p[-2] == '[') + if (c == '-' + && !(p - 2 >= pattern && p[-2] == '[') && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^') && *p != ']') { reg_errcode_t ret - = compile_range(&p, pend, translate, syntax, b); + = compile_range(&p, pend, translate, syntax, b); if (ret != REG_NOERROR) return ret; } else if (p[0] == '-' && p[1] != ']') { /* This handles ranges made up of characters only. */ @@ -1404,7 +1402,8 @@ for (;;) { PATFETCH(c); if (c == ':' || c == ']' || p == pend - || c1 == CHAR_CLASS_MAX_LENGTH) break; + || c1 == CHAR_CLASS_MAX_LENGTH) + break; str[c1++] = c; } str[c1] = '\0'; @@ -1612,8 +1611,7 @@ = COMPILE_STACK_TOP.fixup_alt_jump ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 : 0; - laststart = - bufp->buffer + COMPILE_STACK_TOP.laststart_offset; + laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; this_group_regnum = COMPILE_STACK_TOP.regnum; /* If we've reached MAX_REGNUM groups, then this open * won't actually generate any code, so we'll have to @@ -1624,8 +1622,7 @@ * groups were inside this one. */ if (this_group_regnum <= MAX_REGNUM) { unsigned char *inner_group_loc - = - bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; + = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; *inner_group_loc = regnum - this_group_regnum; BUF_PUSH_3(stop_memory, this_group_regnum, @@ -1683,8 +1680,8 @@ case '{': /* If \{ is a literal. */ if (!(syntax & RE_INTERVALS) - /* If we're at `\{' and it's not the open-interval - * operator. */ + /* If we're at `\{' and it's not the open-interval + * operator. */ || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) || (p - 2 == pattern && p == pend)) goto normal_backslash; @@ -1773,7 +1770,8 @@ * because `re_compile_fastmap' needs to know. * Jump to the `jump_n' we might insert below. */ INSERT_JUMP2(succeed_n, laststart, - b + 5 + (upper_bound > 1) * 5, lower_bound); + b + 5 + (upper_bound > 1) * 5, + lower_bound); b += 5; /* Code to initialize the lower bound. Insert @@ -1939,17 +1937,22 @@ normal_char: /* If no exactn currently being built. */ if (!pending_exact - /* If last exactn not at current position. */ + + /* If last exactn not at current position. */ || pending_exact + *pending_exact + 1 != b - /* We have only one byte following the exactn for the count. */ + + /* We have only one byte following the exactn for the count. */ || *pending_exact == (1 << BYTEWIDTH) - 1 - /* If followed by a repetition operator. */ - || *p == '*' || *p == '^' || ((syntax & RE_BK_PLUS_QM) + + /* If followed by a repetition operator. */ + || *p == '*' || *p == '^' + || ((syntax & RE_BK_PLUS_QM) ? *p == '\\' && (p[1] == '+' || p[1] == '?') : (*p == '+' || *p == '?')) || ((syntax & RE_INTERVALS) && ((syntax & RE_NO_BK_BRACES) - ? *p == '{' : (p[0] == '\\' && p[1] == '{')))) { + ? *p == '{' + : (p[0] == '\\' && p[1] == '{')))) { /* Start building a new exactn. */ laststart = b; @@ -2068,9 +2071,9 @@ boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; return - /* After a subexpression? */ + /* After a subexpression? */ (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) - /* After an alternative? */ + /* After an alternative? */ || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash)); } @@ -2088,10 +2091,10 @@ const char *next_next = p + 1 < pend ? p + 1 : NULL; return - /* Before a subexpression? */ + /* Before a subexpression? */ (syntax & RE_NO_BK_PARENS ? *next == ')' : next_backslash && next_next && *next_next == ')') - /* Before an alternative? */ + /* Before an alternative? */ || (syntax & RE_NO_BK_VBAR ? *next == '|' : next_backslash && next_next && *next_next == '|'); } @@ -2108,7 +2111,8 @@ int this_element; for (this_element = compile_stack.avail - 1; - this_element >= 0; this_element--) + this_element >= 0; + this_element--) if (compile_stack.stack[this_element].regnum == regnum) return true; @@ -2191,13 +2195,11 @@ typedef const unsigned char *fail_stack_elt_t; -typedef struct -{ +typedef struct { fail_stack_elt_t *stack; unsigned size; unsigned avail; /* Offset of next open position. */ -} -fail_stack_type; +} fail_stack_type; #define FAIL_STACK_EMPTY() (fail_stack.avail == 0) #define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0) @@ -2489,7 +2491,7 @@ assert(fastmap != NULL && p != NULL); INIT_FAIL_STACK(); - memset(fastmap, 0, 1 << BYTEWIDTH); /* Assume nothing's valid. */ + memset(fastmap, 0, 1 << BYTEWIDTH); /* Assume nothing's valid. */ bufp->fastmap_accurate = 1; /* It will be when we're done. */ bufp->can_be_null = 0; @@ -2638,7 +2640,8 @@ * ordinary jump. For a * loop, it has pushed its failure * point already; if so, discard that as redundant. */ if ((re_opcode_t) * p != on_failure_jump - && (re_opcode_t) * p != succeed_n) continue; + && (re_opcode_t) * p != succeed_n) + continue; p++; EXTRACT_NUMBER_AND_INCR(j, p); @@ -2852,7 +2855,8 @@ /* Written out as an if-else to avoid testing `translate' * inside the loop. */ if (translate) - while (range > lim && !fastmap[(unsigned char) + while (range > lim + && !fastmap[(unsigned char) translate[(unsigned char) *d++]]) range--; else @@ -2871,7 +2875,8 @@ } /* If can't match the null string, and that's all we have left, fail. */ if (range >= 0 && startpos == total_size && fastmap - && !bufp->can_be_null) return -1; + && !bufp->can_be_null) + return -1; val = re_match_2(bufp, string1, size1, string2, size2, startpos, regs, stop); @@ -2899,7 +2904,7 @@ static int bcmp_translate(); static boolean alt_match_null_string_p(), common_op_match_null_string_p(), -group_match_null_string_p(); + group_match_null_string_p(); /* Structure for per-register (a.k.a. per-group) information. * This must not be longer than one word, because we push this value @@ -2912,11 +2917,9 @@ * the compiler will pack our bit fields into something that fits into * the type of `word', i.e., is something that fits into one item on the * failure stack. */ -typedef union -{ +typedef union { fail_stack_elt_t word; - struct - { + struct { /* This field is one if this group can match the empty string, * zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */ #define MATCH_NULL_UNSET_VALUE 3 @@ -2924,10 +2927,8 @@ unsigned is_active:1; unsigned matched_something:1; unsigned ever_matched_something:1; - } - bits; -} -register_info_type; + } bits; +} register_info_type; #define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p) #define IS_ACTIVE(R) ((R).bits.is_active) @@ -3281,7 +3282,8 @@ == MATCHING_IN_FIRST_STRING); /* If exceeds best match so far, save it. */ - if (!best_regs_set || (same_str_p && d > match_end) + if (!best_regs_set + || (same_str_p && d > match_end) || (!same_str_p && !MATCHING_IN_FIRST_STRING)) { best_regs_set = true; match_end = d; @@ -3320,9 +3322,9 @@ /* If caller wants register contents data back, do it. */ if (regs && !bufp->no_sub) { /* Have the register data arrays been allocated? */ - if (bufp->regs_allocated == REGS_UNALLOCATED) { /* No. So allocate them with malloc. We need one - * extra element beyond `num_regs' for the `-1' marker - * GNU code uses. */ + if (bufp->regs_allocated == REGS_UNALLOCATED) { /* No. So allocate them with malloc. We need one + * extra element beyond `num_regs' for the `-1' marker + * GNU code uses. */ regs->num_regs = MAX(RE_NREGS, num_regs + 1); regs->start = TALLOC(regs->num_regs, regoff_t); regs->end = TALLOC(regs->num_regs, regoff_t); @@ -3376,7 +3378,8 @@ DEBUG_PRINT2("%u registers pushed.\n", num_regs_pushed); mcnt = d - pos - (MATCHING_IN_FIRST_STRING - ? string1 : string2 - size1); + ? string1 + : string2 - size1); DEBUG_PRINT2("Returning %d from re_match_2.\n", mcnt); @@ -3688,7 +3691,8 @@ /* Compare that many; failure if mismatch, else move * past them. */ - if (translate ? bcmp_translate(d, d2, mcnt, translate) + if (translate + ? bcmp_translate(d, d2, mcnt, translate) : memcmp(d, d2, mcnt)) goto fail; d += mcnt, d2 += mcnt; @@ -3846,7 +3850,7 @@ /* Skip over open/close-group commands. */ while (p2 + 2 < pend && ((re_opcode_t) * p2 == stop_memory - || (re_opcode_t) * p2 == start_memory)) + || (re_opcode_t) * p2 == start_memory)) p2 += 3; /* Skip over args, too. */ /* If we're at the end of the pattern, we can change. */ @@ -3860,7 +3864,7 @@ } else if ((re_opcode_t) * p2 == exactn || (bufp->newline_anchor && (re_opcode_t) * p2 == endline)) { register unsigned char c - = *p2 == (unsigned char) endline ? '\n' : p2[2]; + = *p2 == (unsigned char) endline ? '\n' : p2[2]; p1 = p + mcnt; /* p1[0] ... p1[2] are the `on_failure_jump' corresponding @@ -3977,8 +3981,7 @@ STORE_NUMBER_AND_INCR(p, mcnt); DEBUG_PRINT3(" Setting 0x%x to %d.\n", p, mcnt); } else if (mcnt == 0) { - DEBUG_PRINT2(" Setting two bytes from 0x%x to no_op.\n", - p + 2); + DEBUG_PRINT2(" Setting two bytes from 0x%x to no_op.\n", p + 2); p[2] = (unsigned char) no_op; p[3] = (unsigned char) no_op; goto on_failure; @@ -4152,7 +4155,7 @@ if ((is_a_jump_n && (re_opcode_t) * p1 == succeed_n) || (!is_a_jump_n && (re_opcode_t) * p1 == on_failure_jump)) - goto fail; + goto fail; break; default: /* do nothing */ ; @@ -4232,7 +4235,8 @@ * is, including the ending `jump_past_alt' and * its number. */ - if (!alt_match_null_string_p(p1, p1 + mcnt - 3, reg_info)) + if (!alt_match_null_string_p(p1, p1 + mcnt - 3, + reg_info)) return false; /* Move to right after this alternative, including the @@ -4558,8 +4562,8 @@ { reg_errcode_t ret; unsigned syntax - = (cflags & REG_EXTENDED) ? - RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; + = (cflags & REG_EXTENDED) ? + RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; /* regex_compile will allocate the space for the compiled pattern. */ preg->buffer = 0; @@ -4685,7 +4689,7 @@ int errcode; const regex_t *preg; char *errbuf; -size_t errbuf_size; + size_t errbuf_size; { const char *msg; size_t msg_size; Index: squid/lib/base64.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/base64.c,v retrieving revision 1.1.1.1.40.1.2.1 retrieving revision 1.1.1.1.40.1.2.2 diff -u -r1.1.1.1.40.1.2.1 -r1.1.1.1.40.1.2.2 --- squid/lib/base64.c 27 Aug 2001 21:48:17 -0000 1.1.1.1.40.1.2.1 +++ squid/lib/base64.c 9 Sep 2001 11:55:05 -0000 1.1.1.1.40.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: base64.c,v 1.1.1.1.40.1.2.1 2001/08/27 21:48:17 tolsty Exp $ + * $Id: base64.c,v 1.1.1.1.40.1.2.2 2001/09/09 11:55:05 serassio Exp $ */ #include "config.h" @@ -17,8 +17,7 @@ #define BASE64_VALUE_SZ 256 #define BASE64_RESULT_SZ 8192 int base64_value[BASE64_VALUE_SZ]; -const char base64_code[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +const char base64_code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static void Index: squid/lib/dlmalloc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/dlmalloc.c,v retrieving revision 1.1.1.1.44.2.2.1 retrieving revision 1.1.1.1.44.2.2.2 diff -u -r1.1.1.1.44.2.2.1 -r1.1.1.1.44.2.2.2 --- squid/lib/dlmalloc.c 27 Aug 2001 21:48:17 -0000 1.1.1.1.44.2.2.1 +++ squid/lib/dlmalloc.c 9 Sep 2001 11:55:05 -0000 1.1.1.1.44.2.2.2 @@ -1,5 +1,5 @@ /* - * $Id: dlmalloc.c,v 1.1.1.1.44.2.2.1 2001/08/27 21:48:17 tolsty Exp $ + * $Id: dlmalloc.c,v 1.1.1.1.44.2.2.2 2001/09/09 11:55:05 serassio Exp $ */ /* ---------- To make a malloc.h, start cutting here ------------ */ @@ -214,8 +214,8 @@ */ - + /* Preliminaries */ @@ -238,20 +238,19 @@ #else #define Void_t char #endif -#endif /*Void_t */ +#endif /*Void_t*/ #if __STD_C -#include /* for size_t */ +#include /* for size_t */ #else #include #endif #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif -#include /* needed for malloc_stats */ +#include /* needed for malloc_stats */ /* @@ -283,7 +282,7 @@ */ -#if DEBUG +#if DEBUG #include #else #define assert(x) ((void)0) @@ -339,7 +338,7 @@ */ -#define HAVE_MEMCPY +#define HAVE_MEMCPY #ifndef USE_MEMCPY #ifdef HAVE_MEMCPY @@ -349,14 +348,14 @@ #endif #endif -#if (__STD_C || defined(HAVE_MEMCPY)) +#if (__STD_C || defined(HAVE_MEMCPY)) #if __STD_C - void *memset(void *, int, size_t); - void *memcpy(void *, const void *, size_t); +void* memset(void*, int, size_t); +void* memcpy(void*, const void*, size_t); #else - Void_t *memset(); - Void_t *memcpy(); +Void_t* memset(); +Void_t* memcpy(); #endif #endif @@ -401,7 +400,7 @@ } else memcpy(dest, src, mcsz); \ } while(0) -#else /* !USE_MEMCPY */ +#else /* !USE_MEMCPY */ /* Use Duff's device for good zeroing/copying performance. */ @@ -477,7 +476,7 @@ #define MAP_ANONYMOUS MAP_ANON #endif -#endif /* HAVE_MMAP */ +#endif /* HAVE_MMAP */ /* Access to system page size. To the extent possible, this malloc @@ -492,7 +491,7 @@ #endif #ifndef malloc_getpagesize -# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ +# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ # ifndef _SC_PAGE_SIZE # define _SC_PAGE_SIZE _SC_PAGESIZE # endif @@ -501,7 +500,7 @@ # define malloc_getpagesize sysconf(_SC_PAGE_SIZE) # else # if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE) - extern size_t getpagesize(); + extern size_t getpagesize(); # define malloc_getpagesize getpagesize() # else # include @@ -514,19 +513,19 @@ # else # define malloc_getpagesize (NBPG * CLSIZE) # endif -# else +# else # ifdef NBPC # define malloc_getpagesize NBPC # else # ifdef PAGESIZE # define malloc_getpagesize PAGESIZE # else -# define malloc_getpagesize (4096) /* just guess */ +# define malloc_getpagesize (4096) /* just guess */ # endif # endif -# endif +# endif # endif -# endif +# endif # endif #endif @@ -565,26 +564,25 @@ /* SVID2/XPG mallinfo structure */ - struct mallinfo - { - int arena; /* total space allocated from system */ - int ordblks; /* number of non-inuse chunks */ - int smblks; /* unused -- always zero */ - int hblks; /* number of mmapped regions */ - int hblkhd; /* total space in mmapped regions */ - int usmblks; /* unused -- always zero */ - int fsmblks; /* unused -- always zero */ - int uordblks; /* total allocated space */ - int fordblks; /* total non-inuse space */ - int keepcost; /* top-most, releasable (via malloc_trim) space */ - }; +struct mallinfo { + int arena; /* total space allocated from system */ + int ordblks; /* number of non-inuse chunks */ + int smblks; /* unused -- always zero */ + int hblks; /* number of mmapped regions */ + int hblkhd; /* total space in mmapped regions */ + int usmblks; /* unused -- always zero */ + int fsmblks; /* unused -- always zero */ + int uordblks; /* total allocated space */ + int fordblks; /* total non-inuse space */ + int keepcost; /* top-most, releasable (via malloc_trim) space */ +}; /* SVID2/XPG mallopt options */ -#define M_MXFAST 1 /* UNUSED in this malloc */ -#define M_NLBLKS 2 /* UNUSED in this malloc */ -#define M_GRAIN 3 /* UNUSED in this malloc */ -#define M_KEEP 4 /* UNUSED in this malloc */ +#define M_MXFAST 1 /* UNUSED in this malloc */ +#define M_NLBLKS 2 /* UNUSED in this malloc */ +#define M_GRAIN 3 /* UNUSED in this malloc */ +#define M_KEEP 4 /* UNUSED in this malloc */ #endif @@ -778,26 +776,26 @@ #if __STD_C - Void_t *__default_morecore_init(ptrdiff_t); - Void_t *(*__morecore) (ptrdiff_t) = __default_morecore_init; +Void_t * __default_morecore_init (ptrdiff_t); +Void_t *(*__morecore)(ptrdiff_t) = __default_morecore_init; #else - Void_t *__default_morecore_init(); - Void_t *(*__morecore) () = __default_morecore_init; +Void_t * __default_morecore_init (); +Void_t *(*__morecore)() = __default_morecore_init; #endif #define MORECORE (*__morecore) #define MORECORE_FAILURE 0 -#define MORECORE_CLEARS 1 +#define MORECORE_CLEARS 1 -#else /* INTERNAL_LINUX_C_LIB */ +#else /* INTERNAL_LINUX_C_LIB */ #if __STD_C - extern Void_t *sbrk(ptrdiff_t); +extern Void_t* sbrk(ptrdiff_t); #else - extern Void_t *sbrk(); +extern Void_t* sbrk(); #endif #ifndef MORECORE @@ -812,7 +810,7 @@ #define MORECORE_CLEARS 1 #endif -#endif /* INTERNAL_LINUX_C_LIB */ +#endif /* INTERNAL_LINUX_C_LIB */ #if defined(INTERNAL_LINUX_C_LIB) && defined(__ELF__) @@ -856,38 +854,38 @@ #if __STD_C - Void_t *mALLOc(size_t); - void fREe(Void_t *); - Void_t *rEALLOc(Void_t *, size_t); - Void_t *mEMALIGn(size_t, size_t); - Void_t *vALLOc(size_t); - Void_t *pvALLOc(size_t); - Void_t *cALLOc(size_t, size_t); - void cfree(Void_t *); - int malloc_trim(size_t); - size_t malloc_usable_size(Void_t *); - void malloc_stats(); - int mALLOPt(int, int); - struct mallinfo mALLINFo(void); -#else - Void_t *mALLOc(); - void fREe(); - Void_t *rEALLOc(); - Void_t *mEMALIGn(); - Void_t *vALLOc(); - Void_t *pvALLOc(); - Void_t *cALLOc(); - void cfree(); - int malloc_trim(); - size_t malloc_usable_size(); - void malloc_stats(); - int mALLOPt(); - struct mallinfo mALLINFo(); +Void_t* mALLOc(size_t); +void fREe(Void_t*); +Void_t* rEALLOc(Void_t*, size_t); +Void_t* mEMALIGn(size_t, size_t); +Void_t* vALLOc(size_t); +Void_t* pvALLOc(size_t); +Void_t* cALLOc(size_t, size_t); +void cfree(Void_t*); +int malloc_trim(size_t); +size_t malloc_usable_size(Void_t*); +void malloc_stats(); +int mALLOPt(int, int); +struct mallinfo mALLINFo(void); +#else +Void_t* mALLOc(); +void fREe(); +Void_t* rEALLOc(); +Void_t* mEMALIGn(); +Void_t* vALLOc(); +Void_t* pvALLOc(); +Void_t* cALLOc(); +void cfree(); +int malloc_trim(); +size_t malloc_usable_size(); +void malloc_stats(); +int mALLOPt(); +struct mallinfo mALLINFo(); #endif #ifdef __cplusplus -}; /* end of extern "C" */ +}; /* end of extern "C" */ #endif /* ---------- To make a malloc.h, end cutting here ------------ */ @@ -902,146 +900,163 @@ #ifdef WIN32 #define AlignPage(add) (((add) + (malloc_getpagesize-1)) & -~(malloc_getpagesize - 1)) +~(malloc_getpagesize-1)) -/* resrve 64MB to insure large contiguous space */ +/* resrve 64MB to insure large contiguous space */ #define RESERVED_SIZE (1024*1024*64) #define NEXT_SIZE (2048*1024) #define TOP_MEMORY ((unsigned long)2*1024*1024*1024) - struct GmListElement; - typedef struct GmListElement GmListElement; - struct GmListElement - { - GmListElement *next; - void *base; - }; +struct GmListElement; +typedef struct GmListElement GmListElement; -static GmListElement *head = 0; +struct GmListElement +{ + GmListElement* next; + void* base; +}; + +static GmListElement* head = 0; static unsigned int gNextAddress = 0; static unsigned int gAddressBase = 0; static unsigned int gAllocatedSize = 0; -static GmListElement *makeGmListElement(void *bas) +static +GmListElement* makeGmListElement (void* bas) { - GmListElement *this; - this = (GmListElement *) (void *) LocalAlloc(0, sizeof(GmListElement)); - ASSERT(this); - if (this) - { - this->base = bas; - this->next = head; - head = this; - } - return this; + GmListElement* this; + this = (GmListElement*)(void*)LocalAlloc (0, sizeof (GmListElement)); + ASSERT (this); + if (this) + { + this->base = bas; + this->next = head; + head = this; + } + return this; } -void gcleanup() +void gcleanup () { - BOOL rval; - ASSERT((head == NULL) || (head->base == (void *) gAddressBase)); - if (gAddressBase && (gNextAddress - gAddressBase)) { - rval = VirtualFree((void *) gAddressBase, - gNextAddress - gAddressBase, MEM_DECOMMIT); - ASSERT(rval); - } - while (head) { - GmListElement *next = head->next; - rval = VirtualFree(head->base, 0, MEM_RELEASE); - ASSERT(rval); - LocalFree(head); - head = next; - } + BOOL rval; + ASSERT ( (head == NULL) || (head->base == (void*)gAddressBase)); + if (gAddressBase && (gNextAddress - gAddressBase)) + { + rval = VirtualFree ((void*)gAddressBase, + gNextAddress - gAddressBase, + MEM_DECOMMIT); + ASSERT (rval); + } + while (head) + { + GmListElement* next = head->next; + rval = VirtualFree (head->base, 0, MEM_RELEASE); + ASSERT (rval); + LocalFree (head); + head = next; + } } - -static void *findRegion(void *start_address, unsigned long size) + +static +void* findRegion (void* start_address, unsigned long size) { - MEMORY_BASIC_INFORMATION info; - while ((unsigned long) start_address < TOP_MEMORY) - { - VirtualQuery(start_address, &info, sizeof(info)); - if (info.State != MEM_FREE) - start_address = (char *) info.BaseAddress + info.RegionSize; - else if (info.RegionSize >= size) - return start_address; - else - start_address = (char *) info.BaseAddress + info.RegionSize; - } - return NULL; - + MEMORY_BASIC_INFORMATION info; + while ((unsigned long)start_address < TOP_MEMORY) + { + VirtualQuery (start_address, &info, sizeof (info)); + if (info.State != MEM_FREE) + start_address = (char*)info.BaseAddress + info.RegionSize; + else if (info.RegionSize >= size) + return start_address; + else + start_address = (char*)info.BaseAddress + info.RegionSize; + } + return NULL; + } -void *wsbrk(long size) +void* wsbrk (long size) { - void *tmp; - if (size > 0) - { - if (gAddressBase == 0) { - gAllocatedSize = max(RESERVED_SIZE, AlignPage(size)); - gNextAddress = gAddressBase = - (unsigned int) VirtualAlloc(NULL, gAllocatedSize, - MEM_RESERVE, PAGE_NOACCESS); - } else if (AlignPage(gNextAddress + size) > (gAddressBase + - gAllocatedSize)) + void* tmp; + if (size > 0) { - long new_size = max(NEXT_SIZE, AlignPage(size)); - void *new_address = (void *) (gAddressBase + gAllocatedSize); - do { - new_address = findRegion(new_address, new_size); - - if (new_address == 0) - return (void *) -1; - - gAddressBase = gNextAddress = - (unsigned int) VirtualAlloc(new_address, new_size, - MEM_RESERVE, PAGE_NOACCESS); - // repeat in case of race condition - // The region that we found has been snagged - // by another thread - } - while (gAddressBase == 0); + if (gAddressBase == 0) + { + gAllocatedSize = max (RESERVED_SIZE, AlignPage (size)); + gNextAddress = gAddressBase = + (unsigned int)VirtualAlloc (NULL, gAllocatedSize, + MEM_RESERVE, PAGE_NOACCESS); + } else if (AlignPage (gNextAddress + size) > (gAddressBase + +gAllocatedSize)) + { + long new_size = max (NEXT_SIZE, AlignPage (size)); + void* new_address = (void*)(gAddressBase+gAllocatedSize); + do + { + new_address = findRegion (new_address, new_size); + + if (new_address == 0) + return (void*)-1; + + gAddressBase = gNextAddress = + (unsigned int)VirtualAlloc (new_address, new_size, + MEM_RESERVE, PAGE_NOACCESS); + // repeat in case of race condition + // The region that we found has been snagged + // by another thread + } + while (gAddressBase == 0); - ASSERT(new_address == (void *) gAddressBase); + ASSERT (new_address == (void*)gAddressBase); - gAllocatedSize = new_size; + gAllocatedSize = new_size; - if (!makeGmListElement((void *) gAddressBase)) - return (void *) -1; + if (!makeGmListElement ((void*)gAddressBase)) + return (void*)-1; + } + if ((size + gNextAddress) > AlignPage (gNextAddress)) + { + void* res; + res = VirtualAlloc ((void*)AlignPage (gNextAddress), + (size + gNextAddress - + AlignPage (gNextAddress)), + MEM_COMMIT, PAGE_READWRITE); + if (res == 0) + return (void*)-1; + } + tmp = (void*)gNextAddress; + gNextAddress = (unsigned int)tmp + size; + return tmp; } - if ((size + gNextAddress) > AlignPage(gNextAddress)) { - void *res; - res = VirtualAlloc((void *) AlignPage(gNextAddress), - (size + gNextAddress - - AlignPage(gNextAddress)), MEM_COMMIT, PAGE_READWRITE); - if (res == 0) - return (void *) -1; + else if (size < 0) + { + unsigned int alignedGoal = AlignPage (gNextAddress + size); + /* Trim by releasing the virtual memory */ + if (alignedGoal >= gAddressBase) + { + VirtualFree ((void*)alignedGoal, gNextAddress - alignedGoal, + MEM_DECOMMIT); + gNextAddress = gNextAddress + size; + return (void*)gNextAddress; + } + else + { + VirtualFree ((void*)gAddressBase, gNextAddress - gAddressBase, + MEM_DECOMMIT); + gNextAddress = gAddressBase; + return (void*)-1; + } } - tmp = (void *) gNextAddress; - gNextAddress = (unsigned int) tmp + size; - return tmp; - } else if (size < 0) { - unsigned int alignedGoal = AlignPage(gNextAddress + size); - /* Trim by releasing the virtual memory */ - if (alignedGoal >= gAddressBase) { - VirtualFree((void *) alignedGoal, gNextAddress - alignedGoal, - MEM_DECOMMIT); - gNextAddress = gNextAddress + size; - return (void *) gNextAddress; - } else { - VirtualFree((void *) gAddressBase, gNextAddress - gAddressBase, - MEM_DECOMMIT); - gNextAddress = gAddressBase; - return (void *) -1; + else + { + return (void*)gNextAddress; } - } else { - return (void *) gNextAddress; - } } #endif - + /* Type declarations @@ -1050,13 +1065,13 @@ struct malloc_chunk { - INTERNAL_SIZE_T prev_size; /* Size of previous chunk (if free). */ - INTERNAL_SIZE_T size; /* Size in bytes, including overhead. */ - struct malloc_chunk *fd; /* double links -- used only if free. */ - struct malloc_chunk *bk; + INTERNAL_SIZE_T prev_size; /* Size of previous chunk (if free). */ + INTERNAL_SIZE_T size; /* Size in bytes, including overhead. */ + struct malloc_chunk* fd; /* double links -- used only if free. */ + struct malloc_chunk* bk; }; -typedef struct malloc_chunk *mchunkptr; +typedef struct malloc_chunk* mchunkptr; /* @@ -1181,10 +1196,10 @@ serviced via calls to mmap, and then later released via munmap. */ - + /* sizes, alignments */ @@ -1209,9 +1224,9 @@ /* Check if m has acceptable alignment */ #define aligned_OK(m) (((unsigned long)((m)) & (MALLOC_ALIGN_MASK)) == 0) - + /* Physical chunk operations @@ -1220,7 +1235,7 @@ /* size field is or'ed with PREV_INUSE when previous adjacent chunk in use */ -#define PREV_INUSE 0x1 +#define PREV_INUSE 0x1 /* size field is or'ed with IS_MMAPPED if the chunk was obtained with mmap() */ @@ -1244,9 +1259,9 @@ /* Treat space at ptr + offset as a chunk */ #define chunk_at_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) - + /* Dealing with use bits @@ -1283,9 +1298,9 @@ #define clear_inuse_bit_at_offset(p, s)\ (((mchunkptr)(((char*)(p)) + (s)))->size &= ~(PREV_INUSE)) - + /* Dealing with size fields @@ -1306,9 +1321,9 @@ /* Set size at footer (only when chunk is not in use) */ #define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_size = (s)) - + /* @@ -1345,9 +1360,9 @@ */ -#define NAV 128 /* number of bins */ +#define NAV 128 /* number of bins */ -typedef struct malloc_chunk *mbinptr; +typedef struct malloc_chunk* mbinptr; /* access macros */ @@ -1361,8 +1376,8 @@ indexing, maintain locality, and avoid some initialization tests. */ -#define top (bin_at(0)->fd) /* The topmost chunk */ -#define last_remainder (bin_at(1)) /* remainder from last split */ +#define top (bin_at(0)->fd) /* The topmost chunk */ +#define last_remainder (bin_at(1)) /* remainder from last split */ /* @@ -1378,29 +1393,27 @@ #define IAV(i) bin_at(i), bin_at(i) -static mbinptr av_[NAV * 2 + 2] = -{ - 0, 0, - IAV(0), IAV(1), IAV(2), IAV(3), IAV(4), IAV(5), IAV(6), IAV(7), - IAV(8), IAV(9), IAV(10), IAV(11), IAV(12), IAV(13), IAV(14), IAV(15), - IAV(16), IAV(17), IAV(18), IAV(19), IAV(20), IAV(21), IAV(22), IAV(23), - IAV(24), IAV(25), IAV(26), IAV(27), IAV(28), IAV(29), IAV(30), IAV(31), - IAV(32), IAV(33), IAV(34), IAV(35), IAV(36), IAV(37), IAV(38), IAV(39), - IAV(40), IAV(41), IAV(42), IAV(43), IAV(44), IAV(45), IAV(46), IAV(47), - IAV(48), IAV(49), IAV(50), IAV(51), IAV(52), IAV(53), IAV(54), IAV(55), - IAV(56), IAV(57), IAV(58), IAV(59), IAV(60), IAV(61), IAV(62), IAV(63), - IAV(64), IAV(65), IAV(66), IAV(67), IAV(68), IAV(69), IAV(70), IAV(71), - IAV(72), IAV(73), IAV(74), IAV(75), IAV(76), IAV(77), IAV(78), IAV(79), - IAV(80), IAV(81), IAV(82), IAV(83), IAV(84), IAV(85), IAV(86), IAV(87), - IAV(88), IAV(89), IAV(90), IAV(91), IAV(92), IAV(93), IAV(94), IAV(95), - IAV(96), IAV(97), IAV(98), IAV(99), IAV(100), IAV(101), IAV(102), - IAV(103), IAV(104), IAV(105), IAV(106), IAV(107), IAV(108), IAV(109), - IAV(110), IAV(111), IAV(112), IAV(113), IAV(114), IAV(115), IAV(116), - IAV(117), IAV(118), IAV(119), IAV(120), IAV(121), IAV(122), IAV(123), - IAV(124), IAV(125), IAV(126), IAV(127) +static mbinptr av_[NAV * 2 + 2] = { + 0, 0, + IAV(0), IAV(1), IAV(2), IAV(3), IAV(4), IAV(5), IAV(6), IAV(7), + IAV(8), IAV(9), IAV(10), IAV(11), IAV(12), IAV(13), IAV(14), IAV(15), + IAV(16), IAV(17), IAV(18), IAV(19), IAV(20), IAV(21), IAV(22), IAV(23), + IAV(24), IAV(25), IAV(26), IAV(27), IAV(28), IAV(29), IAV(30), IAV(31), + IAV(32), IAV(33), IAV(34), IAV(35), IAV(36), IAV(37), IAV(38), IAV(39), + IAV(40), IAV(41), IAV(42), IAV(43), IAV(44), IAV(45), IAV(46), IAV(47), + IAV(48), IAV(49), IAV(50), IAV(51), IAV(52), IAV(53), IAV(54), IAV(55), + IAV(56), IAV(57), IAV(58), IAV(59), IAV(60), IAV(61), IAV(62), IAV(63), + IAV(64), IAV(65), IAV(66), IAV(67), IAV(68), IAV(69), IAV(70), IAV(71), + IAV(72), IAV(73), IAV(74), IAV(75), IAV(76), IAV(77), IAV(78), IAV(79), + IAV(80), IAV(81), IAV(82), IAV(83), IAV(84), IAV(85), IAV(86), IAV(87), + IAV(88), IAV(89), IAV(90), IAV(91), IAV(92), IAV(93), IAV(94), IAV(95), + IAV(96), IAV(97), IAV(98), IAV(99), IAV(100), IAV(101), IAV(102), IAV(103), + IAV(104), IAV(105), IAV(106), IAV(107), IAV(108), IAV(109), IAV(110), IAV(111), + IAV(112), IAV(113), IAV(114), IAV(115), IAV(116), IAV(117), IAV(118), IAV(119), + IAV(120), IAV(121), IAV(122), IAV(123), IAV(124), IAV(125), IAV(126), IAV(127) }; - + /* field-extraction macros */ @@ -1418,7 +1431,7 @@ ((((unsigned long)(sz)) >> 9) <= 84) ? 110 + (((unsigned long)(sz)) >> 12): \ ((((unsigned long)(sz)) >> 9) <= 340) ? 119 + (((unsigned long)(sz)) >> 15): \ ((((unsigned long)(sz)) >> 9) <= 1364) ? 124 + (((unsigned long)(sz)) >> 18): \ - 126) + 126) /* bins for chunks < 512 are all spaced 8 bytes apart, and hold identically sized chunks. This is exploited in malloc. @@ -1435,8 +1448,8 @@ */ #define is_small_request(nb) (nb < MAX_SMALLBIN_SIZE - SMALLBIN_WIDTH) - + /* To help compensate for the large number of bins, a one-level index @@ -1448,42 +1461,40 @@ when all are noticed to be empty during traversal in malloc. */ -#define BINBLOCKWIDTH 4 /* bins per block */ +#define BINBLOCKWIDTH 4 /* bins per block */ -#define binblocks (bin_at(0)->size) /* bitvector of nonempty blocks */ +#define binblocks (bin_at(0)->size) /* bitvector of nonempty blocks */ /* bin<->block macros */ #define idx2binblock(ix) ((unsigned)1 << (ix / BINBLOCKWIDTH)) #define mark_binblock(ii) (binblocks |= idx2binblock(ii)) #define clear_binblock(ii) (binblocks &= ~(idx2binblock(ii))) - + /* Other static bookkeeping data */ /* variables holding tunable values */ -static unsigned long trim_threshold = DEFAULT_TRIM_THRESHOLD; -static unsigned long top_pad = DEFAULT_TOP_PAD; -static unsigned int n_mmaps_max = DEFAULT_MMAP_MAX; -static unsigned long mmap_threshold = DEFAULT_MMAP_THRESHOLD; +static unsigned long trim_threshold = DEFAULT_TRIM_THRESHOLD; +static unsigned long top_pad = DEFAULT_TOP_PAD; +static unsigned int n_mmaps_max = DEFAULT_MMAP_MAX; +static unsigned long mmap_threshold = DEFAULT_MMAP_THRESHOLD; /* The first value returned from sbrk */ -static char *sbrk_base = (char *) (-1); +static char* sbrk_base = (char*)(-1); /* The maximum memory obtained from system via sbrk */ -static unsigned long max_sbrked_mem = 0; +static unsigned long max_sbrked_mem = 0; /* The maximum via either sbrk or mmap */ -static unsigned long max_total_mem = 0; +static unsigned long max_total_mem = 0; /* internal working copy of mallinfo */ -static struct mallinfo current_mallinfo = -{ -0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static struct mallinfo current_mallinfo = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* The total memory obtained from system via sbrk */ #define sbrked_mem (current_mallinfo.arena) @@ -1494,8 +1505,8 @@ static unsigned int max_n_mmaps = 0; static unsigned long mmapped_mem = 0; static unsigned long max_mmapped_mem = 0; - + /* Debugging support @@ -1513,114 +1524,114 @@ */ #if __STD_C -static void do_check_chunk(mchunkptr p) +static void do_check_chunk(mchunkptr p) #else -static void do_check_chunk(p) - mchunkptr p; +static void do_check_chunk(p) mchunkptr p; #endif -{ - INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; +{ + INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; - /* No checkable chunk is mmapped */ - assert(!chunk_is_mmapped(p)); + /* No checkable chunk is mmapped */ + assert(!chunk_is_mmapped(p)); - /* Check for legal address ... */ - assert((char *) p >= sbrk_base); - if (p != top) - assert((char *) p + sz <= (char *) top); - else - assert((char *) p + sz <= sbrk_base + sbrked_mem); + /* Check for legal address ... */ + assert((char*)p >= sbrk_base); + if (p != top) + assert((char*)p + sz <= (char*)top); + else + assert((char*)p + sz <= sbrk_base + sbrked_mem); } #if __STD_C -static void do_check_free_chunk(mchunkptr p) +static void do_check_free_chunk(mchunkptr p) #else -static void do_check_free_chunk(p) - mchunkptr p; +static void do_check_free_chunk(p) mchunkptr p; #endif -{ - INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; - mchunkptr next = chunk_at_offset(p, sz); +{ + INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; + mchunkptr next = chunk_at_offset(p, sz); - do_check_chunk(p); + do_check_chunk(p); - /* Check whether it claims to be free ... */ - assert(!inuse(p)); + /* Check whether it claims to be free ... */ + assert(!inuse(p)); - /* Unless a special marker, must have OK fields */ - if ((long) sz >= (long) MINSIZE) { - assert((sz & MALLOC_ALIGN_MASK) == 0); - assert(aligned_OK(chunk2mem(p))); - /* ... matching footer field */ - assert(next->prev_size == sz); - /* ... and is fully consolidated */ - assert(prev_inuse(p)); - assert(next == top || inuse(next)); - - /* ... and has minimally sane links */ - assert(p->fd->bk == p); - assert(p->bk->fd == p); - } else /* markers are always of size SIZE_SZ */ - assert(sz == SIZE_SZ); + /* Unless a special marker, must have OK fields */ + if ((long)sz >= (long)MINSIZE) + { + assert((sz & MALLOC_ALIGN_MASK) == 0); + assert(aligned_OK(chunk2mem(p))); + /* ... matching footer field */ + assert(next->prev_size == sz); + /* ... and is fully consolidated */ + assert(prev_inuse(p)); + assert (next == top || inuse(next)); + + /* ... and has minimally sane links */ + assert(p->fd->bk == p); + assert(p->bk->fd == p); + } + else /* markers are always of size SIZE_SZ */ + assert(sz == SIZE_SZ); } #if __STD_C -static void do_check_inuse_chunk(mchunkptr p) +static void do_check_inuse_chunk(mchunkptr p) #else -static void do_check_inuse_chunk(p) - mchunkptr p; +static void do_check_inuse_chunk(p) mchunkptr p; #endif -{ - mchunkptr next = next_chunk(p); - do_check_chunk(p); +{ + mchunkptr next = next_chunk(p); + do_check_chunk(p); - /* Check whether it claims to be in use ... */ - assert(inuse(p)); + /* Check whether it claims to be in use ... */ + assert(inuse(p)); - /* ... and is surrounded by OK chunks. - * Since more things can be checked with free chunks than inuse ones, - * if an inuse chunk borders them and debug is on, it's worth doing them. - */ - if (!prev_inuse(p)) { - mchunkptr prv = prev_chunk(p); - assert(next_chunk(prv) == p); - do_check_free_chunk(prv); - } - if (next == top) { - assert(prev_inuse(next)); - assert(chunksize(next) >= MINSIZE); - } else if (!inuse(next)) - do_check_free_chunk(next); + /* ... and is surrounded by OK chunks. + Since more things can be checked with free chunks than inuse ones, + if an inuse chunk borders them and debug is on, it's worth doing them. + */ + if (!prev_inuse(p)) + { + mchunkptr prv = prev_chunk(p); + assert(next_chunk(prv) == p); + do_check_free_chunk(prv); + } + if (next == top) + { + assert(prev_inuse(next)); + assert(chunksize(next) >= MINSIZE); + } + else if (!inuse(next)) + do_check_free_chunk(next); } #if __STD_C -static void do_check_malloced_chunk(mchunkptr p, INTERNAL_SIZE_T s) +static void do_check_malloced_chunk(mchunkptr p, INTERNAL_SIZE_T s) #else -static void do_check_malloced_chunk(p, s) - mchunkptr p; - INTERNAL_SIZE_T s; +static void do_check_malloced_chunk(p, s) mchunkptr p; INTERNAL_SIZE_T s; #endif { - INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; - long room = sz - s; + INTERNAL_SIZE_T sz = p->size & ~PREV_INUSE; + long room = sz - s; - do_check_inuse_chunk(p); + do_check_inuse_chunk(p); - /* Legal size ... */ - assert((long) sz >= (long) MINSIZE); - assert((sz & MALLOC_ALIGN_MASK) == 0); - assert(room >= 0); - assert(room < (long) MINSIZE); + /* Legal size ... */ + assert((long)sz >= (long)MINSIZE); + assert((sz & MALLOC_ALIGN_MASK) == 0); + assert(room >= 0); + assert(room < (long)MINSIZE); - /* ... and alignment */ - assert(aligned_OK(chunk2mem(p))); + /* ... and alignment */ + assert(aligned_OK(chunk2mem(p))); - /* ... and was allocated at front of an available chunk */ - assert(prev_inuse(p)); + /* ... and was allocated at front of an available chunk */ + assert(prev_inuse(p)); } @@ -1630,13 +1641,13 @@ #define check_chunk(P) do_check_chunk(P) #define check_malloced_chunk(P,N) do_check_malloced_chunk(P,N) #else -#define check_free_chunk(P) +#define check_free_chunk(P) #define check_inuse_chunk(P) #define check_chunk(P) #define check_malloced_chunk(P,N) #endif - + /* Macro-based internal utilities @@ -1706,10 +1717,10 @@ #define clear_last_remainder \ (last_remainder->fd = last_remainder->bk = last_remainder) - + /* Routines dealing with mmap(). */ @@ -1719,84 +1730,79 @@ #if __STD_C static mchunkptr mmap_chunk(size_t size) #else -static mchunkptr mmap_chunk(size) - size_t size; +static mchunkptr mmap_chunk(size) size_t size; #endif { - size_t page_mask = malloc_getpagesize - 1; - mchunkptr p; + size_t page_mask = malloc_getpagesize - 1; + mchunkptr p; #ifndef MAP_ANONYMOUS - static int fd = -1; + static int fd = -1; #endif - if (n_mmaps >= n_mmaps_max) - return 0; /* too many regions */ + if(n_mmaps >= n_mmaps_max) return 0; /* too many regions */ - /* For mmapped chunks, the overhead is one SIZE_SZ unit larger, because - * there is no following chunk whose prev_size field could be used. - */ - size = (size + SIZE_SZ + page_mask) & ~page_mask; + /* For mmapped chunks, the overhead is one SIZE_SZ unit larger, because + * there is no following chunk whose prev_size field could be used. + */ + size = (size + SIZE_SZ + page_mask) & ~page_mask; #ifdef MAP_ANONYMOUS - p = (mchunkptr) mmap(0, size, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + p = (mchunkptr)mmap(0, size, PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); #else /* !MAP_ANONYMOUS */ - if (fd < 0) { - fd = open("/dev/zero", O_RDWR); - if (fd < 0) - return 0; - } - p = (mchunkptr) mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + if (fd < 0) + { + fd = open("/dev/zero", O_RDWR); + if(fd < 0) return 0; + } + p = (mchunkptr)mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); #endif - if (p == (mchunkptr) - 1) - return 0; - - n_mmaps++; - if (n_mmaps > max_n_mmaps) - max_n_mmaps = n_mmaps; + if(p == (mchunkptr)-1) return 0; - /* We demand that eight bytes into a page must be 8-byte aligned. */ - assert(aligned_OK(chunk2mem(p))); + n_mmaps++; + if (n_mmaps > max_n_mmaps) max_n_mmaps = n_mmaps; + + /* We demand that eight bytes into a page must be 8-byte aligned. */ + assert(aligned_OK(chunk2mem(p))); - /* The offset to the start of the mmapped region is stored - * in the prev_size field of the chunk; normally it is zero, - * but that can be changed in memalign(). - */ - p->prev_size = 0; - set_head(p, size | IS_MMAPPED); - - mmapped_mem += size; - if ((unsigned long) mmapped_mem > (unsigned long) max_mmapped_mem) - max_mmapped_mem = mmapped_mem; - if ((unsigned long) (mmapped_mem + sbrked_mem) > - (unsigned long) max_total_mem) max_total_mem = mmapped_mem + sbrked_mem; - return p; + /* The offset to the start of the mmapped region is stored + * in the prev_size field of the chunk; normally it is zero, + * but that can be changed in memalign(). + */ + p->prev_size = 0; + set_head(p, size|IS_MMAPPED); + + mmapped_mem += size; + if ((unsigned long)mmapped_mem > (unsigned long)max_mmapped_mem) + max_mmapped_mem = mmapped_mem; + if ((unsigned long)(mmapped_mem + sbrked_mem) > (unsigned long)max_total_mem) + max_total_mem = mmapped_mem + sbrked_mem; + return p; } #if __STD_C static void munmap_chunk(mchunkptr p) #else -static void munmap_chunk(p) - mchunkptr p; +static void munmap_chunk(p) mchunkptr p; #endif { - INTERNAL_SIZE_T size = chunksize(p); - int ret; + INTERNAL_SIZE_T size = chunksize(p); + int ret; - assert(chunk_is_mmapped(p)); - assert(!((char *) p >= sbrk_base && (char *) p < sbrk_base + sbrked_mem)); - assert((n_mmaps > 0)); - assert(((p->prev_size + size) & (malloc_getpagesize - 1)) == 0); + assert (chunk_is_mmapped(p)); + assert(! ((char*)p >= sbrk_base && (char*)p < sbrk_base + sbrked_mem)); + assert((n_mmaps > 0)); + assert(((p->prev_size + size) & (malloc_getpagesize-1)) == 0); - n_mmaps--; - mmapped_mem -= (size + p->prev_size); + n_mmaps--; + mmapped_mem -= (size + p->prev_size); - ret = munmap((char *) p - p->prev_size, size + p->prev_size); + ret = munmap((char *)p - p->prev_size, size + p->prev_size); - /* munmap returns non-zero on failure */ - assert(ret == 0); + /* munmap returns non-zero on failure */ + assert(ret == 0); } #if HAVE_MREMAP @@ -1804,51 +1810,48 @@ #if __STD_C static mchunkptr mremap_chunk(mchunkptr p, size_t new_size) #else -static mchunkptr mremap_chunk(p, new_size) - mchunkptr p; - size_t new_size; +static mchunkptr mremap_chunk(p, new_size) mchunkptr p; size_t new_size; #endif { - size_t page_mask = malloc_getpagesize - 1; - INTERNAL_SIZE_T offset = p->prev_size; - INTERNAL_SIZE_T size = chunksize(p); - char *cp; + size_t page_mask = malloc_getpagesize - 1; + INTERNAL_SIZE_T offset = p->prev_size; + INTERNAL_SIZE_T size = chunksize(p); + char *cp; - assert(chunk_is_mmapped(p)); - assert(!((char *) p >= sbrk_base && (char *) p < sbrk_base + sbrked_mem)); - assert((n_mmaps > 0)); - assert(((size + offset) & (malloc_getpagesize - 1)) == 0); + assert (chunk_is_mmapped(p)); + assert(! ((char*)p >= sbrk_base && (char*)p < sbrk_base + sbrked_mem)); + assert((n_mmaps > 0)); + assert(((size + offset) & (malloc_getpagesize-1)) == 0); - /* Note the extra SIZE_SZ overhead as in mmap_chunk(). */ - new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask; + /* Note the extra SIZE_SZ overhead as in mmap_chunk(). */ + new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask; - cp = (char *) mremap((char *) p - offset, size + offset, new_size, 1); + cp = (char *)mremap((char *)p - offset, size + offset, new_size, 1); - if (cp == (char *) -1) - return 0; + if (cp == (char *)-1) return 0; - p = (mchunkptr) (cp + offset); + p = (mchunkptr)(cp + offset); - assert(aligned_OK(chunk2mem(p))); + assert(aligned_OK(chunk2mem(p))); - assert((p->prev_size == offset)); - set_head(p, (new_size - offset) | IS_MMAPPED); + assert((p->prev_size == offset)); + set_head(p, (new_size - offset)|IS_MMAPPED); - mmapped_mem -= size + offset; - mmapped_mem += new_size; - if ((unsigned long) mmapped_mem > (unsigned long) max_mmapped_mem) - max_mmapped_mem = mmapped_mem; - if ((unsigned long) (mmapped_mem + sbrked_mem) > - (unsigned long) max_total_mem) max_total_mem = mmapped_mem + sbrked_mem; - return p; + mmapped_mem -= size + offset; + mmapped_mem += new_size; + if ((unsigned long)mmapped_mem > (unsigned long)max_mmapped_mem) + max_mmapped_mem = mmapped_mem; + if ((unsigned long)(mmapped_mem + sbrked_mem) > (unsigned long)max_total_mem) + max_total_mem = mmapped_mem + sbrked_mem; + return p; } #endif /* HAVE_MREMAP */ #endif /* HAVE_MMAP */ - + /* Extend the top-most chunk by obtaining memory from system. @@ -1858,106 +1861,112 @@ #if __STD_C static void malloc_extend_top(INTERNAL_SIZE_T nb) #else -static void malloc_extend_top(nb) - INTERNAL_SIZE_T nb; +static void malloc_extend_top(nb) INTERNAL_SIZE_T nb; #endif { - char *brk; /* return value from sbrk */ - INTERNAL_SIZE_T front_misalign; /* unusable bytes at front of sbrked space */ - INTERNAL_SIZE_T correction; /* bytes for 2nd sbrk call */ - char *new_brk; /* return of 2nd sbrk call */ - INTERNAL_SIZE_T top_size; /* new size of top chunk */ - - mchunkptr old_top = top; /* Record state of old top */ - INTERNAL_SIZE_T old_top_size = chunksize(old_top); - char *old_end = (char *) (chunk_at_offset(old_top, old_top_size)); - - /* Pad request with top_pad plus minimal overhead */ - - INTERNAL_SIZE_T sbrk_size = nb + top_pad + MINSIZE; - unsigned long pagesz = malloc_getpagesize; - - /* If not the first time through, round to preserve page boundary */ - /* Otherwise, we need to correct to a page size below anyway. */ - /* (We also correct below if an intervening foreign sbrk call.) */ - - if (sbrk_base != (char *) (-1)) - sbrk_size = (sbrk_size + (pagesz - 1)) & ~(pagesz - 1); - - brk = (char *) (MORECORE(sbrk_size)); - - /* Fail if sbrk failed or if a foreign sbrk call killed our space */ - if (brk == (char *) (MORECORE_FAILURE) || - (brk < old_end && old_top != initial_top)) return; - - sbrked_mem += sbrk_size; - - if (brk == old_end) { /* can just add bytes to current top */ - top_size = sbrk_size + old_top_size; - set_head(top, top_size | PREV_INUSE); - } else { - if (sbrk_base == (char *) (-1)) /* First time through. Record base */ - sbrk_base = brk; - else /* Someone else called sbrk(). Count those bytes as sbrked_mem. */ - sbrked_mem += brk - (char *) old_end; - - /* Guarantee alignment of first new chunk made from this space */ - front_misalign = (unsigned long) chunk2mem(brk) & MALLOC_ALIGN_MASK; - if (front_misalign > 0) { - correction = (MALLOC_ALIGNMENT) - front_misalign; - brk += correction; - } else - correction = 0; - - /* Guarantee the next brk will be at a page boundary */ - correction += - pagesz - ((unsigned long) (brk + sbrk_size) & (pagesz - 1)); - - /* Allocate correction */ - new_brk = (char *) (MORECORE(correction)); - if (new_brk == (char *) (MORECORE_FAILURE)) - return; - - sbrked_mem += correction; - - top = (mchunkptr) brk; - top_size = new_brk - brk + correction; - set_head(top, top_size | PREV_INUSE); - - if (old_top != initial_top) { - - /* There must have been an intervening foreign sbrk call. */ - /* A double fencepost is necessary to prevent consolidation */ - - /* If not enough space to do this, then user did something very wrong */ - if (old_top_size < MINSIZE) { - set_head(top, PREV_INUSE); /* will force null return from malloc */ - return; - } - - /* Also keep size a multiple of MALLOC_ALIGNMENT */ - old_top_size = (old_top_size - 3 * SIZE_SZ) & ~MALLOC_ALIGN_MASK; - chunk_at_offset(old_top, old_top_size)->size = SIZE_SZ | PREV_INUSE; - chunk_at_offset(old_top, old_top_size + SIZE_SZ)->size = - SIZE_SZ | PREV_INUSE; - set_head_size(old_top, old_top_size); - /* If possible, release the rest. */ - if (old_top_size >= MINSIZE) - fREe(chunk2mem(old_top)); - } + char* brk; /* return value from sbrk */ + INTERNAL_SIZE_T front_misalign; /* unusable bytes at front of sbrked space */ + INTERNAL_SIZE_T correction; /* bytes for 2nd sbrk call */ + char* new_brk; /* return of 2nd sbrk call */ + INTERNAL_SIZE_T top_size; /* new size of top chunk */ + + mchunkptr old_top = top; /* Record state of old top */ + INTERNAL_SIZE_T old_top_size = chunksize(old_top); + char* old_end = (char*)(chunk_at_offset(old_top, old_top_size)); + + /* Pad request with top_pad plus minimal overhead */ + + INTERNAL_SIZE_T sbrk_size = nb + top_pad + MINSIZE; + unsigned long pagesz = malloc_getpagesize; + + /* If not the first time through, round to preserve page boundary */ + /* Otherwise, we need to correct to a page size below anyway. */ + /* (We also correct below if an intervening foreign sbrk call.) */ + + if (sbrk_base != (char*)(-1)) + sbrk_size = (sbrk_size + (pagesz - 1)) & ~(pagesz - 1); + + brk = (char*)(MORECORE (sbrk_size)); + + /* Fail if sbrk failed or if a foreign sbrk call killed our space */ + if (brk == (char*)(MORECORE_FAILURE) || + (brk < old_end && old_top != initial_top)) + return; + + sbrked_mem += sbrk_size; + + if (brk == old_end) /* can just add bytes to current top */ + { + top_size = sbrk_size + old_top_size; + set_head(top, top_size | PREV_INUSE); + } + else + { + if (sbrk_base == (char*)(-1)) /* First time through. Record base */ + sbrk_base = brk; + else /* Someone else called sbrk(). Count those bytes as sbrked_mem. */ + sbrked_mem += brk - (char*)old_end; + + /* Guarantee alignment of first new chunk made from this space */ + front_misalign = (unsigned long)chunk2mem(brk) & MALLOC_ALIGN_MASK; + if (front_misalign > 0) + { + correction = (MALLOC_ALIGNMENT) - front_misalign; + brk += correction; } + else + correction = 0; + + /* Guarantee the next brk will be at a page boundary */ + correction += pagesz - ((unsigned long)(brk + sbrk_size) & (pagesz - 1)); - if ((unsigned long) sbrked_mem > (unsigned long) max_sbrked_mem) - max_sbrked_mem = sbrked_mem; - if ((unsigned long) (mmapped_mem + sbrked_mem) > - (unsigned long) max_total_mem) max_total_mem = mmapped_mem + sbrked_mem; + /* Allocate correction */ + new_brk = (char*)(MORECORE (correction)); + if (new_brk == (char*)(MORECORE_FAILURE)) return; + + sbrked_mem += correction; + + top = (mchunkptr)brk; + top_size = new_brk - brk + correction; + set_head(top, top_size | PREV_INUSE); + + if (old_top != initial_top) + { - /* We always land on a page boundary */ - assert(((unsigned long) ((char *) top + top_size) & (pagesz - 1)) == 0); + /* There must have been an intervening foreign sbrk call. */ + /* A double fencepost is necessary to prevent consolidation */ + + /* If not enough space to do this, then user did something very wrong */ + if (old_top_size < MINSIZE) + { + set_head(top, PREV_INUSE); /* will force null return from malloc */ + return; + } + + /* Also keep size a multiple of MALLOC_ALIGNMENT */ + old_top_size = (old_top_size - 3*SIZE_SZ) & ~MALLOC_ALIGN_MASK; + chunk_at_offset(old_top, old_top_size )->size = + SIZE_SZ|PREV_INUSE; + chunk_at_offset(old_top, old_top_size + SIZE_SZ)->size = + SIZE_SZ|PREV_INUSE; + set_head_size(old_top, old_top_size); + /* If possible, release the rest. */ + if (old_top_size >= MINSIZE) + fREe(chunk2mem(old_top)); + } + } + + if ((unsigned long)sbrked_mem > (unsigned long)max_sbrked_mem) + max_sbrked_mem = sbrked_mem; + if ((unsigned long)(mmapped_mem + sbrked_mem) > (unsigned long)max_total_mem) + max_total_mem = mmapped_mem + sbrked_mem; + + /* We always land on a page boundary */ + assert(((unsigned long)((char*)top + top_size) & (pagesz - 1)) == 0); } - + /* Main public routines */ @@ -2022,215 +2031,239 @@ */ #if __STD_C -Void_t *mALLOc(size_t bytes) +Void_t* mALLOc(size_t bytes) #else -Void_t *mALLOc(bytes) - size_t bytes; +Void_t* mALLOc(bytes) size_t bytes; #endif { - mchunkptr victim; /* inspected/selected chunk */ - INTERNAL_SIZE_T victim_size; /* its size */ - int idx; /* index for bin traversal */ - mbinptr bin; /* associated bin */ - mchunkptr remainder; /* remainder from a split */ - long remainder_size; /* its size */ - int remainder_index; /* its bin index */ - unsigned long block; /* block traverser bit */ - int startidx; /* first bin of a traversed block */ - mchunkptr fwd; /* misc temp for linking */ - mchunkptr bck; /* misc temp for linking */ - mbinptr q; /* misc temp */ + mchunkptr victim; /* inspected/selected chunk */ + INTERNAL_SIZE_T victim_size; /* its size */ + int idx; /* index for bin traversal */ + mbinptr bin; /* associated bin */ + mchunkptr remainder; /* remainder from a split */ + long remainder_size; /* its size */ + int remainder_index; /* its bin index */ + unsigned long block; /* block traverser bit */ + int startidx; /* first bin of a traversed block */ + mchunkptr fwd; /* misc temp for linking */ + mchunkptr bck; /* misc temp for linking */ + mbinptr q; /* misc temp */ - INTERNAL_SIZE_T nb = request2size(bytes); /* padded request size; */ + INTERNAL_SIZE_T nb = request2size(bytes); /* padded request size; */ - /* Check for exact match in a bin */ + /* Check for exact match in a bin */ - if (is_small_request(nb)) { /* Faster version for small requests */ - idx = smallbin_index(nb); + if (is_small_request(nb)) /* Faster version for small requests */ + { + idx = smallbin_index(nb); - /* No traversal or size check necessary for small bins. */ + /* No traversal or size check necessary for small bins. */ - q = bin_at(idx); - victim = last(q); - - /* Also scan the next one, since it would have a remainder < MINSIZE */ - if (victim == q) { - q = next_bin(q); - victim = last(q); - } - if (victim != q) { - victim_size = chunksize(victim); - unlink(victim, bck, fwd); - set_inuse_bit_at_offset(victim, victim_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - idx += 2; /* Set for bin scan below. We've already scanned 2 bins. */ - - } else { - idx = bin_index(nb); - bin = bin_at(idx); - - for (victim = last(bin); victim != bin; victim = victim->bk) { - victim_size = chunksize(victim); - remainder_size = victim_size - nb; - - if (remainder_size >= (long) MINSIZE) { /* too big */ - --idx; /* adjust to rescan below after checking last remainder */ - break; - } - - else if (remainder_size >= 0) { /* exact fit */ - unlink(victim, bck, fwd); - set_inuse_bit_at_offset(victim, victim_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - } - - ++idx; + q = bin_at(idx); + victim = last(q); + /* Also scan the next one, since it would have a remainder < MINSIZE */ + if (victim == q) + { + q = next_bin(q); + victim = last(q); } + if (victim != q) + { + victim_size = chunksize(victim); + unlink(victim, bck, fwd); + set_inuse_bit_at_offset(victim, victim_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } + + idx += 2; /* Set for bin scan below. We've already scanned 2 bins. */ + + } + else + { + idx = bin_index(nb); + bin = bin_at(idx); - /* Try to use the last split-off remainder */ - - if ((victim = last_remainder->fd) != last_remainder) { - victim_size = chunksize(victim); - remainder_size = victim_size - nb; - - if (remainder_size >= (long) MINSIZE) { /* re-split */ - remainder = chunk_at_offset(victim, nb); - set_head(victim, nb | PREV_INUSE); - link_last_remainder(remainder); - set_head(remainder, remainder_size | PREV_INUSE); - set_foot(remainder, remainder_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - clear_last_remainder; - - if (remainder_size >= 0) { /* exhaust */ - set_inuse_bit_at_offset(victim, victim_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - /* Else place in bin */ + for (victim = last(bin); victim != bin; victim = victim->bk) + { + victim_size = chunksize(victim); + remainder_size = victim_size - nb; + + if (remainder_size >= (long)MINSIZE) /* too big */ + { + --idx; /* adjust to rescan below after checking last remainder */ + break; + } + + else if (remainder_size >= 0) /* exact fit */ + { + unlink(victim, bck, fwd); + set_inuse_bit_at_offset(victim, victim_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } + } + + ++idx; + + } + + /* Try to use the last split-off remainder */ + + if ( (victim = last_remainder->fd) != last_remainder) + { + victim_size = chunksize(victim); + remainder_size = victim_size - nb; - frontlink(victim, victim_size, remainder_index, bck, fwd); + if (remainder_size >= (long)MINSIZE) /* re-split */ + { + remainder = chunk_at_offset(victim, nb); + set_head(victim, nb | PREV_INUSE); + link_last_remainder(remainder); + set_head(remainder, remainder_size | PREV_INUSE); + set_foot(remainder, remainder_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); } - /* - * If there are any possibly nonempty big-enough blocks, - * search for best fitting chunk by scanning bins in blockwidth units. - */ - - if ((block = idx2binblock(idx)) <= binblocks) { - - /* Get to the first marked block */ - - if ((block & binblocks) == 0) { - /* force to an even block boundary */ - idx = (idx & ~(BINBLOCKWIDTH - 1)) + BINBLOCKWIDTH; - block <<= 1; - while ((block & binblocks) == 0) { - idx += BINBLOCKWIDTH; - block <<= 1; - } - } + clear_last_remainder; - /* For each possibly nonempty block ... */ - for (;;) { - startidx = idx; /* (track incomplete blocks) */ - q = bin = bin_at(idx); - - /* For each bin in this block ... */ - do { - /* Find and use first big enough chunk ... */ - - for (victim = last(bin); victim != bin; victim = victim->bk) { - victim_size = chunksize(victim); - remainder_size = victim_size - nb; - - if (remainder_size >= (long) MINSIZE) { /* split */ - remainder = chunk_at_offset(victim, nb); - set_head(victim, nb | PREV_INUSE); - unlink(victim, bck, fwd); - link_last_remainder(remainder); - set_head(remainder, remainder_size | PREV_INUSE); - set_foot(remainder, remainder_size); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } - - else if (remainder_size >= 0) { /* take */ - set_inuse_bit_at_offset(victim, victim_size); - unlink(victim, bck, fwd); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); - } + if (remainder_size >= 0) /* exhaust */ + { + set_inuse_bit_at_offset(victim, victim_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } - } + /* Else place in bin */ - bin = next_bin(bin); + frontlink(victim, victim_size, remainder_index, bck, fwd); + } - } while ((++idx & (BINBLOCKWIDTH - 1)) != 0); + /* + If there are any possibly nonempty big-enough blocks, + search for best fitting chunk by scanning bins in blockwidth units. + */ - /* Clear out the block bit. */ - - do { /* Possibly backtrack to try to clear a partial block */ - if ((startidx & (BINBLOCKWIDTH - 1)) == 0) { - binblocks &= ~block; - break; - } - --startidx; - q = prev_bin(q); - } while (first(q) == q); - - /* Get to the next possibly nonempty block */ - - if ((block <<= 1) <= binblocks && (block != 0)) { - while ((block & binblocks) == 0) { - idx += BINBLOCKWIDTH; - block <<= 1; - } - } else - break; - } - } + if ( (block = idx2binblock(idx)) <= binblocks) + { + /* Get to the first marked block */ - /* Try to use top chunk */ + if ( (block & binblocks) == 0) + { + /* force to an even block boundary */ + idx = (idx & ~(BINBLOCKWIDTH - 1)) + BINBLOCKWIDTH; + block <<= 1; + while ((block & binblocks) == 0) + { + idx += BINBLOCKWIDTH; + block <<= 1; + } + } + + /* For each possibly nonempty block ... */ + for (;;) + { + startidx = idx; /* (track incomplete blocks) */ + q = bin = bin_at(idx); - /* Require that there be a remainder, ensuring top always exists */ - if ((remainder_size = chunksize(top) - nb) < (long) MINSIZE) { + /* For each bin in this block ... */ + do + { + /* Find and use first big enough chunk ... */ + + for (victim = last(bin); victim != bin; victim = victim->bk) + { + victim_size = chunksize(victim); + remainder_size = victim_size - nb; + + if (remainder_size >= (long)MINSIZE) /* split */ + { + remainder = chunk_at_offset(victim, nb); + set_head(victim, nb | PREV_INUSE); + unlink(victim, bck, fwd); + link_last_remainder(remainder); + set_head(remainder, remainder_size | PREV_INUSE); + set_foot(remainder, remainder_size); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } + + else if (remainder_size >= 0) /* take */ + { + set_inuse_bit_at_offset(victim, victim_size); + unlink(victim, bck, fwd); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); + } + + } + + bin = next_bin(bin); + + } while ((++idx & (BINBLOCKWIDTH - 1)) != 0); + + /* Clear out the block bit. */ + + do /* Possibly backtrack to try to clear a partial block */ + { + if ((startidx & (BINBLOCKWIDTH - 1)) == 0) + { + binblocks &= ~block; + break; + } + --startidx; + q = prev_bin(q); + } while (first(q) == q); + + /* Get to the next possibly nonempty block */ + + if ( (block <<= 1) <= binblocks && (block != 0) ) + { + while ((block & binblocks) == 0) + { + idx += BINBLOCKWIDTH; + block <<= 1; + } + } + else + break; + } + } + + + /* Try to use top chunk */ + + /* Require that there be a remainder, ensuring top always exists */ + if ( (remainder_size = chunksize(top) - nb) < (long)MINSIZE) + { #if HAVE_MMAP - /* If big and would otherwise need to extend, try to use mmap instead */ - if ((unsigned long) nb >= (unsigned long) mmap_threshold && - (victim = mmap_chunk(nb)) != 0) - return chunk2mem(victim); -#endif - - /* Try to extend */ - malloc_extend_top(nb); - if ((remainder_size = chunksize(top) - nb) < (long) MINSIZE) - return 0; /* propagate failure */ - } - - victim = top; - set_head(victim, nb | PREV_INUSE); - top = chunk_at_offset(victim, nb); - set_head(top, remainder_size | PREV_INUSE); - check_malloced_chunk(victim, nb); - return chunk2mem(victim); + /* If big and would otherwise need to extend, try to use mmap instead */ + if ((unsigned long)nb >= (unsigned long)mmap_threshold && + (victim = mmap_chunk(nb)) != 0) + return chunk2mem(victim); +#endif + + /* Try to extend */ + malloc_extend_top(nb); + if ( (remainder_size = chunksize(top) - nb) < (long)MINSIZE) + return 0; /* propagate failure */ + } + + victim = top; + set_head(victim, nb | PREV_INUSE); + top = chunk_at_offset(victim, nb); + set_head(top, remainder_size | PREV_INUSE); + check_malloced_chunk(victim, nb); + return chunk2mem(victim); } - + /* @@ -2255,93 +2288,99 @@ #if __STD_C -void fREe(Void_t * mem) +void fREe(Void_t* mem) #else -void fREe(mem) - Void_t *mem; +void fREe(mem) Void_t* mem; #endif { - mchunkptr p; /* chunk corresponding to mem */ - INTERNAL_SIZE_T hd; /* its head field */ - INTERNAL_SIZE_T sz; /* its size */ - int idx; /* its bin index */ - mchunkptr next; /* next contiguous chunk */ - INTERNAL_SIZE_T nextsz; /* its size */ - INTERNAL_SIZE_T prevsz; /* size of previous contiguous chunk */ - mchunkptr bck; /* misc temp for linking */ - mchunkptr fwd; /* misc temp for linking */ - int islr; /* track whether merging with last_remainder */ + mchunkptr p; /* chunk corresponding to mem */ + INTERNAL_SIZE_T hd; /* its head field */ + INTERNAL_SIZE_T sz; /* its size */ + int idx; /* its bin index */ + mchunkptr next; /* next contiguous chunk */ + INTERNAL_SIZE_T nextsz; /* its size */ + INTERNAL_SIZE_T prevsz; /* size of previous contiguous chunk */ + mchunkptr bck; /* misc temp for linking */ + mchunkptr fwd; /* misc temp for linking */ + int islr; /* track whether merging with last_remainder */ - if (mem == 0) /* free(0) has no effect */ - return; + if (mem == 0) /* free(0) has no effect */ + return; - p = mem2chunk(mem); - hd = p->size; + p = mem2chunk(mem); + hd = p->size; #if HAVE_MMAP - if (hd & IS_MMAPPED) { /* release mmapped memory. */ - munmap_chunk(p); - return; - } + if (hd & IS_MMAPPED) /* release mmapped memory. */ + { + munmap_chunk(p); + return; + } #endif + + check_inuse_chunk(p); + + sz = hd & ~PREV_INUSE; + next = chunk_at_offset(p, sz); + nextsz = chunksize(next); + + if (next == top) /* merge with top */ + { + sz += nextsz; - check_inuse_chunk(p); - - sz = hd & ~PREV_INUSE; - next = chunk_at_offset(p, sz); - nextsz = chunksize(next); - - if (next == top) { /* merge with top */ - sz += nextsz; - - if (!(hd & PREV_INUSE)) { /* consolidate backward */ - prevsz = p->prev_size; - p = chunk_at_offset(p, -prevsz); - sz += prevsz; - unlink(p, bck, fwd); - } - - set_head(p, sz | PREV_INUSE); - top = p; - if ((unsigned long) (sz) >= (unsigned long) trim_threshold) - malloc_trim(top_pad); - return; - } - - set_head(next, nextsz); /* clear inuse bit */ - - islr = 0; - - if (!(hd & PREV_INUSE)) { /* consolidate backward */ - prevsz = p->prev_size; - p = chunk_at_offset(p, -prevsz); - sz += prevsz; - - if (p->fd == last_remainder) /* keep as last_remainder */ - islr = 1; - else - unlink(p, bck, fwd); + if (!(hd & PREV_INUSE)) /* consolidate backward */ + { + prevsz = p->prev_size; + p = chunk_at_offset(p, -prevsz); + sz += prevsz; + unlink(p, bck, fwd); } - if (!(inuse_bit_at_offset(next, nextsz))) { /* consolidate forward */ - sz += nextsz; - - if (!islr && next->fd == last_remainder) { /* re-insert last_remainder */ - islr = 1; - link_last_remainder(p); - } else - unlink(next, bck, fwd); + set_head(p, sz | PREV_INUSE); + top = p; + if ((unsigned long)(sz) >= (unsigned long)trim_threshold) + malloc_trim(top_pad); + return; + } + + set_head(next, nextsz); /* clear inuse bit */ + + islr = 0; + + if (!(hd & PREV_INUSE)) /* consolidate backward */ + { + prevsz = p->prev_size; + p = chunk_at_offset(p, -prevsz); + sz += prevsz; + + if (p->fd == last_remainder) /* keep as last_remainder */ + islr = 1; + else + unlink(p, bck, fwd); + } + + if (!(inuse_bit_at_offset(next, nextsz))) /* consolidate forward */ + { + sz += nextsz; + + if (!islr && next->fd == last_remainder) /* re-insert last_remainder */ + { + islr = 1; + link_last_remainder(p); } + else + unlink(next, bck, fwd); + } - set_head(p, sz | PREV_INUSE); - set_foot(p, sz); - if (!islr) - frontlink(p, sz, idx, bck, fwd); + set_head(p, sz | PREV_INUSE); + set_foot(p, sz); + if (!islr) + frontlink(p, sz, idx, bck, fwd); } - + /* @@ -2381,196 +2420,203 @@ #if __STD_C -Void_t *rEALLOc(Void_t * oldmem, size_t bytes) +Void_t* rEALLOc(Void_t* oldmem, size_t bytes) #else -Void_t *rEALLOc(oldmem, bytes) - Void_t *oldmem; - size_t bytes; +Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; #endif { - INTERNAL_SIZE_T nb; /* padded request size */ + INTERNAL_SIZE_T nb; /* padded request size */ - mchunkptr oldp; /* chunk corresponding to oldmem */ - INTERNAL_SIZE_T oldsize; /* its size */ + mchunkptr oldp; /* chunk corresponding to oldmem */ + INTERNAL_SIZE_T oldsize; /* its size */ - mchunkptr newp; /* chunk to return */ - INTERNAL_SIZE_T newsize; /* its size */ - Void_t *newmem; /* corresponding user mem */ + mchunkptr newp; /* chunk to return */ + INTERNAL_SIZE_T newsize; /* its size */ + Void_t* newmem; /* corresponding user mem */ - mchunkptr next; /* next contiguous chunk after oldp */ - INTERNAL_SIZE_T nextsize; /* its size */ + mchunkptr next; /* next contiguous chunk after oldp */ + INTERNAL_SIZE_T nextsize; /* its size */ - mchunkptr prev; /* previous contiguous chunk before oldp */ - INTERNAL_SIZE_T prevsize; /* its size */ + mchunkptr prev; /* previous contiguous chunk before oldp */ + INTERNAL_SIZE_T prevsize; /* its size */ - mchunkptr remainder; /* holds split off extra space from newp */ - INTERNAL_SIZE_T remainder_size; /* its size */ + mchunkptr remainder; /* holds split off extra space from newp */ + INTERNAL_SIZE_T remainder_size; /* its size */ - mchunkptr bck; /* misc temp for linking */ - mchunkptr fwd; /* misc temp for linking */ + mchunkptr bck; /* misc temp for linking */ + mchunkptr fwd; /* misc temp for linking */ #ifdef REALLOC_ZERO_BYTES_FREES - if (bytes == 0) { - fREe(oldmem); - return 0; - } + if (bytes == 0) { fREe(oldmem); return 0; } #endif - /* realloc of null is supposed to be same as malloc */ - if (oldmem == 0) - return mALLOc(bytes); + /* realloc of null is supposed to be same as malloc */ + if (oldmem == 0) return mALLOc(bytes); - newp = oldp = mem2chunk(oldmem); - newsize = oldsize = chunksize(oldp); + newp = oldp = mem2chunk(oldmem); + newsize = oldsize = chunksize(oldp); - nb = request2size(bytes); + nb = request2size(bytes); #if HAVE_MMAP - if (chunk_is_mmapped(oldp)) { + if (chunk_is_mmapped(oldp)) + { #if HAVE_MREMAP - newp = mremap_chunk(oldp, nb); - if (newp) - return chunk2mem(newp); -#endif - /* Note the extra SIZE_SZ overhead. */ - if (oldsize - SIZE_SZ >= nb) - return oldmem; /* do nothing */ - /* Must alloc, copy, free. */ - newmem = mALLOc(bytes); - if (newmem == 0) - return 0; /* propagate failure */ - MALLOC_COPY(newmem, oldmem, oldsize - 2 * SIZE_SZ); - munmap_chunk(oldp); - return newmem; - } + newp = mremap_chunk(oldp, nb); + if(newp) return chunk2mem(newp); +#endif + /* Note the extra SIZE_SZ overhead. */ + if(oldsize - SIZE_SZ >= nb) return oldmem; /* do nothing */ + /* Must alloc, copy, free. */ + newmem = mALLOc(bytes); + if (newmem == 0) return 0; /* propagate failure */ + MALLOC_COPY(newmem, oldmem, oldsize - 2*SIZE_SZ); + munmap_chunk(oldp); + return newmem; + } #endif - check_inuse_chunk(oldp); - - if ((long) (oldsize) < (long) (nb)) { - - /* Try expanding forward */ - - next = chunk_at_offset(oldp, oldsize); - if (next == top || !inuse(next)) { - nextsize = chunksize(next); - - /* Forward into top only if a remainder */ - if (next == top) { - if ((long) (nextsize + newsize) >= (long) (nb + MINSIZE)) { - newsize += nextsize; - top = chunk_at_offset(oldp, nb); - set_head(top, (newsize - nb) | PREV_INUSE); - set_head_size(oldp, nb); - return chunk2mem(oldp); - } - } - - /* Forward into next chunk */ - else if (((long) (nextsize + newsize) >= (long) (nb))) { - unlink(next, bck, fwd); - newsize += nextsize; - goto split; - } - } else { - next = 0; - nextsize = 0; - } - - /* Try shifting backwards. */ + check_inuse_chunk(oldp); - if (!prev_inuse(oldp)) { - prev = prev_chunk(oldp); - prevsize = chunksize(prev); - - /* try forward + backward first to save a later consolidation */ - - if (next != 0) { - /* into top */ - if (next == top) { - if ((long) (nextsize + prevsize + newsize) >= - (long) (nb + MINSIZE)) { - unlink(prev, bck, fwd); - newp = prev; - newsize += prevsize + nextsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - top = chunk_at_offset(newp, nb); - set_head(top, (newsize - nb) | PREV_INUSE); - set_head_size(newp, nb); - return newmem; - } - } + if ((long)(oldsize) < (long)(nb)) + { - /* into next chunk */ - else if (((long) (nextsize + prevsize + newsize) >= - (long) (nb))) { - unlink(next, bck, fwd); - unlink(prev, bck, fwd); - newp = prev; - newsize += nextsize + prevsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - goto split; - } - } + /* Try expanding forward */ - /* backward only */ - if (prev != 0 && (long) (prevsize + newsize) >= (long) nb) { - unlink(prev, bck, fwd); - newp = prev; - newsize += prevsize; - newmem = chunk2mem(newp); - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - goto split; - } - } - - /* Must allocate */ + next = chunk_at_offset(oldp, oldsize); + if (next == top || !inuse(next)) + { + nextsize = chunksize(next); - newmem = mALLOc(bytes); + /* Forward into top only if a remainder */ + if (next == top) + { + if ((long)(nextsize + newsize) >= (long)(nb + MINSIZE)) + { + newsize += nextsize; + top = chunk_at_offset(oldp, nb); + set_head(top, (newsize - nb) | PREV_INUSE); + set_head_size(oldp, nb); + return chunk2mem(oldp); + } + } + + /* Forward into next chunk */ + else if (((long)(nextsize + newsize) >= (long)(nb))) + { + unlink(next, bck, fwd); + newsize += nextsize; + goto split; + } + } + else + { + next = 0; + nextsize = 0; + } - if (newmem == 0) /* propagate failure */ - return 0; + /* Try shifting backwards. */ - /* Avoid copy if newp is next chunk after oldp. */ - /* (This can only happen when new chunk is sbrk'ed.) */ + if (!prev_inuse(oldp)) + { + prev = prev_chunk(oldp); + prevsize = chunksize(prev); - if ((newp = mem2chunk(newmem)) == next_chunk(oldp)) { - newsize += chunksize(newp); - newp = oldp; - goto split; - } + /* try forward + backward first to save a later consolidation */ - /* Otherwise copy, free, and exit */ - MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); - fREe(oldmem); - return newmem; - } + if (next != 0) + { + /* into top */ + if (next == top) + { + if ((long)(nextsize + prevsize + newsize) >= (long)(nb + MINSIZE)) + { + unlink(prev, bck, fwd); + newp = prev; + newsize += prevsize + nextsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + top = chunk_at_offset(newp, nb); + set_head(top, (newsize - nb) | PREV_INUSE); + set_head_size(newp, nb); + return newmem; + } + } + + /* into next chunk */ + else if (((long)(nextsize + prevsize + newsize) >= (long)(nb))) + { + unlink(next, bck, fwd); + unlink(prev, bck, fwd); + newp = prev; + newsize += nextsize + prevsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + goto split; + } + } + + /* backward only */ + if (prev != 0 && (long)(prevsize + newsize) >= (long)nb) + { + unlink(prev, bck, fwd); + newp = prev; + newsize += prevsize; + newmem = chunk2mem(newp); + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + goto split; + } + } + + /* Must allocate */ + + newmem = mALLOc (bytes); + if (newmem == 0) /* propagate failure */ + return 0; - split: /* split off extra room in old or expanded chunk */ + /* Avoid copy if newp is next chunk after oldp. */ + /* (This can only happen when new chunk is sbrk'ed.) */ - if (newsize - nb >= MINSIZE) { /* split off remainder */ - remainder = chunk_at_offset(newp, nb); - remainder_size = newsize - nb; - set_head_size(newp, nb); - set_head(remainder, remainder_size | PREV_INUSE); - set_inuse_bit_at_offset(remainder, remainder_size); - fREe(chunk2mem(remainder)); /* let free() deal with it */ - } else { - set_head_size(newp, newsize); - set_inuse_bit_at_offset(newp, newsize); - } + if ( (newp = mem2chunk(newmem)) == next_chunk(oldp)) + { + newsize += chunksize(newp); + newp = oldp; + goto split; + } + + /* Otherwise copy, free, and exit */ + MALLOC_COPY(newmem, oldmem, oldsize - SIZE_SZ); + fREe(oldmem); + return newmem; + } + + + split: /* split off extra room in old or expanded chunk */ + + if (newsize - nb >= MINSIZE) /* split off remainder */ + { + remainder = chunk_at_offset(newp, nb); + remainder_size = newsize - nb; + set_head_size(newp, nb); + set_head(remainder, remainder_size | PREV_INUSE); + set_inuse_bit_at_offset(remainder, remainder_size); + fREe(chunk2mem(remainder)); /* let free() deal with it */ + } + else + { + set_head_size(newp, newsize); + set_inuse_bit_at_offset(newp, newsize); + } - check_inuse_chunk(newp); - return chunk2mem(newp); + check_inuse_chunk(newp); + return chunk2mem(newp); } - + /* @@ -2592,106 +2638,101 @@ #if __STD_C -Void_t *mEMALIGn(size_t alignment, size_t bytes) +Void_t* mEMALIGn(size_t alignment, size_t bytes) #else -Void_t *mEMALIGn(alignment, bytes) - size_t alignment; - size_t bytes; +Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; #endif { - INTERNAL_SIZE_T nb; /* padded request size */ - char *m; /* memory returned by malloc call */ - mchunkptr p; /* corresponding chunk */ - char *brk; /* alignment point within p */ - mchunkptr newp; /* chunk to return */ - INTERNAL_SIZE_T newsize; /* its size */ - INTERNAL_SIZE_T leadsize; /* leading space befor alignment point */ - mchunkptr remainder; /* spare room at end to split off */ - long remainder_size; /* its size */ + INTERNAL_SIZE_T nb; /* padded request size */ + char* m; /* memory returned by malloc call */ + mchunkptr p; /* corresponding chunk */ + char* brk; /* alignment point within p */ + mchunkptr newp; /* chunk to return */ + INTERNAL_SIZE_T newsize; /* its size */ + INTERNAL_SIZE_T leadsize; /* leading space befor alignment point */ + mchunkptr remainder; /* spare room at end to split off */ + long remainder_size; /* its size */ - /* If need less alignment than we give anyway, just relay to malloc */ + /* If need less alignment than we give anyway, just relay to malloc */ - if (alignment <= MALLOC_ALIGNMENT) - return mALLOc(bytes); + if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes); - /* Otherwise, ensure that it is at least a minimum chunk size */ - - if (alignment < MINSIZE) - alignment = MINSIZE; + /* Otherwise, ensure that it is at least a minimum chunk size */ + + if (alignment < MINSIZE) alignment = MINSIZE; - /* Call malloc with worst case padding to hit alignment. */ + /* Call malloc with worst case padding to hit alignment. */ - nb = request2size(bytes); - m = (char *) (mALLOc(nb + alignment + MINSIZE)); + nb = request2size(bytes); + m = (char*)(mALLOc(nb + alignment + MINSIZE)); - if (m == 0) - return 0; /* propagate failure */ + if (m == 0) return 0; /* propagate failure */ - p = mem2chunk(m); + p = mem2chunk(m); - if ((((unsigned long) (m)) % alignment) == 0) { /* aligned */ + if ((((unsigned long)(m)) % alignment) == 0) /* aligned */ + { #if HAVE_MMAP - if (chunk_is_mmapped(p)) - return chunk2mem(p); /* nothing more to do */ + if(chunk_is_mmapped(p)) + return chunk2mem(p); /* nothing more to do */ #endif - } else { /* misaligned */ - - /* - * Find an aligned spot inside chunk. - * Since we need to give back leading space in a chunk of at - * least MINSIZE, if the first calculation places us at - * a spot with less than MINSIZE leader, we can move to the - * next aligned spot -- we've allocated enough total room so that - * this is always possible. - */ - - brk = - (char *) mem2chunk(((unsigned long) (m + alignment - - 1)) & -alignment); - if ((long) (brk - (char *) (p)) < MINSIZE) - brk = brk + alignment; - - newp = (mchunkptr) brk; - leadsize = brk - (char *) (p); - newsize = chunksize(p) - leadsize; + } + else /* misaligned */ + { + /* + Find an aligned spot inside chunk. + Since we need to give back leading space in a chunk of at + least MINSIZE, if the first calculation places us at + a spot with less than MINSIZE leader, we can move to the + next aligned spot -- we've allocated enough total room so that + this is always possible. + */ + + brk = (char*)mem2chunk(((unsigned long)(m + alignment - 1)) & -alignment); + if ((long)(brk - (char*)(p)) < MINSIZE) brk = brk + alignment; + + newp = (mchunkptr)brk; + leadsize = brk - (char*)(p); + newsize = chunksize(p) - leadsize; #if HAVE_MMAP - if (chunk_is_mmapped(p)) { - newp->prev_size = p->prev_size + leadsize; - set_head(newp, newsize | IS_MMAPPED); - return chunk2mem(newp); - } + if(chunk_is_mmapped(p)) + { + newp->prev_size = p->prev_size + leadsize; + set_head(newp, newsize|IS_MMAPPED); + return chunk2mem(newp); + } #endif - /* give back leader, use the rest */ + /* give back leader, use the rest */ - set_head(newp, newsize | PREV_INUSE); - set_inuse_bit_at_offset(newp, newsize); - set_head_size(p, leadsize); - fREe(chunk2mem(p)); - p = newp; + set_head(newp, newsize | PREV_INUSE); + set_inuse_bit_at_offset(newp, newsize); + set_head_size(p, leadsize); + fREe(chunk2mem(p)); + p = newp; - assert(newsize >= nb - && (((unsigned long) (chunk2mem(p))) % alignment) == 0); - } + assert (newsize >= nb && (((unsigned long)(chunk2mem(p))) % alignment) == 0); + } - /* Also give back spare room at the end */ + /* Also give back spare room at the end */ - remainder_size = chunksize(p) - nb; + remainder_size = chunksize(p) - nb; - if (remainder_size >= (long) MINSIZE) { - remainder = chunk_at_offset(p, nb); - set_head(remainder, remainder_size | PREV_INUSE); - set_head_size(p, nb); - fREe(chunk2mem(remainder)); - } + if (remainder_size >= (long)MINSIZE) + { + remainder = chunk_at_offset(p, nb); + set_head(remainder, remainder_size | PREV_INUSE); + set_head_size(p, nb); + fREe(chunk2mem(remainder)); + } - check_inuse_chunk(p); - return chunk2mem(p); + check_inuse_chunk(p); + return chunk2mem(p); } - + /* @@ -2701,13 +2742,12 @@ */ #if __STD_C -Void_t *vALLOc(size_t bytes) +Void_t* vALLOc(size_t bytes) #else -Void_t *vALLOc(bytes) - size_t bytes; +Void_t* vALLOc(bytes) size_t bytes; #endif { - return mEMALIGn(malloc_getpagesize, bytes); + return mEMALIGn (malloc_getpagesize, bytes); } /* @@ -2717,14 +2757,13 @@ #if __STD_C -Void_t *pvALLOc(size_t bytes) +Void_t* pvALLOc(size_t bytes) #else -Void_t *pvALLOc(bytes) - size_t bytes; +Void_t* pvALLOc(bytes) size_t bytes; #endif { - size_t pagesize = malloc_getpagesize; - return mEMALIGn(pagesize, (bytes + pagesize - 1) & ~(pagesize - 1)); + size_t pagesize = malloc_getpagesize; + return mEMALIGn (pagesize, (bytes + pagesize - 1) & ~(pagesize - 1)); } /* @@ -2734,50 +2773,49 @@ */ #if __STD_C -Void_t *cALLOc(size_t n, size_t elem_size) +Void_t* cALLOc(size_t n, size_t elem_size) #else -Void_t *cALLOc(n, elem_size) - size_t n; - size_t elem_size; +Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size; #endif { - mchunkptr p; - INTERNAL_SIZE_T csz; + mchunkptr p; + INTERNAL_SIZE_T csz; - INTERNAL_SIZE_T sz = n * elem_size; + INTERNAL_SIZE_T sz = n * elem_size; - /* check if expand_top called, in which case don't need to clear */ + /* check if expand_top called, in which case don't need to clear */ #if MORECORE_CLEARS - mchunkptr oldtop = top; - INTERNAL_SIZE_T oldtopsize = chunksize(top); + mchunkptr oldtop = top; + INTERNAL_SIZE_T oldtopsize = chunksize(top); #endif - Void_t *mem = mALLOc(sz); + Void_t* mem = mALLOc (sz); - if (mem == 0) - return 0; - else { - p = mem2chunk(mem); + if (mem == 0) + return 0; + else + { + p = mem2chunk(mem); - /* Two optional cases in which clearing not necessary */ + /* Two optional cases in which clearing not necessary */ #if HAVE_MMAP - if (chunk_is_mmapped(p)) - return mem; + if (chunk_is_mmapped(p)) return mem; #endif - csz = chunksize(p); + csz = chunksize(p); #if MORECORE_CLEARS - if (p == oldtop && csz > oldtopsize) { - /* clear only the bytes from non-freshly-sbrked memory */ - csz = oldtopsize; - } + if (p == oldtop && csz > oldtopsize) + { + /* clear only the bytes from non-freshly-sbrked memory */ + csz = oldtopsize; + } #endif - MALLOC_ZERO(mem, csz - SIZE_SZ); - return mem; - } + MALLOC_ZERO(mem, csz - SIZE_SZ); + return mem; + } } /* @@ -2789,17 +2827,16 @@ #if !defined(INTERNAL_LINUX_C_LIB) || !defined(__ELF__) #if __STD_C -void cfree(Void_t * mem) +void cfree(Void_t *mem) #else -void cfree(mem) - Void_t *mem; +void cfree(mem) Void_t *mem; #endif { - free(mem); + free(mem); } #endif - + /* @@ -2827,56 +2864,60 @@ #if __STD_C int malloc_trim(size_t pad) #else -int malloc_trim(pad) - size_t pad; +int malloc_trim(pad) size_t pad; #endif { - long top_size; /* Amount of top-most memory */ - long extra; /* Amount to release */ - char *current_brk; /* address returned by pre-check sbrk call */ - char *new_brk; /* address returned by negative sbrk call */ - - unsigned long pagesz = malloc_getpagesize; - - top_size = chunksize(top); - extra = ((top_size - pad - MINSIZE + (pagesz - 1)) / pagesz - 1) * pagesz; - - if (extra < (long) pagesz) /* Not enough memory to release */ - return 0; - - else { - /* Test to make sure no one else called sbrk */ - current_brk = (char *) (MORECORE(0)); - if (current_brk != (char *) (top) + top_size) - return 0; /* Apparently we don't own memory; must fail */ - - else { - new_brk = (char *) (MORECORE(-extra)); - - if (new_brk == (char *) (MORECORE_FAILURE)) { /* sbrk failed? */ - /* Try to figure out what we have */ - current_brk = (char *) (MORECORE(0)); - top_size = current_brk - (char *) top; - if (top_size >= (long) MINSIZE) { /* if not, we are very very dead! */ - sbrked_mem = current_brk - sbrk_base; - set_head(top, top_size | PREV_INUSE); - } - check_chunk(top); - return 0; - } - - else { - /* Success. Adjust top accordingly. */ - set_head(top, (top_size - extra) | PREV_INUSE); - sbrked_mem -= extra; - check_chunk(top); - return 1; - } - } + long top_size; /* Amount of top-most memory */ + long extra; /* Amount to release */ + char* current_brk; /* address returned by pre-check sbrk call */ + char* new_brk; /* address returned by negative sbrk call */ + + unsigned long pagesz = malloc_getpagesize; + + top_size = chunksize(top); + extra = ((top_size - pad - MINSIZE + (pagesz-1)) / pagesz - 1) * pagesz; + + if (extra < (long)pagesz) /* Not enough memory to release */ + return 0; + + else + { + /* Test to make sure no one else called sbrk */ + current_brk = (char*)(MORECORE (0)); + if (current_brk != (char*)(top) + top_size) + return 0; /* Apparently we don't own memory; must fail */ + + else + { + new_brk = (char*)(MORECORE (-extra)); + + if (new_brk == (char*)(MORECORE_FAILURE)) /* sbrk failed? */ + { + /* Try to figure out what we have */ + current_brk = (char*)(MORECORE (0)); + top_size = current_brk - (char*)top; + if (top_size >= (long)MINSIZE) /* if not, we are very very dead! */ + { + sbrked_mem = current_brk - sbrk_base; + set_head(top, top_size | PREV_INUSE); + } + check_chunk(top); + return 0; + } + + else + { + /* Success. Adjust top accordingly. */ + set_head(top, (top_size - extra) | PREV_INUSE); + sbrked_mem -= extra; + check_chunk(top); + return 1; + } } + } } - + /* malloc_usable_size: @@ -2890,69 +2931,71 @@ */ #if __STD_C -size_t malloc_usable_size(Void_t * mem) +size_t malloc_usable_size(Void_t* mem) #else -size_t malloc_usable_size(mem) - Void_t *mem; +size_t malloc_usable_size(mem) Void_t* mem; #endif { - mchunkptr p; - if (mem == 0) - return 0; - else { - p = mem2chunk(mem); - if (!chunk_is_mmapped(p)) { - if (!inuse(p)) - return 0; - check_inuse_chunk(p); - return chunksize(p) - SIZE_SZ; - } - return chunksize(p) - 2 * SIZE_SZ; + mchunkptr p; + if (mem == 0) + return 0; + else + { + p = mem2chunk(mem); + if(!chunk_is_mmapped(p)) + { + if (!inuse(p)) return 0; + check_inuse_chunk(p); + return chunksize(p) - SIZE_SZ; } + return chunksize(p) - 2*SIZE_SZ; + } } - + /* Utility to update current_mallinfo for malloc_stats and mallinfo() */ -static void malloc_update_mallinfo() +static void malloc_update_mallinfo() { - int i; - mbinptr b; - mchunkptr p; + int i; + mbinptr b; + mchunkptr p; #if DEBUG - mchunkptr q; + mchunkptr q; #endif - INTERNAL_SIZE_T avail = chunksize(top); - int navail = ((long) (avail) >= (long) MINSIZE) ? 1 : 0; + INTERNAL_SIZE_T avail = chunksize(top); + int navail = ((long)(avail) >= (long)MINSIZE)? 1 : 0; - for (i = 1; i < NAV; ++i) { - b = bin_at(i); - for (p = last(b); p != b; p = p->bk) { + for (i = 1; i < NAV; ++i) + { + b = bin_at(i); + for (p = last(b); p != b; p = p->bk) + { #if DEBUG - check_free_chunk(p); - for (q = next_chunk(p); - q < top && inuse(q) && (long) (chunksize(q)) >= (long) MINSIZE; - q = next_chunk(q)) - check_inuse_chunk(q); -#endif - avail += chunksize(p); - navail++; - } - } - - current_mallinfo.ordblks = navail; - current_mallinfo.uordblks = sbrked_mem - avail; - current_mallinfo.fordblks = avail; - current_mallinfo.hblks = n_mmaps; - current_mallinfo.hblkhd = mmapped_mem; - current_mallinfo.keepcost = chunksize(top); + check_free_chunk(p); + for (q = next_chunk(p); + q < top && inuse(q) && (long)(chunksize(q)) >= (long)MINSIZE; + q = next_chunk(q)) + check_inuse_chunk(q); +#endif + avail += chunksize(p); + navail++; + } + } + + current_mallinfo.ordblks = navail; + current_mallinfo.uordblks = sbrked_mem - avail; + current_mallinfo.fordblks = avail; + current_mallinfo.hblks = n_mmaps; + current_mallinfo.hblkhd = mmapped_mem; + current_mallinfo.keepcost = chunksize(top); } - + /* @@ -2971,15 +3014,16 @@ void malloc_stats() { - malloc_update_mallinfo(); - fprintf(stderr, "max system bytes = %10u\n", - (unsigned int) (max_total_mem)); - fprintf(stderr, "system bytes = %10u\n", - (unsigned int) (sbrked_mem + mmapped_mem)); - fprintf(stderr, "in use bytes = %10u\n", - (unsigned int) (current_mallinfo.uordblks + mmapped_mem)); + malloc_update_mallinfo(); + fprintf(stderr, "max system bytes = %10u\n", + (unsigned int)(max_total_mem)); + fprintf(stderr, "system bytes = %10u\n", + (unsigned int)(sbrked_mem + mmapped_mem)); + fprintf(stderr, "in use bytes = %10u\n", + (unsigned int)(current_mallinfo.uordblks + mmapped_mem)); #if HAVE_MMAP - fprintf(stderr, "max mmap regions = %10u\n", (unsigned int) max_n_mmaps); + fprintf(stderr, "max mmap regions = %10u\n", + (unsigned int)max_n_mmaps); #endif } @@ -2989,12 +3033,12 @@ struct mallinfo mALLINFo() { - malloc_update_mallinfo(); - return current_mallinfo; + malloc_update_mallinfo(); + return current_mallinfo; } - + /* mallopt: @@ -3012,36 +3056,27 @@ #if __STD_C int mALLOPt(int param_number, int value) #else -int mALLOPt(param_number, value) - int param_number; - int value; +int mALLOPt(param_number, value) int param_number; int value; #endif { - switch (param_number) { + switch(param_number) + { case M_TRIM_THRESHOLD: - trim_threshold = value; - return 1; + trim_threshold = value; return 1; case M_TOP_PAD: - top_pad = value; - return 1; + top_pad = value; return 1; case M_MMAP_THRESHOLD: - mmap_threshold = value; - return 1; + mmap_threshold = value; return 1; case M_MMAP_MAX: #if HAVE_MMAP - n_mmaps_max = value; - return 1; + n_mmaps_max = value; return 1; #else - if (value != 0) - return 0; - else - n_mmaps_max = value; - return 1; + if (value != 0) return 0; else n_mmaps_max = value; return 1; #endif default: - return 0; - } + return 0; + } } /* @@ -3131,3 +3166,5 @@ structure of old version, but most details differ.) */ + + Index: squid/lib/drand48.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/drand48.c,v retrieving revision 1.1.1.2.122.1 retrieving revision 1.1.1.2.122.2 diff -u -r1.1.1.2.122.1 -r1.1.1.2.122.2 --- squid/lib/drand48.c 27 Aug 2001 21:48:18 -0000 1.1.1.2.122.1 +++ squid/lib/drand48.c 9 Sep 2001 11:55:05 -0000 1.1.1.2.122.2 @@ -1,3 +1,5 @@ + + /* borrowed from libc/misc/drand48.c in Linux libc-5.4.46 this quick * hack by Martin Hamilton to make Squid build on * Win32 with GNU-Win32 - sorry, folks! */ @@ -21,11 +23,9 @@ #define C 0xB static void next(void); -static unsigned x[3] = { X0, X1, X2 }, a[3] = - -{ -A0, A1, A2} -, c = C; +static unsigned x[3] = +{X0, X1, X2}, a[3] = +{A0, A1, A2}, c = C; double drand48(void); Index: squid/lib/encrypt.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/Attic/encrypt.c,v retrieving revision 1.1.2.1.2.1 retrieving revision 1.1.2.1.2.2 diff -u -r1.1.2.1.2.1 -r1.1.2.1.2.2 --- squid/lib/encrypt.c 27 Aug 2001 21:48:18 -0000 1.1.2.1.2.1 +++ squid/lib/encrypt.c 9 Sep 2001 11:55:05 -0000 1.1.2.1.2.2 @@ -1,5 +1,6 @@ /* encrypt.c - providing 56 bit DES encryption Copyright (C) 1991 Jochen Obalek + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) @@ -28,266 +29,295 @@ static char schluessel[16][KS]; -static char PC1[] = { - 56, 48, 40, 32, 24, 16, 8, 0, - 57, 49, 41, 33, 25, 17, 9, 1, - 58, 50, 42, 34, 26, 18, 10, 2, - 59, 51, 43, 35, - 62, 54, 46, 38, 30, 22, 14, 6, - 61, 53, 45, 37, 29, 21, 13, 5, - 60, 52, 44, 36, 28, 20, 12, 4, - 27, 19, 11, 3 +static char PC1[] = +{ + 56, 48, 40, 32, 24, 16, 8, 0, + 57, 49, 41, 33, 25, 17, 9, 1, + 58, 50, 42, 34, 26, 18, 10, 2, + 59, 51, 43, 35, + 62, 54, 46, 38, 30, 22, 14, 6, + 61, 53, 45, 37, 29, 21, 13, 5, + 60, 52, 44, 36, 28, 20, 12, 4, + 27, 19, 11, 3 }; -static char PC2[] = { - 13, 16, 10, 23, 0, 4, 2, 27, - 14, 5, 20, 9, 22, 18, 11, 3, - 25, 7, 15, 6, 26, 19, 12, 1, - 40, 51, 30, 36, 46, 54, 29, 39, - 50, 44, 32, 47, 43, 48, 38, 55, - 33, 52, 45, 41, 49, 35, 28, 31 +static char PC2[] = +{ + 13, 16, 10, 23, 0, 4, 2, 27, + 14, 5, 20, 9, 22, 18, 11, 3, + 25, 7, 15, 6, 26, 19, 12, 1, + 40, 51, 30, 36, 46, 54, 29, 39, + 50, 44, 32, 47, 43, 48, 38, 55, + 33, 52, 45, 41, 49, 35, 28, 31 }; -static char IP[] = { - 57, 49, 41, 33, 25, 17, 9, 1, - 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, - 63, 55, 47, 39, 31, 23, 15, 7, - 56, 48, 40, 32, 24, 16, 8, 0, - 58, 50, 42, 34, 26, 18, 10, 2, - 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6 +static char IP[] = +{ + 57, 49, 41, 33, 25, 17, 9, 1, + 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, + 63, 55, 47, 39, 31, 23, 15, 7, + 56, 48, 40, 32, 24, 16, 8, 0, + 58, 50, 42, 34, 26, 18, 10, 2, + 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6 }; -static char EP[] = { - 7, 39, 15, 47, 23, 55, 31, 63, - 6, 38, 14, 46, 22, 54, 30, 62, - 5, 37, 13, 45, 21, 53, 29, 61, - 4, 36, 12, 44, 20, 52, 28, 60, - 3, 35, 11, 43, 19, 51, 27, 59, - 2, 34, 10, 42, 18, 50, 26, 58, - 1, 33, 9, 41, 17, 49, 25, 57, - 0, 32, 8, 40, 16, 48, 24, 56 +static char EP[] = +{ + 7, 39, 15, 47, 23, 55, 31, 63, + 6, 38, 14, 46, 22, 54, 30, 62, + 5, 37, 13, 45, 21, 53, 29, 61, + 4, 36, 12, 44, 20, 52, 28, 60, + 3, 35, 11, 43, 19, 51, 27, 59, + 2, 34, 10, 42, 18, 50, 26, 58, + 1, 33, 9, 41, 17, 49, 25, 57, + 0, 32, 8, 40, 16, 48, 24, 56 }; -static char E0[] = { - 31, 0, 1, 2, 3, 4, 3, 4, - 5, 6, 7, 8, 7, 8, 9, 10, - 11, 12, 11, 12, 13, 14, 15, 16, - 15, 16, 17, 18, 19, 20, 19, 20, - 21, 22, 23, 24, 23, 24, 25, 26, - 27, 28, 27, 28, 29, 30, 31, 0 +static char E0[] = +{ + 31, 0, 1, 2, 3, 4, 3, 4, + 5, 6, 7, 8, 7, 8, 9, 10, + 11, 12, 11, 12, 13, 14, 15, 16, + 15, 16, 17, 18, 19, 20, 19, 20, + 21, 22, 23, 24, 23, 24, 25, 26, + 27, 28, 27, 28, 29, 30, 31, 0 }; static char E[KS]; -static char PERM[] = { - 15, 6, 19, 20, 28, 11, 27, 16, - 0, 14, 22, 25, 4, 17, 30, 9, - 1, 7, 23, 13, 31, 26, 2, 8, - 18, 12, 29, 5, 21, 10, 3, 24 +static char PERM[] = +{ + 15, 6, 19, 20, 28, 11, 27, 16, + 0, 14, 22, 25, 4, 17, 30, 9, + 1, 7, 23, 13, 31, 26, 2, 8, + 18, 12, 29, 5, 21, 10, 3, 24 }; -static char S_BOX[][64] = { - { - 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, - 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, - 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, - 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13}, - { - 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, - 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, - 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, - 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9}, - { - 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, - 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, - 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, - 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12}, - { - 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, - 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, - 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, - 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14}, - { - 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, - 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, - 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, - 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3}, - { - 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, - 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, - 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, - 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13}, - { - 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, - 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, - 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, - 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12}, - { - 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, - 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, - 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, - 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11} +static char S_BOX[][64] = +{ + { + 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, + 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, + 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, + 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13 + }, + { + 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, + 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, + 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, + 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9 + }, + { + 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, + 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, + 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, + 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12 + }, + { + 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, + 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, + 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, + 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14 + }, + { + 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, + 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, + 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, + 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3 + }, + { + 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, + 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, + 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, + 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13 + }, + { + 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, + 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, + 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, + 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12 + }, + { + 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, + 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, + 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, + 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11 + } }; -static void -perm(a, e, pc, n) +static void +perm (a, e, pc, n) register char *a, *e; register char *pc; int n; { - for (; n--; pc++, a++) - *a = e[*pc]; + for (; n--; pc++, a++) + *a = e[*pc]; } -static void -crypt_main(nachr_l, nachr_r, schl) +static void +crypt_main (nachr_l, nachr_r, schl) register char *nachr_l, *nachr_r; register char *schl; { - char tmp[KS]; - register int sbval; - register char *tp = tmp; - register char *e = E; - register int i, j; - - for (i = 0; i < 8; i++) { - for (j = 0, sbval = 0; j < 6; j++) - sbval = (sbval << 1) | (nachr_r[*e++] ^ *schl++); - sbval = S_BOX[i][sbval]; - for (tp += 4, j = 4; j--; sbval >>= 1) - *--tp = sbval & 1; - tp += 4; + char tmp[KS]; + register int sbval; + register char *tp = tmp; + register char *e = E; + register int i, j; + + for (i = 0; i < 8; i++) + { + for (j = 0, sbval = 0; j < 6; j++) + sbval = (sbval << 1) | (nachr_r[*e++] ^ *schl++); + sbval = S_BOX[i][sbval]; + for (tp += 4, j = 4; j--; sbval >>= 1) + *--tp = sbval & 1; + tp += 4; } - e = PERM; - for (i = 0; i < BS2; i++) - *nachr_l++ ^= tmp[*e++]; + e = PERM; + for (i = 0; i < BS2; i++) + *nachr_l++ ^= tmp[*e++]; } -void -encrypt(char *nachr, int decr) +void +encrypt (char *nachr, int decr) { - char (*schl)[KS] = decr ? schluessel + 15 : schluessel; - char tmp[BS]; - int i; - - perm(tmp, nachr, IP, BS); - - for (i = 8; i--;) { - crypt_main(tmp, tmp + BS2, *schl); - if (decr) - schl--; - else - schl++; - crypt_main(tmp + BS2, tmp, *schl); - if (decr) - schl--; - else - schl++; + char (*schl)[KS] = decr ? schluessel + 15 : schluessel; + char tmp[BS]; + int i; + + perm (tmp, nachr, IP, BS); + + for (i = 8; i--;) + { + crypt_main (tmp, tmp + BS2, *schl); + if (decr) + schl--; + else + schl++; + crypt_main (tmp + BS2, tmp, *schl); + if (decr) + schl--; + else + schl++; } - perm(nachr, tmp, EP, BS); + perm (nachr, tmp, EP, BS); } -void -setkey(char *schl) +void +setkey (char *schl) { - char tmp1[IS]; - register unsigned int ls = 0x7efc; - register int i, j, k; - register int shval = 0; - register char *akt_schl; - - memcpy(E, E0, KS); - perm(tmp1, schl, PC1, IS); - - for (i = 0; i < 16; i++) { - shval += 1 + (ls & 1); - akt_schl = schluessel[i]; - for (j = 0; j < KS; j++) { - if ((k = PC2[j]) >= IS2) { - if ((k += shval) >= IS) - k = (k - IS2) % IS2 + IS2; - } else if ((k += shval) >= IS2) - k %= IS2; - *akt_schl++ = tmp1[k]; + char tmp1[IS]; + register unsigned int ls = 0x7efc; + register int i, j, k; + register int shval = 0; + register char *akt_schl; + + memcpy (E, E0, KS); + perm (tmp1, schl, PC1, IS); + + for (i = 0; i < 16; i++) + { + shval += 1 + (ls & 1); + akt_schl = schluessel[i]; + for (j = 0; j < KS; j++) + { + if ((k = PC2[j]) >= IS2) + { + if ((k += shval) >= IS) + k = (k - IS2) % IS2 + IS2; + } + else if ((k += shval) >= IS2) + k %= IS2; + *akt_schl++ = tmp1[k]; } - ls >>= 1; + ls >>= 1; } } char * -crypt(const char *wort, const char *salt) +crypt (const char *wort, const char *salt) { - static char retkey[14]; - char key[BS + 2]; - char *k; - int tmp, keybyte; - int i, j; - - memset(key, 0, BS + 2); - - for (k = key, i = 0; i < BS; i++) { - if (!(keybyte = *wort++)) - break; - k += 7; - for (j = 0; j < 7; j++, i++) { - *--k = keybyte & 1; - keybyte >>= 1; + static char retkey[14]; + char key[BS + 2]; + char *k; + int tmp, keybyte; + int i, j; + + memset (key, 0, BS + 2); + + for (k = key, i = 0; i < BS; i++) + { + if (!(keybyte = *wort++)) + break; + k += 7; + for (j = 0; j < 7; j++, i++) + { + *--k = keybyte & 1; + keybyte >>= 1; } - k += 8; + k += 8; } - setkey(key); - memset(key, 0, BS + 2); + setkey (key); + memset (key, 0, BS + 2); - for (k = E, i = 0; i < 2; i++) { - retkey[i] = keybyte = *salt++; - if (keybyte > 'Z') - keybyte -= 'a' - 'Z' - 1; - if (keybyte > '9') - keybyte -= 'A' - '9' - 1; - keybyte -= '.'; - - for (j = 0; j < 6; j++, keybyte >>= 1, k++) { - if (!(keybyte & 1)) - continue; - tmp = *k; - *k = k[24]; - k[24] = tmp; + for (k = E, i = 0; i < 2; i++) + { + retkey[i] = keybyte = *salt++; + if (keybyte > 'Z') + keybyte -= 'a' - 'Z' - 1; + if (keybyte > '9') + keybyte -= 'A' - '9' - 1; + keybyte -= '.'; + + for (j = 0; j < 6; j++, keybyte >>= 1, k++) + { + if (!(keybyte & 1)) + continue; + tmp = *k; + *k = k[24]; + k[24] = tmp; } } - for (i = 0; i < 25; i++) - encrypt(key, 0); + for (i = 0; i < 25; i++) + encrypt (key, 0); - for (k = key, i = 0; i < 11; i++) { - for (j = keybyte = 0; j < 6; j++) { - keybyte <<= 1; - keybyte |= *k++; + for (k = key, i = 0; i < 11; i++) + { + for (j = keybyte = 0; j < 6; j++) + { + keybyte <<= 1; + keybyte |= *k++; } - keybyte += '.'; - if (keybyte > '9') - keybyte += 'A' - '9' - 1; - if (keybyte > 'Z') - keybyte += 'a' - 'Z' - 1; - retkey[i + 2] = keybyte; + keybyte += '.'; + if (keybyte > '9') + keybyte += 'A' - '9' - 1; + if (keybyte > 'Z') + keybyte += 'a' - 'Z' - 1; + retkey[i + 2] = keybyte; } - retkey[i + 2] = 0; + retkey[i + 2] = 0; - if (!retkey[1]) - retkey[1] = *retkey; + if (!retkey[1]) + retkey[1] = *retkey; - return retkey; + return retkey; } + + Index: squid/lib/hash.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/hash.c,v retrieving revision 1.1.1.3.4.1.2.1.2.1 retrieving revision 1.1.1.3.4.1.2.1.2.2 diff -u -r1.1.1.3.4.1.2.1.2.1 -r1.1.1.3.4.1.2.1.2.2 --- squid/lib/hash.c 27 Aug 2001 21:48:18 -0000 1.1.1.3.4.1.2.1.2.1 +++ squid/lib/hash.c 9 Sep 2001 11:55:05 -0000 1.1.1.3.4.1.2.1.2.2 @@ -1,5 +1,6 @@ + /* - * $Id: hash.c,v 1.1.1.3.4.1.2.1.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: hash.c,v 1.1.1.3.4.1.2.1.2.2 2001/09/09 11:55:05 serassio Exp $ * * DEBUG: section 0 Hash Tables * AUTHOR: Harvest Derived @@ -312,7 +313,8 @@ xfree(hid); } -static int hash_primes[] = { +static int hash_primes[] = +{ 103, 229, 467, @@ -373,7 +375,8 @@ while (fgets(buf, BUFSIZ, stdin)) { buf[strlen(buf) - 1] = '\0'; - printf("Inserting '%s' for item %p to hash table: %d\n", buf, buf, hid); + printf("Inserting '%s' for item %p to hash table: %d\n", + buf, buf, hid); hash_insert(hid, xstrdup(buf), (void *) 0x12345678); if (random() % 17 == 0) strcpy(todelete, buf); Index: squid/lib/html_quote.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/html_quote.c,v retrieving revision 1.1.30.1.2.1.2.1 retrieving revision 1.1.30.1.2.1.2.2 diff -u -r1.1.30.1.2.1.2.1 -r1.1.30.1.2.1.2.2 --- squid/lib/html_quote.c 27 Aug 2001 21:48:18 -0000 1.1.30.1.2.1.2.1 +++ squid/lib/html_quote.c 9 Sep 2001 11:55:05 -0000 1.1.30.1.2.1.2.2 @@ -47,28 +47,33 @@ /* * HTML defines these characters as special entities that should be quoted. */ -static struct -{ +static struct { unsigned char code; char *quote; -} -htmlstandardentities[] = +} htmlstandardentities[] = + { /* NOTE: The quoted form MUST not be larger than 6 character. * see close to the MemPool commend below */ { - '<', "<"} - , { - '>', ">"} - , { - '"', """} - , { - '&', "&"} - , { - '\'', "'"} - , { - 0, NULL} + '<', "<" + }, + { + '>', ">" + }, + { + '"', """ + }, + { + '&', "&" + }, + { + '\'', "'" + }, + { + 0, NULL + } }; /* @@ -109,8 +114,7 @@ * sure all 8-bit characters are encoded to protect from buggy * clients */ - if (!escape && (ch <= 0x1F || ch >= 0x7f) && ch != '\n' && ch != '\r' - && ch != '\t') { + if (!escape && (ch <= 0x1F || ch >= 0x7f) && ch != '\n' && ch != '\r' && ch != '\t') { static char dec_encoded[7]; snprintf(dec_encoded, sizeof dec_encoded, "&#%3d;", (int) ch); escape = dec_encoded; Index: squid/lib/md5-test.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/md5-test.c,v retrieving revision 1.1.1.1.44.1.2.1 retrieving revision 1.1.1.1.44.1.2.2 diff -u -r1.1.1.1.44.1.2.1 -r1.1.1.1.44.1.2.2 --- squid/lib/md5-test.c 27 Aug 2001 21:48:18 -0000 1.1.1.1.44.1.2.1 +++ squid/lib/md5-test.c 9 Sep 2001 11:55:05 -0000 1.1.1.1.44.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: md5-test.c,v 1.1.1.1.44.1.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: md5-test.c,v 1.1.1.1.44.1.2.2 2001/09/09 11:55:05 serassio Exp $ */ /* @@ -45,8 +45,10 @@ MDString("abc"); MDString("message digest"); MDString("abcdefghijklmnopqrstuvwxyz"); - MDString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); - MDString("1234567890123456789012345678901234567890\ + MDString + ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); + MDString + ("1234567890123456789012345678901234567890\ 1234567890123456789012345678901234567890"); return 0; } Index: squid/lib/md5.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/md5.c,v retrieving revision 1.1.1.2.30.1.2.1 retrieving revision 1.1.1.2.30.1.2.2 diff -u -r1.1.1.2.30.1.2.1 -r1.1.1.2.30.1.2.2 --- squid/lib/md5.c 27 Aug 2001 21:48:18 -0000 1.1.1.2.30.1.2.1 +++ squid/lib/md5.c 9 Sep 2001 11:55:05 -0000 1.1.1.2.30.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: md5.c,v 1.1.1.2.30.1.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: md5.c,v 1.1.1.2.30.1.2.2 2001/09/09 11:55:05 serassio Exp $ */ /* taken from RFC-1321/Appendix A.3 */ @@ -79,7 +79,8 @@ static void MD5_memset(char *, int, unsigned int); #endif -static unsigned char PADDING[64] = { +static unsigned char PADDING[64] = +{ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 Index: squid/lib/radix.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/radix.c,v retrieving revision 1.1.1.2.4.1.2.1.2.1 retrieving revision 1.1.1.2.4.1.2.1.2.2 diff -u -r1.1.1.2.4.1.2.1.2.1 -r1.1.1.2.4.1.2.1.2.2 --- squid/lib/radix.c 27 Aug 2001 21:48:18 -0000 1.1.1.2.4.1.2.1.2.1 +++ squid/lib/radix.c 9 Sep 2001 11:55:05 -0000 1.1.1.2.4.1.2.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: radix.c,v 1.1.1.2.4.1.2.1.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: radix.c,v 1.1.1.2.4.1.2.1.2.2 2001/09/09 11:55:05 serassio Exp $ * * DEBUG: section 53 Radix tree data structure implementation * AUTHOR: NetBSD Derived @@ -118,7 +118,7 @@ struct radix_node_head *mask_rnhead; static char *addmask_key; static unsigned char normal_chars[] = - { 0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xFF }; +{0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xFF}; static char *rn_zeros, *rn_ones; #define rn_masktop (mask_rnhead->rnh_treetop) @@ -184,7 +184,8 @@ register caddr_t v = v_arg, m = m_arg; for (x = head; x->rn_b >= 0;) { - if ((x->rn_bmask & m[x->rn_off]) && (x->rn_bmask & v[x->rn_off])) + if ((x->rn_bmask & m[x->rn_off]) && + (x->rn_bmask & v[x->rn_off])) x = x->rn_r; else x = x->rn_l; @@ -240,7 +241,8 @@ return x; } -static int +static +int rn_satsifies_leaf(trial, leaf, skip) char *trial; register struct radix_node *leaf; @@ -616,7 +618,9 @@ for (t = tt; tt; t = tt, tt = tt->rn_dupedkey) { if (tt->rn_mask == netmask) return (0); - if (netmask == 0 || (tt->rn_mask && ((b_leaf < tt->rn_b) || /* index(netmask) > node */ + if (netmask == 0 || + (tt->rn_mask && + ((b_leaf < tt->rn_b) || /* index(netmask) > node */ rn_refines(netmask, tt->rn_mask) || rn_lexobetter(netmask, tt->rn_mask)))) break; @@ -715,7 +719,8 @@ if (m->rm_flags & RNF_NORMAL) { mmask = m->rm_leaf->rn_mask; if (tt->rn_flags & RNF_NORMAL) { - fprintf(stderr, "Non-unique normal route, mask not entered"); + fprintf(stderr, + "Non-unique normal route, mask not entered"); return tt; } } else @@ -751,7 +756,8 @@ vlen = *(u_char *) v; saved_tt = tt; top = x; - if (tt == 0 || memcmp(v + head_off, tt->rn_key + head_off, vlen - head_off)) + if (tt == 0 || + memcmp(v + head_off, tt->rn_key + head_off, vlen - head_off)) return (0); /* * Delete our route from mask lists. @@ -996,7 +1002,8 @@ max_keylen = dom->dom_maxrtkey; #endif if (max_keylen == 0) { - fprintf(stderr, "rn_init: radix functions require max_keylen be set\n"); + fprintf(stderr, + "rn_init: radix functions require max_keylen be set\n"); return; } R_Malloc(rn_zeros, char *, 3 * max_keylen); Index: squid/lib/readdir.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/Attic/readdir.c,v retrieving revision 1.1.78.1.2.1 retrieving revision 1.1.78.1.2.2 diff -u -r1.1.78.1.2.1 -r1.1.78.1.2.2 --- squid/lib/readdir.c 27 Aug 2001 21:48:18 -0000 1.1.78.1.2.1 +++ squid/lib/readdir.c 9 Sep 2001 11:55:05 -0000 1.1.78.1.2.2 @@ -1,3 +1,4 @@ + #include #include #include @@ -17,8 +18,7 @@ * The DIR typedef is not compatible with Unix. **********************************************************************/ -DIR * -opendir(const char *dir) +DIR * opendir(const char *dir) { DIR *dp; char *filespec; @@ -29,19 +29,19 @@ strcpy(filespec, dir); index = strlen(filespec) - 1; if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\')) - filespec[index] = '\0'; + filespec[index] = '\0'; strcat(filespec, "/*"); - dp = (DIR *) malloc(sizeof(DIR)); + dp = (DIR *)malloc(sizeof(DIR)); dp->offset = 0; dp->finished = 0; dp->dir = strdup(dir); if ((handle = _findfirst(filespec, &(dp->fileinfo))) < 0) { - if (errno == ENOENT) - dp->finished = 1; - else - return NULL; + if (errno == ENOENT) + dp->finished = 1; + else + return NULL; } dp->handle = handle; @@ -50,17 +50,15 @@ return dp; } -struct dirent * -readdir(DIR * dp) +struct dirent * readdir(DIR *dp) { - if (!dp || dp->finished) - return NULL; + if (!dp || dp->finished) return NULL; if (dp->offset != 0) { - if (_findnext(dp->handle, &(dp->fileinfo)) < 0) { - dp->finished = 1; - return NULL; - } + if (_findnext(dp->handle, &(dp->fileinfo)) < 0) { + dp->finished = 1; + return NULL; + } } dp->offset++; @@ -72,16 +70,12 @@ return &(dp->dent); } -int -closedir(DIR * dp) +int closedir(DIR *dp) { - if (!dp) - return 0; + if (!dp) return 0; _findclose(dp->handle); - if (dp->dir) - free(dp->dir); - if (dp) - free(dp); + if (dp->dir) free(dp->dir); + if (dp) free(dp); return 0; } Index: squid/lib/rfc1035.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/rfc1035.c,v retrieving revision 1.1.1.1.4.3.2.1.2.1 retrieving revision 1.1.1.1.4.3.2.1.2.2 diff -u -r1.1.1.1.4.3.2.1.2.1 -r1.1.1.1.4.3.2.1.2.2 --- squid/lib/rfc1035.c 27 Aug 2001 21:48:18 -0000 1.1.1.1.4.3.2.1.2.1 +++ squid/lib/rfc1035.c 9 Sep 2001 11:55:05 -0000 1.1.1.1.4.3.2.1.2.2 @@ -1,5 +1,6 @@ + /* - * $Id: rfc1035.c,v 1.1.1.1.4.3.2.1.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: rfc1035.c,v 1.1.1.1.4.3.2.1.2.2 2001/09/09 11:55:05 serassio Exp $ * * Low level DNS protocol routines * AUTHOR: Duane Wessels @@ -77,8 +78,7 @@ int rfc1035_errno; const char *rfc1035_error_message; -struct _rfc1035_header -{ +struct _rfc1035_header { unsigned short id; unsigned int qr:1; unsigned int opcode:4; @@ -191,7 +191,10 @@ */ static off_t rfc1035QuestionPack(char *buf, - size_t sz, const char *name, unsigned short type, unsigned short class) + size_t sz, + const char *name, + unsigned short type, + unsigned short class) { off_t off = 0; unsigned short s; @@ -374,7 +377,9 @@ int rfc1035AnswersUnpack(const char *buf, - size_t sz, rfc1035_rr ** records, unsigned short *id) + size_t sz, + rfc1035_rr ** records, + unsigned short *id) { off_t off = 0; int l; @@ -473,7 +478,10 @@ h.qdcount = (unsigned int) 1; offset += rfc1035HeaderPack(buf + offset, sz - offset, &h); offset += rfc1035QuestionPack(buf + offset, - sz - offset, hostname, RFC1035_TYPE_A, RFC1035_CLASS_IN); + sz - offset, + hostname, + RFC1035_TYPE_A, + RFC1035_CLASS_IN); assert(offset <= sz); *szp = (size_t) offset; return h.id; @@ -500,7 +508,10 @@ memset(&h, '\0', sizeof(h)); i = (unsigned int) ntohl(addr.s_addr); snprintf(rev, 32, "%u.%u.%u.%u.in-addr.arpa.", - i & 255, (i >> 8) & 255, (i >> 16) & 255, (i >> 24) & 255); + i & 255, + (i >> 8) & 255, + (i >> 16) & 255, + (i >> 24) & 255); h.id = rfc1035Qid(); h.qr = 0; h.rd = 1; @@ -508,7 +519,10 @@ h.qdcount = (unsigned int) 1; offset += rfc1035HeaderPack(buf + offset, sz - offset, &h); offset += rfc1035QuestionPack(buf + offset, - sz - offset, rev, RFC1035_TYPE_PTR, RFC1035_CLASS_IN); + sz - offset, + rev, + RFC1035_TYPE_PTR, + RFC1035_CLASS_IN); assert(offset <= sz); *szp = (size_t) offset; return h.id; @@ -584,7 +598,10 @@ int i; int n; rfc1035_rr *answers = NULL; - n = rfc1035AnswersUnpack(rbuf, rl, &answers, &rid); + n = rfc1035AnswersUnpack(rbuf, + rl, + &answers, + &rid); if (rid != sid) { printf("ERROR, ID mismatch (%#hx, %#hx)\n", sid, rid); } else if (n < 0) { Index: squid/lib/rfc1738.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/rfc1738.c,v retrieving revision 1.1.1.2.4.1.2.2.2.1 retrieving revision 1.1.1.2.4.1.2.2.2.2 diff -u -r1.1.1.2.4.1.2.2.2.1 -r1.1.1.2.4.1.2.2.2.2 --- squid/lib/rfc1738.c 27 Aug 2001 21:48:18 -0000 1.1.1.2.4.1.2.2.2.1 +++ squid/lib/rfc1738.c 9 Sep 2001 11:55:05 -0000 1.1.1.2.4.1.2.2.2.2 @@ -1,5 +1,5 @@ /* - * $Id: rfc1738.c,v 1.1.1.2.4.1.2.2.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: rfc1738.c,v 1.1.1.2.4.1.2.2.2.2 2001/09/09 11:55:05 serassio Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -48,7 +48,8 @@ * RFC 1738 defines that these characters should be escaped, as well * any non-US-ASCII character or anything between 0x00 - 0x1F. */ -static char rfc1738_unsafe_chars[] = { +static char rfc1738_unsafe_chars[] = +{ (char) 0x3C, /* < */ (char) 0x3E, /* > */ (char) 0x22, /* " */ @@ -69,7 +70,8 @@ (char) 0x20 /* space */ }; -static char rfc1738_reserved_chars[] = { +static char rfc1738_reserved_chars[] = +{ (char) 0x3b, /* ; */ (char) 0x2f, /* / */ (char) 0x3f, /* ? */ @@ -111,8 +113,7 @@ if (encode_reserved >= 0 && *p == '%') do_escape = 1; /* RFC 1738 defines these chars as reserved */ - for (i = 0; i < sizeof(rfc1738_reserved_chars) && encode_reserved > 0; - i++) { + for (i = 0; i < sizeof(rfc1738_reserved_chars) && encode_reserved > 0; i++) { if (*p == rfc1738_reserved_chars[i]) { do_escape = 1; break; Index: squid/lib/snprintf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/snprintf.c,v retrieving revision 1.1.1.3.30.1.2.1 retrieving revision 1.1.1.3.30.1.2.2 diff -u -r1.1.1.3.30.1.2.1 -r1.1.1.3.30.1.2.2 --- squid/lib/snprintf.c 27 Aug 2001 21:48:18 -0000 1.1.1.3.30.1.2.1 +++ squid/lib/snprintf.c 9 Sep 2001 11:55:05 -0000 1.1.1.3.30.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: snprintf.c,v 1.1.1.3.30.1.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: snprintf.c,v 1.1.1.3.30.1.2.2 2001/09/09 11:55:05 serassio Exp $ */ /* ==================================================================== @@ -196,7 +196,7 @@ for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--) ndigit--; if ((decpt >= 0 && decpt - ndigit > 4) - || (decpt < 0 && decpt < -3)) { /* use E-style */ + || (decpt < 0 && decpt < -3)) { /* use E-style */ decpt--; *p2++ = *p1++; *p2++ = '.'; @@ -241,11 +241,9 @@ #endif /* HAVE_CVT */ -typedef enum -{ +typedef enum { NO = 0, YES = 1 -} -boolean_e; +} boolean_e; #define FALSE 0 #define TRUE 1 @@ -274,8 +272,7 @@ /* * Descriptor for buffer area */ -struct buf_area -{ +struct buf_area { char *buf_end; char *nextb; /* pointer to next byte to read/write */ }; @@ -411,8 +408,7 @@ */ static char * conv_fp(register char format, register double num, - boolean_e add_dp, int precision, bool_int * is_negative, char *buf, - int *len) + boolean_e add_dp, int precision, bool_int * is_negative, char *buf, int *len) { register char *s = buf; register char *p; @@ -523,7 +519,8 @@ * Do format conversion placing the output in buffer */ static int -format_converter(register buffy * odp, const char *fmt, va_list ap) +format_converter(register buffy * odp, const char *fmt, + va_list ap) { register char *sp; register char *bep; @@ -536,11 +533,9 @@ register int min_width = 0; int precision = 0; - enum - { + enum { LEFT, RIGHT - } - adjust; + } adjust; char pad_char; char prefix_char; @@ -703,7 +698,8 @@ ui_num = va_arg(ap, u_wide_int); else ui_num = (u_wide_int) va_arg(ap, unsigned int); - s = conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); + s = conv_p2(ui_num, 3, *fmt, + &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && *s != '0') { *--s = '0'; @@ -718,7 +714,8 @@ ui_num = (u_wide_int) va_arg(ap, u_wide_int); else ui_num = (u_wide_int) va_arg(ap, unsigned int); - s = conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len); + s = conv_p2(ui_num, 4, *fmt, + &num_buf[NUM_BUF_SIZE], &s_len); FIX_PRECISION(adjust_precision, precision, s, s_len); if (alternate_form && i_num != 0) { *--s = *fmt; /* 'x' or 'X' */ @@ -817,7 +814,8 @@ ui_num = (u_wide_int) va_arg(ap, char *); if (sizeof(char *) <= sizeof(u_wide_int)) - s = conv_p2(ui_num, 4, 'x', &num_buf[NUM_BUF_SIZE], &s_len); + s = conv_p2(ui_num, 4, 'x', + &num_buf[NUM_BUF_SIZE], &s_len); else { s = "%p"; s_len = 2; @@ -890,7 +888,8 @@ * because size_t is unsigned on some platforms */ static void -strx_printv(int *ccp, char *buf, size_t len, const char *format, va_list ap) +strx_printv(int *ccp, char *buf, size_t len, const char *format, + va_list ap) { buffy od; int cc; @@ -923,7 +922,7 @@ * if len == 0, silently return */ int -snprintf(char *buf, size_t len, const char *format, ...) +snprintf(char *buf, size_t len, const char *format,...) { int cc = 0; va_list ap; Index: squid/lib/splay.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/splay.c,v retrieving revision 1.1.1.2.2.1.2.1 retrieving revision 1.1.1.2.2.1.2.2 diff -u -r1.1.1.2.2.1.2.1 -r1.1.1.2.2.1.2.2 --- squid/lib/splay.c 27 Aug 2001 21:48:18 -0000 1.1.1.2.2.1.2.1 +++ squid/lib/splay.c 9 Sep 2001 11:55:05 -0000 1.1.1.2.2.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: splay.c,v 1.1.1.2.2.1.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: splay.c,v 1.1.1.2.2.1.2.2 2001/09/09 11:55:05 serassio Exp $ */ #include "config.h" @@ -148,11 +148,9 @@ #ifdef DRIVER -typedef struct -{ +typedef struct { int i; -} -intnode; +} intnode; int compareint(void *a, splayNode * n) Index: squid/lib/uudecode.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/uudecode.c,v retrieving revision 1.1.1.1.44.1.2.1 retrieving revision 1.1.1.1.44.1.2.2 diff -u -r1.1.1.1.44.1.2.1 -r1.1.1.1.44.1.2.2 --- squid/lib/uudecode.c 27 Aug 2001 21:48:18 -0000 1.1.1.1.44.1.2.1 +++ squid/lib/uudecode.c 9 Sep 2001 11:55:05 -0000 1.1.1.1.44.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: uudecode.c,v 1.1.1.1.44.1.2.1 2001/08/27 21:48:18 tolsty Exp $ + * $Id: uudecode.c,v 1.1.1.1.44.1.2.2 2001/09/09 11:55:05 serassio Exp $ */ #include "config.h" @@ -8,27 +8,18 @@ extern char **environ; /* aaaack but it's fast and const should make it shared text page. */ -const int pr2six[256] = { - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 62, 64, 64, 64, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, 64, 0, 1, 2, - 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, - 64, 64, 64, 26, 27, - 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, 48, 49, 50, 51, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, +const int pr2six[256] = +{ + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, 64, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }; @@ -54,7 +45,7 @@ nprbytes = (char *) bufin - bufcoded - 1; nbytesdecoded = ((nprbytes + 3) / 4) * 3; - bufplain = (char *) xmalloc(nbytesdecoded + 1); + bufplain = (char*)xmalloc(nbytesdecoded + 1); bufout = (unsigned char *) bufplain; bufin = (const unsigned char *) bufcoded;