home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / mallc120 / part05 < prev    next >
Encoding:
Text File  |  1993-04-05  |  69.5 KB  |  2,470 lines

  1. Newsgroups: comp.sources.unix
  2. From: gray@antaire.com (Gray Watson)
  3. Subject: v26i102: malloc - debugging version of malloc, V1.2.0, Part05/05
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: gray@antaire.com (Gray Watson)
  8. Posting-Number: Volume 26, Issue 102
  9. Archive-Name: malloc-1.2.0/part05
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 5 (of 5)."
  18. # Contents:  configure.in dbg_tokens.h dbg_values.h heap.c heap.h
  19. #   malloc.h malloc_dbg.c malloc_loc.h malloc_lp.c malloc_lp.h
  20. #   malloc_str.c malloc_str.h sample.c version.h
  21. # Wrapped by gray@toaster.antaire.com on Tue Apr  6 01:24:07 1993
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'configure.in' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'configure.in'\"
  25. else
  26. echo shar: Extracting \"'configure.in'\" \(1711 characters\)
  27. sed "s/^X//" >'configure.in' <<'END_OF_FILE'
  28. Xdnl
  29. Xdnl Process this file with autoconf to produce a configure script.
  30. Xdnl Copyright 1992 by Gray Watson and the Antaire Corporation
  31. Xdnl
  32. XAC_INIT(malloc.c)
  33. XAC_CONFIG_HEADER(conf.h)
  34. Xdnl
  35. Xecho Configuring for the malloc-debug library
  36. Xecho .
  37. Xecho checking programs:
  38. XAC_PROG_CC
  39. XAC_PROG_INSTALL
  40. XAC_PROG_RANLIB
  41. Xdnl
  42. Xecho .
  43. Xecho checking functions:
  44. XAC_HAVE_FUNCS(bcmp bcopy memcmp memcpy memset)
  45. Xdnl this is necessary because index is a m4 function
  46. Xecho checking for _index
  47. XAC_TEST_PROGRAM([
  48. Xmain() { exit(0); }
  49. Xt() {
  50. X#ifdef __stub_index
  51. Xchoke me
  52. X#else
  53. X/* Override any gcc2 internal prototype to avoid an error.  */
  54. Xextern char index(); index();
  55. X#endif
  56. X }
  57. X], [
  58. XAC_DEFINE(HAVE_INDEX, 1)
  59. X], [
  60. XAC_DEFINE(HAVE_INDEX, 0)
  61. X])
  62. XAC_HAVE_FUNCS(rindex)
  63. XAC_HAVE_FUNCS(strcat strcmp strlen strtok)
  64. Xecho .
  65. Xecho checking various functions for string checking
  66. XAC_HAVE_FUNCS(bzero)
  67. XAC_HAVE_FUNCS(memccpy memchr)
  68. XAC_HAVE_FUNCS(strchr strrchr strcpy strncpy strcasecmp strncasecmp)
  69. XAC_HAVE_FUNCS(strspn strcspn strncat strncmp strpbrk strstr)
  70. Xdnl
  71. Xecho .
  72. Xecho PLEASE WATCH: checking for very important functionality:
  73. XAC_HAVE_FUNCS(sbrk)
  74. Xecho checking for heap ordering...
  75. XAC_TEST_PROGRAM([
  76. Xmain()
  77. X{
  78. X  char    * first, *next;
  79. X  first = sbrk(1024);
  80. X  next = sbrk(1024);
  81. X  if (next > first)
  82. X    exit(0);
  83. X  else
  84. X    exit(1);
  85. X}
  86. X], [
  87. XAC_DEFINE(HEAP_GROWS_UP, 1)
  88. Xecho '   FYI: your heap seems to grow up.'
  89. X], [
  90. XAC_DEFINE(HEAP_GROWS_UP, 0)
  91. Xecho '   FYI: your heap seems to grow down.'
  92. Xecho '   WARNING: the library has little support for this.'
  93. X])
  94. Xdnl
  95. Xecho .
  96. XAC_OUTPUT(Makefile)
  97. Xecho .
  98. Xecho Done!!
  99. Xecho created conf.h and Makefile.
  100. Xecho Please check-out Makefile and especially conf.h to make sure that
  101. Xecho     sane configuration values were a result.
  102. END_OF_FILE
  103. if test 1711 -ne `wc -c <'configure.in'`; then
  104.     echo shar: \"'configure.in'\" unpacked with wrong size!
  105. fi
  106. # end of 'configure.in'
  107. fi
  108. if test -f 'dbg_tokens.h' -a "${1}" != "-c" ; then 
  109.   echo shar: Will not clobber existing file \"'dbg_tokens.h'\"
  110. else
  111. echo shar: Extracting \"'dbg_tokens.h'\" \(2293 characters\)
  112. sed "s/^X//" >'dbg_tokens.h' <<'END_OF_FILE'
  113. X/*
  114. X * tokens attributes for the malloc_dbg program
  115. X *
  116. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  117. X *
  118. X * This file is part of the malloc-debug package.
  119. X *
  120. X * This library is free software; you can redistribute it and/or
  121. X * modify it under the terms of the GNU Library General Public
  122. X * License as published by the Free Software Foundation; either
  123. X * version 2 of the License, or (at your option) any later version.
  124. X *
  125. X * This library is distributed in the hope that it will be useful,
  126. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  127. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  128. X * Library General Public License for more details.
  129. X *
  130. X * You should have received a copy of the GNU Library General Public
  131. X * License along with this library (see COPYING-LIB); if not, write to the
  132. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  133. X *
  134. X * The author of the program may be contacted at gray.watson@antaire.com
  135. X *
  136. X * $Id: dbg_tokens.h,v 1.5 1993/04/05 22:30:04 gray Exp $
  137. X */
  138. X
  139. X#ifndef __DBG_TOKENS_H__
  140. X#define __DBG_TOKENS_H__
  141. X
  142. X#include "malloc.h"            /* for LOCAL and bool stuff */
  143. X#include "dbg_values.h"            /* for debug codes */
  144. X
  145. Xtypedef struct {
  146. X  char        *at_string;        /* attribute string */
  147. X  int        at_value;        /* value for the item*/
  148. X} attr_t;
  149. X
  150. XLOCAL    attr_t        attributes[] = {
  151. X  { "none",            0 },
  152. X  
  153. X  { "log-stats",        DEBUG_LOG_STATS },
  154. X  { "log-non-free",        DEBUG_LOG_NONFREE },
  155. X  { "log-perror",        DEBUG_LOG_PERROR },
  156. X  { "log-trans",        DEBUG_LOG_TRANS },
  157. X  { "log-bad-pnt",        DEBUG_LOG_BAD_POINTER },
  158. X  { "log-admin",        DEBUG_LOG_ADMIN },
  159. X  { "log-blocks",        DEBUG_LOG_BLOCKS },
  160. X  { "log-unknown",        DEBUG_LOG_UNKNOWN },
  161. X  
  162. X  { "check-fence",        DEBUG_CHECK_FENCE },
  163. X  { "check-heap",        DEBUG_CHECK_HEAP },
  164. X  { "check-lists",        DEBUG_CHECK_LISTS },
  165. X  { "check-dblock",        DEBUG_CHECK_DBLOCK },
  166. X  { "check-dblock-fence",    DEBUG_CHECK_DB_FENCE },
  167. X  { "check-free",        DEBUG_CHECK_FREE },
  168. X  { "check-funcs",        DEBUG_CHECK_FUNCS },
  169. X  
  170. X  { "realloc-copy",        DEBUG_REALLOC_COPY },
  171. X  { "free-blank",        DEBUG_FREE_BLANK },
  172. X  { "error-abort",        DEBUG_ERROR_ABORT },
  173. X  { "alloc-blank",        DEBUG_ALLOC_BLANK },
  174. X  { "heap-check-map",        DEBUG_HEAP_CHECK_MAP },
  175. X  { "print-perror",        DEBUG_PRINT_PERROR },
  176. X  
  177. X  { NULL }
  178. X};
  179. X
  180. X#endif /* ! __DBG_TOKENS_H__ */
  181. END_OF_FILE
  182. if test 2293 -ne `wc -c <'dbg_tokens.h'`; then
  183.     echo shar: \"'dbg_tokens.h'\" unpacked with wrong size!
  184. fi
  185. # end of 'dbg_tokens.h'
  186. fi
  187. if test -f 'dbg_values.h' -a "${1}" != "-c" ; then 
  188.   echo shar: Will not clobber existing file \"'dbg_values.h'\"
  189. else
  190. echo shar: Extracting \"'dbg_values.h'\" \(2848 characters\)
  191. sed "s/^X//" >'dbg_values.h' <<'END_OF_FILE'
  192. X/*
  193. X * debug values for MALLOC_DEBUG and _malloc_debug
  194. X *
  195. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  196. X *
  197. X * This file is part of the malloc-debug package.
  198. X *
  199. X * This library is free software; you can redistribute it and/or
  200. X * modify it under the terms of the GNU Library General Public
  201. X * License as published by the Free Software Foundation; either
  202. X * version 2 of the License, or (at your option) any later version.
  203. X *
  204. X * This library is distributed in the hope that it will be useful,
  205. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  206. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  207. X * Library General Public License for more details.
  208. X *
  209. X * You should have received a copy of the GNU Library General Public
  210. X * License along with this library (see COPYING-LIB); if not, write to the
  211. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  212. X *
  213. X * The author of the program may be contacted at gray.watson@antaire.com
  214. X *
  215. X * $Id: dbg_values.h,v 1.3 1993/04/05 22:30:05 gray Exp $
  216. X */
  217. X
  218. X#ifndef __DBG_VALUES_H__
  219. X#define __DBG_VALUES_H__
  220. X
  221. X/*
  222. X * special debug codes which detail what debug features are enabled
  223. X */
  224. X
  225. X/* logging */
  226. X#define DEBUG_LOG_STATS        BIT_FLAG(0)    /* generally log statistics */
  227. X#define DEBUG_LOG_NONFREE    BIT_FLAG(1)    /* report non-freed pointers */
  228. X#define DEBUG_LOG_PERROR    BIT_FLAG(2)    /* log perror problems */
  229. X#define DEBUG_LOG_TRANS        BIT_FLAG(3)    /* log memory transactions */
  230. X#define DEBUG_LOG_BAD_POINTER    BIT_FLAG(4)    /* log pointer info on error */
  231. X#define DEBUG_LOG_ADMIN        BIT_FLAG(5)    /* log background admin info */
  232. X#define DEBUG_LOG_BLOCKS    BIT_FLAG(6)    /* log blocks when heap-map */
  233. X#define DEBUG_LOG_UNKNOWN    BIT_FLAG(7)    /* report unknown non-freed */
  234. X
  235. X/* checking */
  236. X#define DEBUG_CHECK_FENCE    BIT_FLAG(10)    /* check fence-post errors  */
  237. X#define DEBUG_CHECK_HEAP    BIT_FLAG(11)    /* examine heap adm structs */
  238. X#define DEBUG_CHECK_LISTS    BIT_FLAG(12)    /* check the free lists */
  239. X#define DEBUG_CHECK_DBLOCK    BIT_FLAG(13)    /* closely examine dblocks */
  240. X#define DEBUG_CHECK_DB_FENCE    BIT_FLAG(14)    /* check fences for dblocks */
  241. X#define DEBUG_CHECK_FREE    BIT_FLAG(15)    /* check free blocks of 0's */
  242. X#define DEBUG_CHECK_FUNCS    BIT_FLAG(16)    /* check functions */
  243. X
  244. X/* misc */
  245. X#define DEBUG_REALLOC_COPY    BIT_FLAG(20)    /* copy all reallocations */
  246. X#define DEBUG_FREE_BLANK    BIT_FLAG(21)    /* write over free'd memory */
  247. X#define DEBUG_ERROR_ABORT    BIT_FLAG(22)    /* abort on error else exit */
  248. X#define DEBUG_ALLOC_BLANK    BIT_FLAG(23)    /* write over to-be-alloced */
  249. X#define DEBUG_HEAP_CHECK_MAP    BIT_FLAG(24)    /* heap-map on heap-check */
  250. X#define DEBUG_PRINT_PERROR    BIT_FLAG(25)    /* print errors to STDERR */
  251. X
  252. X/*
  253. X * special flags that after being set or not/set and process start-up, cannot
  254. X * be reset.
  255. X */
  256. X#define DEBUG_NOT_CHANGEABLE    (DEBUG_CHECK_FREE)
  257. X
  258. X#endif /* ! __DBG_VALUES_H__ */
  259. END_OF_FILE
  260. if test 2848 -ne `wc -c <'dbg_values.h'`; then
  261.     echo shar: \"'dbg_values.h'\" unpacked with wrong size!
  262. fi
  263. # end of 'dbg_values.h'
  264. fi
  265. if test -f 'heap.c' -a "${1}" != "-c" ; then 
  266.   echo shar: Will not clobber existing file \"'heap.c'\"
  267. else
  268. echo shar: Extracting \"'heap.c'\" \(2785 characters\)
  269. sed "s/^X//" >'heap.c' <<'END_OF_FILE'
  270. X/*
  271. X * system specific memory routines
  272. X *
  273. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  274. X *
  275. X * This file is part of the malloc-debug package.
  276. X *
  277. X * This library is free software; you can redistribute it and/or
  278. X * modify it under the terms of the GNU Library General Public
  279. X * License as published by the Free Software Foundation; either
  280. X * version 2 of the License, or (at your option) any later version.
  281. X *
  282. X * This library is distributed in the hope that it will be useful,
  283. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  284. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  285. X * Library General Public License for more details.
  286. X *
  287. X * You should have received a copy of the GNU Library General Public
  288. X * License along with this library (see COPYING-LIB); if not, write to the
  289. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  290. X *
  291. X * The author of the program may be contacted at gray.watson@antaire.com
  292. X */
  293. X
  294. X/*
  295. X * These are the system/machine specific routines for allocating space on the
  296. X * heap as well as reporting the current position of the heap.
  297. X */
  298. X
  299. X#define MALLOC_DEBUG_DISABLE
  300. X
  301. X#include "malloc.h"
  302. X#include "malloc_loc.h"
  303. X
  304. X#include "chunk.h"
  305. X#include "compat.h"
  306. X#include "conf.h"
  307. X#include "error.h"
  308. X#include "error_val.h"
  309. X#include "heap.h"
  310. X
  311. X#if INCLUDE_RCS_IDS
  312. XLOCAL    char    *rcs_id =
  313. X  "$Id: heap.c,v 1.18 1993/04/05 01:29:03 gray Exp $";
  314. X#endif
  315. X
  316. X/* external routines */
  317. X#if HAVE_SBRK
  318. XIMPORT    char        *sbrk(int incr);    /* to extend the heap */
  319. X#define SBRK_ERROR    ((char *)-1)        /* sbrk error code */
  320. X#endif
  321. X
  322. X/* exported variables */
  323. XEXPORT    char        *_heap_base = NULL;    /* base of our heap */
  324. XEXPORT    char        *_heap_last = NULL;    /* end of our heap */
  325. X
  326. X/*
  327. X * function to get SIZE memory bytes from the end of the heap
  328. X */
  329. XEXPORT    char    *_heap_alloc(unsigned int size)
  330. X{
  331. X  char        *ret = HEAP_ALLOC_ERROR;
  332. X  
  333. X#if HAVE_SBRK
  334. X  ret = sbrk(size);
  335. X  if (ret == SBRK_ERROR) {
  336. X    malloc_errno = MALLOC_ALLOC_FAILED;
  337. X    _malloc_perror("_heap_alloc");
  338. X    ret = HEAP_ALLOC_ERROR;
  339. X  }
  340. X  else {
  341. X    /* increment last pointer */
  342. X    _heap_last += size;
  343. X  }
  344. X#endif
  345. X  
  346. X  return ret;
  347. X}
  348. X
  349. X/*
  350. X * return a pointer to the current end of the heap
  351. X */
  352. XEXPORT    char    *_heap_end(void)
  353. X{
  354. X  char        *ret = HEAP_ALLOC_ERROR;
  355. X  
  356. X#if HAVE_SBRK
  357. X  ret = sbrk(0);
  358. X  if (ret == SBRK_ERROR) {
  359. X    malloc_errno = MALLOC_ALLOC_FAILED;
  360. X    _malloc_perror("_heap_end");
  361. X    ret = HEAP_ALLOC_ERROR;
  362. X  }
  363. X#endif
  364. X  
  365. X  return ret;
  366. X}
  367. X
  368. X/*
  369. X * initialize heap pointers
  370. X */
  371. XEXPORT    void    _heap_startup(void)
  372. X{
  373. X  _heap_base = _heap_last = _heap_end();
  374. X}
  375. X
  376. X/*
  377. X * align (by extending) _heap_base to BASE byte boundary
  378. X */
  379. XEXPORT    char    *_heap_align_base(int base)
  380. X{
  381. X  int    diff;
  382. X  
  383. X  diff = (long)_heap_base % base;
  384. X  _heap_base += base - diff;
  385. X  
  386. X  return _heap_alloc(base - diff);
  387. X}
  388. END_OF_FILE
  389. if test 2785 -ne `wc -c <'heap.c'`; then
  390.     echo shar: \"'heap.c'\" unpacked with wrong size!
  391. fi
  392. # end of 'heap.c'
  393. fi
  394. if test -f 'heap.h' -a "${1}" != "-c" ; then 
  395.   echo shar: Will not clobber existing file \"'heap.h'\"
  396. else
  397. echo shar: Extracting \"'heap.h'\" \(2524 characters\)
  398. sed "s/^X//" >'heap.h' <<'END_OF_FILE'
  399. X/*
  400. X * defines for the system specific memory routines
  401. X *
  402. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  403. X *
  404. X * This file is part of the malloc-debug package.
  405. X *
  406. X * This library is free software; you can redistribute it and/or
  407. X * modify it under the terms of the GNU Library General Public
  408. X * License as published by the Free Software Foundation; either
  409. X * version 2 of the License, or (at your option) any later version.
  410. X *
  411. X * This library is distributed in the hope that it will be useful,
  412. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  413. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  414. X * Library General Public License for more details.
  415. X *
  416. X * You should have received a copy of the GNU Library General Public
  417. X * License along with this library (see COPYING-LIB); if not, write to the
  418. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  419. X *
  420. X * The author of the program may be contacted at gray.watson@antaire.com
  421. X *
  422. X * $Id: heap.h,v 1.9 1993/03/26 09:16:41 gray Exp $
  423. X */
  424. X
  425. X#ifndef __HEAP_H__
  426. X#define __HEAP_H__
  427. X
  428. X#include "malloc.h"            /* for LOCAL and bool stuff */
  429. X
  430. X/*
  431. X * error code returned by heap allocation routine
  432. X */
  433. X#define HEAP_ALLOC_ERROR    ((char *)-1)
  434. X
  435. X/*
  436. X * probably machine specific defines used for certain calculations
  437. X */
  438. X#if HEAP_GROWS_UP
  439. X
  440. X/* test whether pointer P is in the heap space */
  441. X#define IS_IN_HEAP(p)        \
  442. X  ((char *)(p) >= _heap_base && (char *)(p) < _heap_last)
  443. X
  444. X/* turn pointer P into a block index */
  445. X#define WHICH_BLOCK(p)        (((p) - _heap_base) / BLOCK_SIZE)
  446. X
  447. X/* get a pointer to the memory block number C */
  448. X#define BLOCK_POINTER(c)    (_heap_base + (c) * BLOCK_SIZE)
  449. X
  450. X/* test whether pointer P is on a block boundary */
  451. X#define ON_BLOCK(p)        (((p) - _heap_base) % BLOCK_SIZE == 0)
  452. X
  453. X/* calculate the size of heap */
  454. X#define HEAP_SIZE        (_heap_last - _heap_base)
  455. X
  456. X#endif
  457. X
  458. X/*<<<<<<<<<<  The below prototypes are auto-generated by fillproto */
  459. X
  460. XIMPORT    char        *_heap_base;  /* base of our heap */
  461. X
  462. XIMPORT    char        *_heap_last;  /* end of our heap */
  463. X
  464. X/*
  465. X * function to get SIZE memory bytes from the end of the heap
  466. X */
  467. XIMPORT    char    *_heap_alloc(unsigned int size);
  468. X
  469. X/*
  470. X * return a pointer to the current end of the heap
  471. X */
  472. XIMPORT    char    *_heap_end(void);
  473. X
  474. X/*
  475. X * initialize heap pointers
  476. X */
  477. XIMPORT    void    _heap_startup(void);
  478. X
  479. X/*
  480. X * align (by extending) _heap_base to BASE byte boundary
  481. X */
  482. XIMPORT    char    *_heap_align_base(int base);
  483. X
  484. X/*<<<<<<<<<<   This is end of the auto-generated output from fillproto. */
  485. X
  486. X#endif /* ! __HEAP_H__ */
  487. END_OF_FILE
  488. if test 2524 -ne `wc -c <'heap.h'`; then
  489.     echo shar: \"'heap.h'\" unpacked with wrong size!
  490. fi
  491. # end of 'heap.h'
  492. fi
  493. if test -f 'malloc.h' -a "${1}" != "-c" ; then 
  494.   echo shar: Will not clobber existing file \"'malloc.h'\"
  495. else
  496. echo shar: Extracting \"'malloc.h'\" \(9046 characters\)
  497. sed "s/^X//" >'malloc.h' <<'END_OF_FILE'
  498. X/*
  499. X * defines for the malloc-debug library
  500. X *
  501. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  502. X *
  503. X * This file is part of the malloc-debug package.
  504. X *
  505. X * This library is free software; you can redistribute it and/or
  506. X * modify it under the terms of the GNU Library General Public
  507. X * License as published by the Free Software Foundation; either
  508. X * version 2 of the License, or (at your option) any later version.
  509. X *
  510. X * This library is distributed in the hope that it will be useful,
  511. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  512. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  513. X * Library General Public License for more details.
  514. X *
  515. X * You should have received a copy of the GNU Library General Public
  516. X * License along with this library (see COPYING-LIB); if not, write to the
  517. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  518. X *
  519. X * The author of the program may be contacted at gray.watson@antaire.com
  520. X *
  521. X * $Id: malloc.h,v 1.21 1993/04/06 04:48:09 gray Exp $
  522. X */
  523. X
  524. X#ifndef __MALLOC_H__
  525. X#define __MALLOC_H__
  526. X
  527. X/*
  528. X * malloc function return codes
  529. X */
  530. X#define CALLOC_ERROR        0        /* error from calloc */
  531. X#define MALLOC_ERROR        0        /* error from malloc */
  532. X#define REALLOC_ERROR        0        /* error from realloc */
  533. X
  534. X#define FREE_ERROR        0        /* error from free */
  535. X#define FREE_NOERROR        1        /* no error from free */
  536. X
  537. X#define MALLOC_VERIFY_ERROR    0        /* checks failed, error */
  538. X#define MALLOC_VERIFY_NOERROR    1        /* checks passed, no error */
  539. X
  540. X/*
  541. X * default values if _malloc_file and _malloc_line are not set
  542. X */
  543. X#define MALLOC_DEFAULT_FILE    "unknown"
  544. X#define MALLOC_DEFAULT_LINE    0
  545. X
  546. X/*
  547. X * global variable and procedure scoping for code readability
  548. X */
  549. X#undef    EXPORT
  550. X#define    EXPORT
  551. X
  552. X#undef    IMPORT
  553. X#define    IMPORT        extern
  554. X
  555. X#undef    LOCAL
  556. X#define    LOCAL        static
  557. X
  558. X#if __GNUC__ < 2
  559. X/*
  560. X * prototype for memory copy.  needed for below macros.
  561. X */
  562. XIMPORT    char    *memcpy(char * to, char * from, int length);
  563. X#endif
  564. X
  565. X/*
  566. X * memory copy: copy SIZE bytes from pointer FROM to pointer TO
  567. X */
  568. X#define MEMORY_COPY(from, to, size)    (void)memcpy((char *)to, \
  569. X                             (char *)from, size)
  570. X
  571. X/*
  572. X * alloc macros to improve memory usage readibility...
  573. X */
  574. X#undef ALLOC
  575. X#undef CALLOC
  576. X#undef MALLOC
  577. X#undef REALLOC
  578. X#undef REMALLOC
  579. X#undef FREE
  580. X
  581. X#define ALLOC(type, count) \
  582. X  (type *)malloc((unsigned int)(sizeof(type) * (count)))
  583. X
  584. X#define MALLOC(size) \
  585. X  (char *)malloc((unsigned int)(size))
  586. X
  587. X/* WARNING: notice that the arguments are REVERSED from normal calloc() */
  588. X#define CALLOC(type, count) \
  589. X  (type *)calloc((unsigned int)(count), (unsigned int)sizeof(type))
  590. X
  591. X#define REALLOC(ptr, type, count) \
  592. X  (type *)realloc((char *)(ptr), (unsigned int)(sizeof(type) * (count)))
  593. X
  594. X#define REMALLOC(ptr, size) \
  595. X  (char *)realloc((char *)(ptr), (unsigned int)(size))
  596. X
  597. X#define FREE(ptr) \
  598. X  free((char *)(ptr))
  599. X
  600. X/*
  601. X * some small allocation macros
  602. X */
  603. X
  604. X#ifdef __GNUC__
  605. X
  606. X/*
  607. X * duplicate BUF of SIZE bytes
  608. X */
  609. X#define BDUP(buf, size)    ({ \
  610. X              char    *_ret; \
  611. X              int    _size = (size); \
  612. X               \
  613. X              _ret = MALLOC(_size); \
  614. X              if (_ret != NULL) \
  615. X                MEMORY_COPY((buf), _ret, _size); \
  616. X               \
  617. X              _ret; \
  618. X            })
  619. X
  620. X/*
  621. X * the strdup() function in macro form.  duplicate string STR
  622. X */
  623. X#define STRDUP(str)    ({ \
  624. X              const char *_strp = (str); \
  625. X              char    *_ret; \
  626. X              int    _len; \
  627. X               \
  628. X              _len = strlen(_strp); \
  629. X              _ret = MALLOC(_len + 1); \
  630. X              if (_ret != NULL) \
  631. X                MEMORY_COPY(_strp, _ret, _len + 1); \
  632. X               \
  633. X              _ret; \
  634. X            })
  635. X
  636. X#else /* ! __GNUC__ */
  637. X
  638. X/*
  639. X * duplicate BUF of SIZE and return the new address in OUT
  640. X */
  641. X#define BDUP(buf, size, out)    do { \
  642. X                  char    *_ret; \
  643. X                  int    _size = (size); \
  644. X                   \
  645. X                  _ret = MALLOC(_size); \
  646. X                  if (_ret != NULL) \
  647. X                    MEMORY_COPY((buf), _ret, _size); \
  648. X                   \
  649. X                  (out) = _ret; \
  650. X                } while(0)
  651. X
  652. X/*
  653. X * strdup() in macro form.  duplicate string STR and return a copy in OUT
  654. X */
  655. X#define STRDUP(str, out)    do { \
  656. X                  const char *_strp = (str); \
  657. X                  char    *_ret; \
  658. X                  int    _len; \
  659. X                   \
  660. X                  _len = strlen(_strp); \
  661. X                  _ret = MALLOC(_len + 1); \
  662. X                  if (_ret != NULL) \
  663. X                    MEMORY_COPY(_strp, _ret, _len + 1); \
  664. X                   \
  665. X                  (out) = _ret; \
  666. X                } while(0)
  667. X
  668. X#endif /* ! __GNUC__ */
  669. X
  670. X/*<<<<<<<<<<  The below prototypes are auto-generated by fillproto */
  671. X
  672. X/* logfile for dumping malloc info, MALLOC_LOGFILE env. var overrides this */
  673. XIMPORT    char        *malloc_logpath;
  674. X
  675. X/* internal malloc error number for reference purposes only */
  676. XIMPORT    int        malloc_errno;
  677. X
  678. X/*
  679. X * shutdown memory-allocation module, provide statistics if necessary
  680. X */
  681. XIMPORT    void    malloc_shutdown(void);
  682. X
  683. X/*
  684. X * allocate and return a SIZE block of bytes
  685. X */
  686. XIMPORT    char    *malloc(unsigned int size);
  687. X
  688. X/*
  689. X * allocate and return a block of bytes able to hold NUM_ELEMENTS of elements
  690. X * of SIZE bytes and zero the block
  691. X */
  692. XIMPORT    char    *calloc(unsigned int num_elements, unsigned int size);
  693. X
  694. X/*
  695. X * resizes OLD_PNT to SIZE bytes and return the new space after either copying
  696. X * all of OLD_PNT to the new area or truncating
  697. X */
  698. XIMPORT    char    *realloc(char * old_pnt, unsigned int new_size);
  699. X
  700. X/*
  701. X * release PNT in the heap, returning FREE_[NO]ERROR
  702. X */
  703. XIMPORT    int    free(char * pnt);
  704. X
  705. X/*
  706. X * call through to _heap_map function, returns [NO]ERROR
  707. X */
  708. XIMPORT    int    malloc_heap_map(void);
  709. X
  710. X/*
  711. X * verify pointer PNT, if PNT is 0 then check the entire heap.
  712. X * returns MALLOC_VERIFY_[NO]ERROR
  713. X */
  714. XIMPORT    int    malloc_verify(char * pnt);
  715. X
  716. X/*
  717. X * set the global debug functionality flags to DEBUG (0 to disable).
  718. X * returns [NO]ERROR
  719. X */
  720. XIMPORT    int    malloc_debug(int debug);
  721. X
  722. X/*
  723. X * examine pointer PNT and returns SIZE, and FILE / LINE info on it
  724. X * if any of the pointers are not NULL.
  725. X * returns NOERROR or ERROR depending on whether PNT is good or not
  726. X */
  727. XIMPORT    int    malloc_examine(char * pnt, unsigned int * size,
  728. X                   char ** file, unsigned int * line);
  729. X
  730. X/*
  731. X * malloc version of strerror to return the string version of ERRNUM
  732. X * returns the string for MALLOC_BAD_ERRNO if ERRNUM is out-of-range.
  733. X */
  734. XIMPORT    char    *malloc_strerror(int errnum);
  735. X
  736. X/*<<<<<<<<<<   This is end of the auto-generated output from fillproto. */
  737. X
  738. X/*
  739. X * alloc macros to provide for memory FILE/LINE debugging information.
  740. X */
  741. X
  742. X#ifndef MALLOC_DEBUG_DISABLE
  743. X
  744. X#define malloc(size) \
  745. X  _malloc_leap(__FILE__, __LINE__, size)
  746. X#define calloc(count, size) \
  747. X  _calloc_leap(__FILE__, __LINE__, count, size)
  748. X#define realloc(ptr, size) \
  749. X  _realloc_leap(__FILE__, __LINE__, ptr, size)
  750. X#define free(ptr) \
  751. X  _free_leap(__FILE__, __LINE__, ptr)
  752. X
  753. X#ifdef MALLOC_FUNC_CHECK
  754. X
  755. X/*
  756. X * do debugging on the following functions.  this may cause compilation or
  757. X * other problems depending on your architecture, hence the need for the
  758. X * MALLOC_STRING_DISABLE define.
  759. X */
  760. X#define bcmp(b1, b2, len)        _malloc_bcmp(b1, b2, len)
  761. X#define bcopy(from, to, len)        _malloc_bcopy(from, to, len)
  762. X
  763. X#define memcmp(b1, b2, len)        _malloc_memcmp(b1, b2, len)
  764. X#define memcpy(to, from, len)        _malloc_memcpy(to, from, len)
  765. X#define memset(buf, ch, len)        _malloc_memset(buf, ch, len)
  766. X
  767. X#define index(str, ch)            _malloc_index(str, ch)
  768. X#define rindex(str, ch)            _malloc_rindex(str, ch)
  769. X
  770. X#define strcat(to, from)        _malloc_strcat(to, from)
  771. X#define strcmp(s1, s2)            _malloc_strcmp(s1, s2)
  772. X#define strlen(str)            _malloc_strlen(str)
  773. X#define strtok(str, sep)        _malloc_strtok(str, sep)
  774. X
  775. X#define bzero(buf, len)            _malloc_bzero(buf, len)
  776. X
  777. X#define memccpy(s1, s2, ch, len)    _malloc_memccpy(s1, s2, ch, len)
  778. X#define memchr(s1, ch, len)        _malloc_memchr(s1, ch, len)
  779. X
  780. X#define strchr(str, ch)            _malloc_strchr(str, ch)
  781. X#define strrchr(str, ch)        _malloc_strrchr(str, ch)
  782. X
  783. X#define strcpy(to, from)        _malloc_strcpy(to, from)
  784. X#define strncpy(to, from, len)        _malloc_strncpy(to, from, len)
  785. X#define strcasecmp(s1, s2)        _malloc_strcasecmp(s1, s2)
  786. X#define strncasecmp(s1, s2, len)    _malloc_strncasecmp(s1, s2, len)
  787. X#define strspn(str, list)        _malloc_strspn(str, list)
  788. X#define strcspn(str, list)        _malloc_strcspn(str, list)
  789. X#define strncat(to, from, len)        _malloc_strncat(to, from, len)
  790. X#define strncmp(s1, s2, len)        _malloc_strncmp(s1, s2, len)
  791. X#define strpbrk(str, list)        _malloc_strpbrk(str, list)
  792. X#define strstr(str, pat)        _malloc_strstr(str, pat)
  793. X
  794. X/*
  795. X * feel free to add your favorite functions here and to malloc_str.[ch]
  796. X */
  797. X
  798. X#endif /* MALLOC_FUNC_CHECK */
  799. X
  800. X/*
  801. X * copied directly from malloc_lp.h
  802. X */
  803. X
  804. X/* to inform the malloc-debug library from which file the call comes from */
  805. XIMPORT    char        *_malloc_file;
  806. X
  807. X/* to inform the library from which line-number the call comes from */
  808. XIMPORT    unsigned int    _malloc_line;
  809. X
  810. X/*
  811. X * leap routine to calloc
  812. X */
  813. XIMPORT    char    *_calloc_leap(const char * file, const int line,
  814. X                  unsigned int elen, unsigned int size);
  815. X
  816. X/*
  817. X * leap routine to free
  818. X */
  819. XIMPORT    int    _free_leap(const char * file, const int line, char * pnt);
  820. X
  821. X/*
  822. X * leap routine to malloc
  823. X */
  824. XIMPORT    char    *_malloc_leap(const char * file, const int line,
  825. X                  unsigned int size);
  826. X
  827. X/*
  828. X * leap routine to realloc
  829. X */
  830. XIMPORT    char    *_realloc_leap(const char * file, const int line, char * oldp,
  831. X                   unsigned int new_size);
  832. X
  833. X#endif /* MALLOC_DEBUG_DISABLE */
  834. X
  835. X#endif /* ! __MALLOC_H__ */
  836. END_OF_FILE
  837. if test 9046 -ne `wc -c <'malloc.h'`; then
  838.     echo shar: \"'malloc.h'\" unpacked with wrong size!
  839. fi
  840. # end of 'malloc.h'
  841. fi
  842. if test -f 'malloc_dbg.c' -a "${1}" != "-c" ; then 
  843.   echo shar: Will not clobber existing file \"'malloc_dbg.c'\"
  844. else
  845. echo shar: Extracting \"'malloc_dbg.c'\" \(13170 characters\)
  846. sed "s/^X//" >'malloc_dbg.c' <<'END_OF_FILE'
  847. X/*
  848. X * program that handles the malloc debug variables.
  849. X *
  850. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  851. X *
  852. X * This file is part of the malloc-debug package.
  853. X *
  854. X * This library is free software; you can redistribute it and/or
  855. X * modify it under the terms of the GNU Library General Public
  856. X * License as published by the Free Software Foundation; either
  857. X * version 2 of the License, or (at your option) any later version.
  858. X *
  859. X * This library is distributed in the hope that it will be useful,
  860. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  861. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  862. X * Library General Public License for more details.
  863. X *
  864. X * You should have received a copy of the GNU Library General Public
  865. X * License along with this library (see COPYING-LIB); if not, write to the
  866. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  867. X *
  868. X * The author of the program may be contacted at gray.watson@antaire.com
  869. X */
  870. X
  871. X/*
  872. X * This is the malloc_dbg program which is designed to enable the user
  873. X * to easily enable the multitude of malloc-debug capabilities.
  874. X *
  875. X * NOTE: all stdout output from this program is designed to be run through
  876. X *   eval by default.  Any messages for the user should be fprintf to stderr.
  877. X */
  878. X
  879. X#include <stdarg.h>                /* for vsprintf handling */
  880. X#include <stdio.h>                /* for stderr */
  881. X
  882. X#define MALLOC_DEBUG_DISABLE
  883. X
  884. X#include "malloc.h"
  885. X#include "malloc_loc.h"
  886. X
  887. X#include "compat.h"
  888. X#include "conf.h"
  889. X#include "dbg_tokens.h"
  890. X#include "version.h"
  891. X
  892. X#if INCLUDE_RCS_IDS
  893. XLOCAL    char    *rcs_id =
  894. X  "$Id: malloc_dbg.c,v 1.6 1993/04/06 04:24:39 gray Exp $";
  895. X#endif
  896. X
  897. X#define HOME_ENVIRON    "HOME"            /* home directory */
  898. X#define DEFAULT_CONFIG    "%s/.mallocrc"        /* default config file */
  899. X#define TOKENIZE_CHARS    " \t,="            /* for tag lines */
  900. X
  901. X#define USAGE_STRING    "--usage"        /* show the usage message */
  902. X#define VERSION_STRING    "--version"        /* show the version message */
  903. X#define NO_VALUE    (-1)            /* no value ... value */
  904. X
  905. X/* local variables */
  906. XLOCAL    char    printed        = FALSE;    /* did we outputed anything? */
  907. XLOCAL    char    *program    = NULL;        /* our program name */
  908. X
  909. X/* argument variables */
  910. XLOCAL    char    *address    = NULL;        /* for ADDRESS */
  911. XLOCAL    char    bourne        = FALSE;    /* set bourne shell output */
  912. XLOCAL    char    clear        = FALSE;    /* clear variables */
  913. XLOCAL    int    debug        = NO_VALUE;    /* for DEBUG */
  914. XLOCAL    int    errno_to_print    = NO_VALUE;    /* to print the error string */
  915. XLOCAL    char    *inpath        = NULL;        /* for config-file path */
  916. XLOCAL    int    interval    = NO_VALUE;    /* for setting INTERVAL */
  917. XLOCAL    char    *logpath    = NULL;        /* for LOGFILE setting */
  918. XLOCAL    char    *start        = NULL;        /* for START settings */
  919. XLOCAL    char    *tag        = NULL;        /* the debug tag */
  920. X
  921. X/*
  922. X * hexadecimal STR to long translation
  923. X */
  924. XLOCAL    int    hex_to_int(char * str)
  925. X{
  926. X  int        ret;
  927. X  
  928. X  /* strip off spaces */
  929. X  for (; *str == ' ' || *str == '\t'; str++);
  930. X  
  931. X  /* skip a leading 0[xX] */
  932. X  if (*str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X'))
  933. X    str += 2;
  934. X  
  935. X  for (ret = 0;; str++) {
  936. X    if (*str >= '0' && *str <= '9')
  937. X      ret = ret * 16 + (*str - '0');
  938. X    else if (*str >= 'a' && *str <= 'f')
  939. X      ret = ret * 16 + (*str - 'a' + 10);
  940. X    else if (*str >= 'A' && *str <= 'F')
  941. X      ret = ret * 16 + (*str - 'A' + 10);
  942. X    else
  943. X      break;
  944. X  }
  945. X  
  946. X  return ret;
  947. X}
  948. X
  949. X/*
  950. X * print a usage message for the program.
  951. X */
  952. XLOCAL    void    usage(void)
  953. X{
  954. X  (void)fprintf(stderr,    "Usage: %s\n", program);
  955. X  (void)fprintf(stderr,    "  [-a address:#]    = stop when malloc sees address "
  956. X        "[for #th time] %%s\n");
  957. X  (void)fprintf(stderr,    "  [-b]              = set the output for bourne "
  958. X        "shells (sh, ksh) %%t\n");
  959. X  (void)fprintf(stderr,    "  [-c]              = clear all variables not "
  960. X        "specified %%t\n");
  961. X  (void)fprintf(stderr,    "  [-d bitmask]      = hex flag to directly set debug "
  962. X        "mask %%x\n");
  963. X  (void)fprintf(stderr,    "  [-e errno]        = print the error string for "
  964. X        "errno %%d\n");
  965. X  (void)fprintf(stderr,    "  [-f file]         = config file to read from when "
  966. X        "not ~/.mallocrc %%s\n");
  967. X  (void)fprintf(stderr, "  [-i number]       = check heap every number times "
  968. X        "%%d\n");
  969. X  (void)fprintf(stderr,    "  [-l file]         = file to log messages to %%s\n");
  970. X  (void)fprintf(stderr, "  [-s file:line]    = start checking heap after "
  971. X        "seeing file [and line] %%s\n");
  972. X  (void)fprintf(stderr, "  [tag]             = debug token to find in mallocrc"
  973. X        "\n");
  974. X  (void)fprintf(stderr, "if no arguments are specified then it dumps the "
  975. X        "current env setings.\n");
  976. X}
  977. X
  978. X/*
  979. X * process the command-line arguments
  980. X * I've got a great library to do this automatically.  sigh.
  981. X */
  982. XLOCAL    void    process_arguments(int argc, char ** argv)
  983. X{
  984. X  program = rindex(*argv, '/');
  985. X  if (program == NULL)
  986. X    program = *argv;
  987. X  else
  988. X    program++;
  989. X  
  990. X  argc--, argv++;
  991. X  
  992. X  for (; argc > 0; argc--, argv++) {
  993. X    
  994. X    /* special usage message */
  995. X    if (strcmp(*argv, USAGE_STRING) == 0) {
  996. X      usage();
  997. X      exit(0);
  998. X    }
  999. X    
  1000. X    /* special version message */
  1001. X    if (strcmp(*argv, VERSION_STRING) == 0) {
  1002. X      (void)fprintf(stderr, "Version '%s'\n", malloc_version);
  1003. X      exit(0);
  1004. X    }
  1005. X    
  1006. X    /* if no - then assume it is the tag */
  1007. X    if (**argv != '-') {
  1008. X      if (tag != NULL) {
  1009. X    (void)fprintf(stderr,
  1010. X              "Usage problem: debug-tag was already specified\n");
  1011. X    usage();
  1012. X    exit(1);
  1013. X      }
  1014. X      tag = *argv;
  1015. X      continue;
  1016. X    }
  1017. X    
  1018. X    /* can only handle -a not -ab */
  1019. X    if ((*argv)[1] == NULLC || (*argv)[2] != NULLC) {
  1020. X      (void)fprintf(stderr, "Usage problem: incorrect argument format '%s'\n",
  1021. X            *argv);
  1022. X      usage();
  1023. X      exit(1);
  1024. X    }
  1025. X    
  1026. X    switch ((*argv)[1]) {
  1027. X      
  1028. X    case 'a':
  1029. X      argc--, argv++;
  1030. X      if (argc == 0) {
  1031. X    (void)fprintf(stderr, "Usage problem: missing argument to -a\n");
  1032. X    usage();
  1033. X    exit(1);
  1034. X      }
  1035. X      address = *argv;
  1036. X      break;
  1037. X      
  1038. X    case 'b':
  1039. X      bourne = TRUE;
  1040. X      break;
  1041. X      
  1042. X    case 'c':
  1043. X      clear = TRUE;
  1044. X      break;
  1045. X      
  1046. X    case 'd':
  1047. X      argc--, argv++;
  1048. X      if (argc == 0) {
  1049. X    (void)fprintf(stderr, "Usage problem: missing argument to -d\n");
  1050. X    usage();
  1051. X    exit(1);
  1052. X      }
  1053. X      debug = hex_to_int(*argv);
  1054. X      break;
  1055. X      
  1056. X    case 'e':
  1057. X      argc--, argv++;
  1058. X      if (argc == 0) {
  1059. X    (void)fprintf(stderr, "Usage problem: missing argument to -e\n");
  1060. X    usage();
  1061. X    exit(1);
  1062. X      }
  1063. X      errno_to_print = atoi(*argv);
  1064. X      break;
  1065. X      
  1066. X    case 'f':
  1067. X      argc--, argv++;
  1068. X      if (argc == 0) {
  1069. X    (void)fprintf(stderr, "Usage problem: missing argument to -f\n");
  1070. X    usage();
  1071. X    exit(1);
  1072. X      }
  1073. X      inpath = *argv;
  1074. X      break;
  1075. X      
  1076. X    case 'i':
  1077. X      argc--, argv++;
  1078. X      if (argc == 0) {
  1079. X    (void)fprintf(stderr, "Usage problem: missing argument to -i\n");
  1080. X    usage();
  1081. X    exit(1);
  1082. X      }
  1083. X      interval = atoi(*argv);
  1084. X      break;
  1085. X      
  1086. X    case 'l':
  1087. X      argc--, argv++;
  1088. X      if (argc == 0) {
  1089. X    (void)fprintf(stderr, "Usage problem: missing argument to -l\n");
  1090. X    usage();
  1091. X    exit(1);
  1092. X      }
  1093. X      logpath = *argv;
  1094. X      break;
  1095. X      
  1096. X    case 's':
  1097. X      argc--, argv++;
  1098. X      if (argc == 0) {
  1099. X    (void)fprintf(stderr, "Usage problem: missing argument to -s\n");
  1100. X    usage();
  1101. X    exit(1);
  1102. X      }
  1103. X      start = *argv;
  1104. X      break;
  1105. X      
  1106. X    default:
  1107. X      (void)fprintf(stderr, "Usage problem: unknown argument '%s'\n", *argv);
  1108. X      usage();
  1109. X      exit(1);
  1110. X      break;
  1111. X    }
  1112. X  }
  1113. X}
  1114. X
  1115. X/*
  1116. X * process the user configuration looking for the tag.  if tag is null then
  1117. X * look for DEBUG_VALUE in the file and return the token for it in STR.
  1118. X * routine returns the new debug value matching tag.
  1119. X */
  1120. XLOCAL    int    process(int debug_value, char ** strp)
  1121. X{
  1122. X  static char    token[128];
  1123. X  FILE        *infile = NULL;
  1124. X  char        path[1024], buf[1024], *homep;
  1125. X  char        found, cont;
  1126. X  int        new_debug = 0;
  1127. X  
  1128. X  /* do we need to have a home variable? */
  1129. X  if (inpath == NULL) {
  1130. X    homep = (char *)getenv(HOME_ENVIRON);
  1131. X    if (homep == NULL) {
  1132. X      (void)fprintf(stderr, "%s: could not find variable '%s'\n",
  1133. X            program, HOME_ENVIRON);
  1134. X      exit(1);
  1135. X    }
  1136. X    
  1137. X    (void)sprintf(path, DEFAULT_CONFIG, homep);
  1138. X    inpath = path;
  1139. X  }
  1140. X  
  1141. X  infile = fopen(inpath, "r");
  1142. X  if (infile == NULL) {
  1143. X    (void)fprintf(stderr, "%s: could not read '%s': ", program, inpath);
  1144. X    (void)perror("");
  1145. X    exit(1);
  1146. X  }
  1147. X  
  1148. X  /* read each of the lines looking for the tag */
  1149. X  found = FALSE;
  1150. X  cont = FALSE;
  1151. X  
  1152. X  while (fgets(buf, sizeof(buf), infile) != NULL) {
  1153. X    int        attrc;
  1154. X    char    *tokp, *endp;
  1155. X    
  1156. X    /* ignore comments and empty lines */
  1157. X    if (buf[0] == '#' || buf[0] == '\n')
  1158. X      continue;
  1159. X    
  1160. X    /* chop off the ending \n */
  1161. X    endp = rindex(buf, '\n');
  1162. X    if (endp != NULL)
  1163. X      *endp = NULLC;
  1164. X    
  1165. X    tokp = strtok(buf, TOKENIZE_CHARS);
  1166. X    
  1167. X    /* if we're not continuing then we need to process a tag */
  1168. X    if (! cont) {
  1169. X      (void)strcpy(token, tokp);
  1170. X      new_debug = 0;
  1171. X      
  1172. X      if (tag != NULL && strcmp(tag, tokp) == 0)
  1173. X    found = TRUE;
  1174. X      
  1175. X      tokp = strtok(NULL, TOKENIZE_CHARS);
  1176. X    }
  1177. X    
  1178. X    cont = FALSE;
  1179. X    
  1180. X    do {
  1181. X      /* do we have a continuation character */
  1182. X      if (strcmp(tokp, "\\") == 0) {
  1183. X    cont = TRUE;
  1184. X    break;
  1185. X      }
  1186. X      
  1187. X      /* are we processing the tag of choice? */
  1188. X      if (found || tag == NULL) {
  1189. X    for (attrc = 0; attributes[attrc].at_string != NULL; attrc++) {
  1190. X      if (strcmp(tokp, attributes[attrc].at_string) == 0)
  1191. X        break;
  1192. X    }
  1193. X    
  1194. X    if (attributes[attrc].at_string == NULL) {
  1195. X      (void)fprintf(stderr, "%s: unknown token '%s'\n",
  1196. X            program, tokp);
  1197. X    }
  1198. X    else
  1199. X      new_debug |= attributes[attrc].at_value;
  1200. X      }
  1201. X      
  1202. X      tokp = strtok(NULL, TOKENIZE_CHARS);
  1203. X    } while (tokp != NULL);
  1204. X    
  1205. X    if (tag == NULL && ! cont && new_debug == debug_value) {
  1206. X      found = TRUE;
  1207. X      if (strp != NULL)
  1208. X    *strp = token;
  1209. X      break;
  1210. X    }
  1211. X    
  1212. X    /* are we done? */
  1213. X    if (found && ! cont)
  1214. X      break;
  1215. X  }
  1216. X  
  1217. X  (void)fclose(infile);
  1218. X  
  1219. X  /* did we find the correct value in the file? */
  1220. X  if (tag == NULL && ! found) {
  1221. X    if (strp != NULL)
  1222. X      *strp = "unknown";
  1223. X  }
  1224. X  else if (! found && tag != NULL) {
  1225. X    (void)fprintf(stderr, "%s: could not find tag '%s' in '%s'\n",
  1226. X          program, tag, inpath);
  1227. X    exit(1);
  1228. X  }
  1229. X  
  1230. X  return new_debug;
  1231. X}
  1232. X
  1233. X/*
  1234. X * dump the current settings of the malloc variables
  1235. X */
  1236. XLOCAL    void    dump_current(void)
  1237. X{
  1238. X  char        *str;
  1239. X  int        num;
  1240. X  
  1241. X  str = (char *)getenv(DEBUG_ENVIRON);
  1242. X  if (str == NULL)
  1243. X    (void)fprintf(stderr, "%s not set\n", DEBUG_ENVIRON);
  1244. X  else {
  1245. X    num = hex_to_int(str);
  1246. X    (void)process(num, &str);
  1247. X    (void)fprintf(stderr, "%s == '%#lx' (%s)\n", DEBUG_ENVIRON, num, str);
  1248. X  }
  1249. X  
  1250. X  str = (char *)getenv(ADDRESS_ENVIRON);
  1251. X  if (str == NULL)
  1252. X    (void)fprintf(stderr, "%s not set\n", ADDRESS_ENVIRON);
  1253. X  else
  1254. X    (void)fprintf(stderr, "%s == '%s'\n", ADDRESS_ENVIRON, str);
  1255. X  
  1256. X  str = (char *)getenv(INTERVAL_ENVIRON);
  1257. X  if (str == NULL)
  1258. X    (void)fprintf(stderr, "%s not set\n", INTERVAL_ENVIRON);
  1259. X  else {
  1260. X    num = atoi(str);
  1261. X    (void)fprintf(stderr, "%s == '%d'\n", INTERVAL_ENVIRON, num);
  1262. X  }
  1263. X  
  1264. X  str = (char *)getenv(LOGFILE_ENVIRON);
  1265. X  if (str == NULL)
  1266. X    (void)fprintf(stderr, "%s not set\n", LOGFILE_ENVIRON);
  1267. X  else
  1268. X    (void)fprintf(stderr, "%s == '%s'\n", LOGFILE_ENVIRON, str);
  1269. X  
  1270. X  str = (char *)getenv(START_ENVIRON);
  1271. X  if (str == NULL)
  1272. X    (void)fprintf(stderr, "%s not set\n", START_ENVIRON);
  1273. X  else
  1274. X    (void)fprintf(stderr, "%s == '%s'\n", START_ENVIRON, str);
  1275. X}
  1276. X
  1277. X/*
  1278. X * output the code to set env VAR to VALUE using printf FORMAT
  1279. X */
  1280. XLOCAL    void    set_variable(char * var, char * format, ...)
  1281. X{
  1282. X  char        value[256];
  1283. X  va_list    args;
  1284. X  
  1285. X  /* write the format + info into str */
  1286. X  va_start(args, format);
  1287. X  (void)vsprintf(value, format, args);
  1288. X  va_end(args);
  1289. X  
  1290. X  if (bourne)
  1291. X    (void)printf("%s=%s; export %s;\n", var, value, var);
  1292. X  else
  1293. X    (void)printf("setenv %s %s;\n", var, value);
  1294. X  
  1295. X  printed = TRUE;
  1296. X}
  1297. X
  1298. X/*
  1299. X * output the code to un-set env VAR
  1300. X */
  1301. XLOCAL    void    unset_variable(char * var)
  1302. X{
  1303. X  if (bourne)
  1304. X    (void)printf("unset %s;\n", var);
  1305. X  else
  1306. X    (void)printf("unsetenv %s;\n", var);
  1307. X  
  1308. X  printed = TRUE;
  1309. X}
  1310. X
  1311. XEXPORT    int    main(int argc, char ** argv)
  1312. X{
  1313. X  /* turn off debugging for this program */
  1314. X  (void)malloc_debug(0);
  1315. X  
  1316. X  process_arguments(argc, argv);
  1317. X  
  1318. X  /* get a new debug value from tag */
  1319. X  if (tag != NULL) {
  1320. X    if (debug != NO_VALUE)
  1321. X      (void)fprintf(stderr, "%s: warning -d option ignored, processing tag "
  1322. X            "'%s'\n",
  1323. X            program, tag);
  1324. X    debug = process(0, NULL);
  1325. X  }
  1326. X  
  1327. X  if (tag != NULL || debug != NO_VALUE)
  1328. X    set_variable(DEBUG_ENVIRON, "%#lx", debug);
  1329. X  
  1330. X  if (address != NULL)
  1331. X    set_variable(ADDRESS_ENVIRON, "%s", address);
  1332. X  else if (clear)
  1333. X    unset_variable(ADDRESS_ENVIRON);
  1334. X  
  1335. X  if (interval != NO_VALUE)
  1336. X    set_variable(INTERVAL_ENVIRON, "%d", interval);
  1337. X  else if (clear)
  1338. X    unset_variable(INTERVAL_ENVIRON);
  1339. X  
  1340. X  if (logpath != NULL)
  1341. X    set_variable(LOGFILE_ENVIRON, "%s", logpath);
  1342. X  else if (clear)
  1343. X    unset_variable(LOGFILE_ENVIRON);
  1344. X  
  1345. X  if (start != NULL)
  1346. X    set_variable(START_ENVIRON, "%s", start);
  1347. X  else if (clear)
  1348. X    unset_variable(START_ENVIRON);
  1349. X  
  1350. X  if (errno_to_print != NO_VALUE) {
  1351. X    (void)fprintf(stderr, "%s: malloc_errno value '%d' = \n",
  1352. X          program, errno_to_print);
  1353. X    (void)fprintf(stderr, "   '%s'\n", malloc_strerror(errno_to_print));
  1354. X  }
  1355. X  else if (! printed)
  1356. X    dump_current();
  1357. X  
  1358. X  exit(0);
  1359. X}
  1360. END_OF_FILE
  1361. if test 13170 -ne `wc -c <'malloc_dbg.c'`; then
  1362.     echo shar: \"'malloc_dbg.c'\" unpacked with wrong size!
  1363. fi
  1364. # end of 'malloc_dbg.c'
  1365. fi
  1366. if test -f 'malloc_loc.h' -a "${1}" != "-c" ; then 
  1367.   echo shar: Will not clobber existing file \"'malloc_loc.h'\"
  1368. else
  1369. echo shar: Extracting \"'malloc_loc.h'\" \(2622 characters\)
  1370. sed "s/^X//" >'malloc_loc.h' <<'END_OF_FILE'
  1371. X/*
  1372. X * local definitions for the user allocation level
  1373. X *
  1374. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  1375. X *
  1376. X * This file is part of the malloc-debug package.
  1377. X *
  1378. X * This library is free software; you can redistribute it and/or
  1379. X * modify it under the terms of the GNU Library General Public
  1380. X * License as published by the Free Software Foundation; either
  1381. X * version 2 of the License, or (at your option) any later version.
  1382. X *
  1383. X * This library is distributed in the hope that it will be useful,
  1384. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1385. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  1386. X * Library General Public License for more details.
  1387. X *
  1388. X * You should have received a copy of the GNU Library General Public
  1389. X * License along with this library (see COPYING-LIB); if not, write to the
  1390. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1391. X *
  1392. X * The author of the program may be contacted at gray.watson@antaire.com
  1393. X *
  1394. X * $Id: malloc_loc.h,v 1.15 1993/03/26 09:16:50 gray Exp $
  1395. X */
  1396. X
  1397. X#ifndef __MALLOC_LOC_H__
  1398. X#define __MALLOC_LOC_H__
  1399. X
  1400. X/* fence post checking defines */
  1401. X#define FENCE_BOTTOM        (1 << ALLOCATION_ALIGNMENT_IN_BITS)
  1402. X#define FENCE_TOP        sizeof(long)
  1403. X#define FENCE_OVERHEAD        (FENCE_BOTTOM + FENCE_TOP)
  1404. X#define FENCE_MAGIC_BASE    0xC0C0AB1B
  1405. X#define FENCE_MAGIC_TOP        0xFACADE69
  1406. X
  1407. X/*
  1408. X * env variables
  1409. X */
  1410. X#define ADDRESS_ENVIRON        "MALLOC_ADDRESS"
  1411. X#define DEBUG_ENVIRON        "MALLOC_DEBUG"
  1412. X#define INTERVAL_ENVIRON    "MALLOC_INTERVAL"
  1413. X#define LOGFILE_ENVIRON        "MALLOC_LOGFILE"
  1414. X#define START_ENVIRON        "MALLOC_START"
  1415. X
  1416. X/******************************* useful defines ******************************/
  1417. X
  1418. X/*
  1419. X * standard int return codes
  1420. X */
  1421. X#undef    ERROR
  1422. X#define    ERROR        (-1)
  1423. X
  1424. X#undef    NOERROR
  1425. X#define    NOERROR        0
  1426. X
  1427. X/*
  1428. X * generic constants
  1429. X */
  1430. X#undef    NULL
  1431. X#define NULL        0
  1432. X
  1433. X#undef    NULLC
  1434. X#define NULLC        '\0'
  1435. X
  1436. X#undef    FALSE
  1437. X#define FALSE        0
  1438. X
  1439. X#undef    TRUE
  1440. X#define TRUE        (! FALSE)
  1441. X
  1442. X/*
  1443. X * standard i/o file descriptors
  1444. X */
  1445. X#undef    STDIN
  1446. X#define    STDIN        0        /* fileno(stdin) */
  1447. X
  1448. X#undef    STDOUT
  1449. X#define    STDOUT        1        /* fileno(stdout) */
  1450. X
  1451. X#undef    STDERR
  1452. X#define    STDERR        2        /* fileno(stderr) */
  1453. X
  1454. X/*
  1455. X * min/max macros
  1456. X *
  1457. X * WARNING: these use their arguments multiple times which may be bad
  1458. X */
  1459. X#undef MAX
  1460. X#define MAX(a,b)    (((a) > (b)) ? (a) : (b))
  1461. X#undef MIN
  1462. X#define MIN(a,b)    (((a) < (b)) ? (a) : (b))
  1463. X
  1464. X/*
  1465. X * bitflag tools for Variable and a Flag
  1466. X */
  1467. X#undef BIT_FLAG
  1468. X#define BIT_FLAG(x)        (1 << (x))
  1469. X#undef BIT_SET
  1470. X#define BIT_SET(v,f)        (v) |= (f)
  1471. X#undef BIT_CLEAR
  1472. X#define BIT_CLEAR(v,f)        (v) &= ~(f)
  1473. X#undef BIT_IS_SET
  1474. X#define BIT_IS_SET(v,f)        ((v) & (f))
  1475. X
  1476. X#endif /* ! __MALLOC_LOC_H__ */
  1477. END_OF_FILE
  1478. if test 2622 -ne `wc -c <'malloc_loc.h'`; then
  1479.     echo shar: \"'malloc_loc.h'\" unpacked with wrong size!
  1480. fi
  1481. # end of 'malloc_loc.h'
  1482. fi
  1483. if test -f 'malloc_lp.c' -a "${1}" != "-c" ; then 
  1484.   echo shar: Will not clobber existing file \"'malloc_lp.c'\"
  1485. else
  1486. echo shar: Extracting \"'malloc_lp.c'\" \(4059 characters\)
  1487. sed "s/^X//" >'malloc_lp.c' <<'END_OF_FILE'
  1488. X/*
  1489. X * leap-frog point to allow malloc-debug on/off via relink.
  1490. X *
  1491. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  1492. X *
  1493. X * This file is part of the malloc-debug package.
  1494. X *
  1495. X * This library is free software; you can redistribute it and/or
  1496. X * modify it under the terms of the GNU Library General Public
  1497. X * License as published by the Free Software Foundation; either
  1498. X * version 2 of the License, or (at your option) any later version.
  1499. X *
  1500. X * This library is distributed in the hope that it will be useful,
  1501. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1502. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  1503. X * Library General Public License for more details.
  1504. X *
  1505. X * You should have received a copy of the GNU Library General Public
  1506. X * License along with this library (see COPYING-LIB); if not, write to the
  1507. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1508. X *
  1509. X * The author of the program may be contacted at gray.watson@antaire.com
  1510. X */
  1511. X
  1512. X/*
  1513. X * If anyone can think of a better way to do this *please* let me know.
  1514. X *
  1515. X * The goal is to allow people to use the debug library during development
  1516. X * and then disable and return to the system (or more efficient) malloc
  1517. X * functions by just relinking with another library.
  1518. X *
  1519. X * The problem is that we want to provide the library with file/line
  1520. X * information with each call.  Backtracing the stack-frame is neither
  1521. X * portable or necessarily easy so the cpp __FILE__ and __LINE__ directives
  1522. X * are used instead.  But how to pass this information to the library is
  1523. X * the challange.  How can we do this in a graceful and sane manner while
  1524. X * still providing the "quick-release" functionality above?
  1525. X *
  1526. X * I have decided on this leap-frog file that will have to *always* be
  1527. X * compiled in.  It will have the special _malloc_file and _malloc_line
  1528. X * variables and will set them whether malloc-debug routines are linked
  1529. X * in to use them or not.
  1530. X *
  1531. X * This *will* mean an extra function call per memory interaction but on
  1532. X * most systems this is pretty cheap.  It will also mean that this file
  1533. X * needs to be compiled into your programs whether or not they use the
  1534. X * debug library unless you want to recompile all .c files with
  1535. X * -DMALLOC_DEBUG_DISABLE.
  1536. X *
  1537. X * Please mail me with any reasonable ideas.
  1538. X */
  1539. X
  1540. X#define MALLOC_DEBUG_DISABLE
  1541. X
  1542. X#include "malloc.h"
  1543. X
  1544. X#if INCLUDE_RCS_IDS
  1545. Xstatic    char    *rcs_id =
  1546. X  "$Id: malloc_lp.c,v 1.5 1993/04/01 04:59:25 gray Exp $";
  1547. X#endif
  1548. X
  1549. X/*
  1550. X * exported variables
  1551. X */
  1552. X/* to inform the malloc-debug library from which file the call comes from */
  1553. XEXPORT    char        *_malloc_file = MALLOC_DEFAULT_FILE;
  1554. X
  1555. X/* to inform the library from which line-number the call comes from */
  1556. XEXPORT    unsigned int    _malloc_line = MALLOC_DEFAULT_LINE;
  1557. X
  1558. X/*
  1559. X * leap routine to calloc
  1560. X */
  1561. XEXPORT    char    *_calloc_leap(const char * file, const int line,
  1562. X                  unsigned int elen, unsigned int size)
  1563. X{
  1564. X  char    *ret;
  1565. X  
  1566. X  _malloc_file = (char *)file;
  1567. X  _malloc_line = line;
  1568. X  
  1569. X  ret = calloc(elen, size);
  1570. X  
  1571. X  _malloc_file = MALLOC_DEFAULT_FILE;
  1572. X  _malloc_line = MALLOC_DEFAULT_LINE;
  1573. X  
  1574. X  return ret;
  1575. X}
  1576. X
  1577. X/*
  1578. X * leap routine to free
  1579. X */
  1580. XEXPORT    int    _free_leap(const char * file, const int line, char * pnt)
  1581. X{
  1582. X  int    ret;
  1583. X  
  1584. X  _malloc_file = (char *)file;
  1585. X  _malloc_line = line;
  1586. X  
  1587. X  ret = free(pnt);
  1588. X  
  1589. X  _malloc_file = MALLOC_DEFAULT_FILE;
  1590. X  _malloc_line = MALLOC_DEFAULT_LINE;
  1591. X  
  1592. X  return ret;
  1593. X}
  1594. X
  1595. X/*
  1596. X * leap routine to malloc
  1597. X */
  1598. XEXPORT    char    *_malloc_leap(const char * file, const int line,
  1599. X                  unsigned int size)
  1600. X{
  1601. X  char    *ret;
  1602. X  
  1603. X  _malloc_file = (char *)file;
  1604. X  _malloc_line = line;
  1605. X  
  1606. X  ret = malloc(size);
  1607. X  
  1608. X  _malloc_file = MALLOC_DEFAULT_FILE;
  1609. X  _malloc_line = MALLOC_DEFAULT_LINE;
  1610. X  
  1611. X  return ret;
  1612. X}
  1613. X
  1614. X/*
  1615. X * leap routine to realloc
  1616. X */
  1617. XEXPORT    char    *_realloc_leap(const char * file, const int line, char * oldp,
  1618. X                   unsigned int new_size)
  1619. X{
  1620. X  char    *ret;
  1621. X  
  1622. X  _malloc_file = (char *)file;
  1623. X  _malloc_line = line;
  1624. X  
  1625. X  ret = realloc(oldp, new_size);
  1626. X  
  1627. X  _malloc_file = MALLOC_DEFAULT_FILE;
  1628. X  _malloc_line = MALLOC_DEFAULT_LINE;
  1629. X  
  1630. X  return ret;
  1631. X}
  1632. END_OF_FILE
  1633. if test 4059 -ne `wc -c <'malloc_lp.c'`; then
  1634.     echo shar: \"'malloc_lp.c'\" unpacked with wrong size!
  1635. fi
  1636. # end of 'malloc_lp.c'
  1637. fi
  1638. if test -f 'malloc_lp.h' -a "${1}" != "-c" ; then 
  1639.   echo shar: Will not clobber existing file \"'malloc_lp.h'\"
  1640. else
  1641. echo shar: Extracting \"'malloc_lp.h'\" \(2034 characters\)
  1642. sed "s/^X//" >'malloc_lp.h' <<'END_OF_FILE'
  1643. X/*
  1644. X * defines for the malloc-leap routines.
  1645. X *
  1646. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  1647. X *
  1648. X * This file is part of the malloc-debug package.
  1649. X *
  1650. X * This library is free software; you can redistribute it and/or
  1651. X * modify it under the terms of the GNU Library General Public
  1652. X * License as published by the Free Software Foundation; either
  1653. X * version 2 of the License, or (at your option) any later version.
  1654. X *
  1655. X * This library is distributed in the hope that it will be useful,
  1656. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1657. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  1658. X * Library General Public License for more details.
  1659. X *
  1660. X * You should have received a copy of the GNU Library General Public
  1661. X * License along with this library (see COPYING-LIB); if not, write to the
  1662. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1663. X *
  1664. X * The author of the program may be contacted at gray.watson@antaire.com
  1665. X *
  1666. X * $Id: malloc_lp.h,v 1.3 1993/03/26 09:16:54 gray Exp $
  1667. X */
  1668. X
  1669. X#ifndef __MALLOC_LP_H__
  1670. X#define __MALLOC_LP_H__
  1671. X
  1672. X#undef    IMPORT
  1673. X#define    IMPORT        extern
  1674. X
  1675. X/*<<<<<<<<<<  The below prototypes are auto-generated by fillproto */
  1676. X
  1677. X/* to inform the malloc-debug library from which file the call comes from */
  1678. XIMPORT    char        *_malloc_file;
  1679. X
  1680. X/* to inform the library from which line-number the call comes from */
  1681. XIMPORT    unsigned int    _malloc_line;
  1682. X
  1683. X/*
  1684. X * leap routine to calloc
  1685. X */
  1686. XIMPORT    char    *_calloc_leap(const char * file, const int line,
  1687. X                  unsigned int elen, unsigned int size);
  1688. X
  1689. X/*
  1690. X * leap routine to free
  1691. X */
  1692. XIMPORT    int    _free_leap(const char * file, const int line, char * pnt);
  1693. X
  1694. X/*
  1695. X * leap routine to malloc
  1696. X */
  1697. XIMPORT    char    *_malloc_leap(const char * file, const int line,
  1698. X                  unsigned int size);
  1699. X
  1700. X/*
  1701. X * leap routine to realloc
  1702. X */
  1703. XIMPORT    char    *_realloc_leap(const char * file, const int line, char * oldp,
  1704. X                   unsigned int new_size);
  1705. X
  1706. X/*<<<<<<<<<<   This is end of the auto-generated output from fillproto. */
  1707. X
  1708. X#endif /* ! __MALLOC_LP_H__ */
  1709. END_OF_FILE
  1710. if test 2034 -ne `wc -c <'malloc_lp.h'`; then
  1711.     echo shar: \"'malloc_lp.h'\" unpacked with wrong size!
  1712. fi
  1713. # end of 'malloc_lp.h'
  1714. fi
  1715. if test -f 'malloc_str.c' -a "${1}" != "-c" ; then 
  1716.   echo shar: Will not clobber existing file \"'malloc_str.c'\"
  1717. else
  1718. echo shar: Extracting \"'malloc_str.c'\" \(13374 characters\)
  1719. sed "s/^X//" >'malloc_str.c' <<'END_OF_FILE'
  1720. X/*
  1721. X * functions for testing of string routines arguments.
  1722. X *
  1723. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  1724. X *
  1725. X * This file is part of the malloc-debug package.
  1726. X *
  1727. X * This library is free software; you can redistribute it and/or
  1728. X * modify it under the terms of the GNU Library General Public
  1729. X * License as published by the Free Software Foundation; either
  1730. X * version 2 of the License, or (at your option) any later version.
  1731. X *
  1732. X * This library is distributed in the hope that it will be useful,
  1733. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1734. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  1735. X * Library General Public License for more details.
  1736. X *
  1737. X * You should have received a copy of the GNU Library General Public
  1738. X * License along with this library (see COPYING-LIB); if not, write to the
  1739. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1740. X *
  1741. X * The author of the program may be contacted at gray.watson@antaire.com
  1742. X */
  1743. X
  1744. X/*
  1745. X * This file contains functions to be used to verify the arguments of
  1746. X * string functions.   If enabled these can discover problems with
  1747. X * heap-based strings (such as fence errors) much closer to the error.
  1748. X */
  1749. X
  1750. X#define MALLOC_DEBUG_DISABLE
  1751. X
  1752. X#include "malloc.h"
  1753. X#include "malloc_loc.h"
  1754. X
  1755. X#include "conf.h"
  1756. X#include "chunk.h"
  1757. X#include "dbg_values.h"
  1758. X#include "error.h"
  1759. X#include "malloc_str.h"
  1760. X
  1761. X#if INCLUDE_RCS_IDS
  1762. XLOCAL    char    *rcs_id =
  1763. X  "$Id: malloc_str.c,v 1.3 1993/04/06 04:24:41 gray Exp $";
  1764. X#endif
  1765. X
  1766. X#if HAVE_BCMP
  1767. X/*
  1768. X * dummy function for checking bcmp's arguments.
  1769. X */
  1770. XEXPORT    int    _malloc_bcmp(void * b1, void * b2, int len)
  1771. X{
  1772. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1773. X    if (_chunk_pnt_check("bcmp", b1, 1, len) != NOERROR
  1774. X    || _chunk_pnt_check("bcmp", b2, 1, len) != NOERROR)
  1775. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1776. X    _malloc_message("bad pointer argument found in bcmp");
  1777. X  }
  1778. X  return bcmp(b1, b2, len);
  1779. X}
  1780. X#endif
  1781. X
  1782. X#if HAVE_BCOPY
  1783. X/*
  1784. X * dummy function for checking bcopy's arguments.
  1785. X */
  1786. XEXPORT    void    _malloc_bcopy(char * from, char * to, int len)
  1787. X{
  1788. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1789. X    if (_chunk_pnt_check("bcopy", from, 1, len) != NOERROR
  1790. X    || _chunk_pnt_check("bcopy", to, 1, len) != NOERROR)
  1791. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1792. X    _malloc_message("bad pointer argument found in bcopy");
  1793. X  }
  1794. X  bcopy(from, to, len);
  1795. X}
  1796. X#endif
  1797. X
  1798. X#if HAVE_MEMCMP
  1799. X/*
  1800. X * dummy function for checking memcmp's arguments.
  1801. X */
  1802. XEXPORT    int    _malloc_memcmp(void * b1,
  1803. X                   void * b2, int len)
  1804. X{
  1805. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1806. X    if (_chunk_pnt_check("memcmp", b1, 1, len) != NOERROR
  1807. X    || _chunk_pnt_check("memcmp", b2, 1, len) != NOERROR)
  1808. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1809. X    _malloc_message("bad pointer argument found in memcmp");
  1810. X  }
  1811. X  return memcmp(b1, b2, len);
  1812. X}
  1813. X#endif
  1814. X
  1815. X#if HAVE_MEMCPY
  1816. X/*
  1817. X * dummy function for checking memcpy's arguments.
  1818. X */
  1819. XEXPORT    char    *_malloc_memcpy(char * to, char * from, int len)
  1820. X{
  1821. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1822. X    if (_chunk_pnt_check("memcpy", to, 1, len) != NOERROR
  1823. X    || _chunk_pnt_check("memcpy", from, 1, len) != NOERROR)
  1824. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1825. X    _malloc_message("bad pointer argument found in memcpy");
  1826. X  }
  1827. X  return (char *)memcpy(to, from, len);
  1828. X}
  1829. X#endif
  1830. X
  1831. X#if HAVE_MEMSET
  1832. X/*
  1833. X * dummy function for checking memset's arguments.
  1834. X */
  1835. XEXPORT    char    *_malloc_memset(void * buf, char ch, int len)
  1836. X{
  1837. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1838. X    if (_chunk_pnt_check("memset", buf, 1, len) != NOERROR)
  1839. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1840. X    _malloc_message("bad pointer argument found in memset");
  1841. X  }
  1842. X  return (char *)memset(buf, ch, len);
  1843. X}
  1844. X#endif
  1845. X
  1846. X#if HAVE_INDEX
  1847. X/*
  1848. X * dummy function for checking index's arguments.
  1849. X */
  1850. XEXPORT    char    *_malloc_index(char * str, char ch)
  1851. X{
  1852. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1853. X    if (_chunk_pnt_check("index", str, 1, 0) != NOERROR)
  1854. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1855. X    _malloc_message("bad pointer argument found in index");
  1856. X  }
  1857. X  return (char *)index(str, ch);
  1858. X}
  1859. X#endif
  1860. X
  1861. X#if HAVE_RINDEX
  1862. X/*
  1863. X * dummy function for checking rindex's arguments.
  1864. X */
  1865. XEXPORT    char    *_malloc_rindex(char * str, char ch)
  1866. X{
  1867. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1868. X    if (_chunk_pnt_check("rindex", str, 1, 0) != NOERROR)
  1869. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1870. X    _malloc_message("bad pointer argument found in rindex");
  1871. X  }
  1872. X  return (char *)rindex(str, ch);
  1873. X}
  1874. X#endif
  1875. X
  1876. X#if HAVE_STRCAT
  1877. X/*
  1878. X * dummy function for checking strcat's arguments.
  1879. X */
  1880. XEXPORT    char    *_malloc_strcat(char * to, char * from)
  1881. X{
  1882. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1883. X    /* maybe should check to, strlen(to) + strlen(from) */
  1884. X    if (_chunk_pnt_check("strcat", to, 1, 0) != NOERROR
  1885. X    || _chunk_pnt_check("strcat", from, 1, 0) != NOERROR)
  1886. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1887. X    _malloc_message("bad pointer argument found in strcat");
  1888. X  }
  1889. X  return (char *)strcat(to, from);
  1890. X}
  1891. X#endif
  1892. X
  1893. X#if HAVE_STRCMP
  1894. X/*
  1895. X * dummy function for checking strcmp's arguments.
  1896. X */
  1897. XEXPORT    int    _malloc_strcmp(char * s1,
  1898. X                   char * s2)
  1899. X{
  1900. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1901. X    if (_chunk_pnt_check("strcmp", s1, 1, 0) != NOERROR
  1902. X    || _chunk_pnt_check("strcmp", s2, 1, 0) != NOERROR)
  1903. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1904. X    _malloc_message("bad pointer argument found in strcmp");
  1905. X  }
  1906. X  return strcmp(s1, s2);
  1907. X}
  1908. X#endif
  1909. X
  1910. X#if HAVE_STRLEN
  1911. X/*
  1912. X * dummy function for checking strlen's arguments.
  1913. X */
  1914. XEXPORT    int    _malloc_strlen(char * str)
  1915. X{
  1916. X  if (BIT_IS_SET(_malloc_debug,
  1917. X         DEBUG_CHECK_FUNCS)) {
  1918. X    if (_chunk_pnt_check("strlen", str, 1, 0) != NOERROR)
  1919. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1920. X    _malloc_message("bad pointer argument found in strlen");
  1921. X  }
  1922. X  return strlen(str);
  1923. X}
  1924. X#endif
  1925. X
  1926. X#if HAVE_STRTOK
  1927. X/*
  1928. X * dummy function for checking strtok's arguments.
  1929. X */
  1930. XEXPORT    char    *_malloc_strtok(char * str, char * sep)
  1931. X{
  1932. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1933. X    if (_chunk_pnt_check("strtok", str, 1, 0) != NOERROR
  1934. X    || _chunk_pnt_check("strtok", sep, 1, 0) != NOERROR)
  1935. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1936. X    _malloc_message("bad pointer argument found in strtok");
  1937. X  }
  1938. X  return (char *)strtok(str, sep);
  1939. X}
  1940. X#endif
  1941. X
  1942. X#if HAVE_BZERO
  1943. X/*
  1944. X * dummy function for checking bzero's arguments.
  1945. X */
  1946. XEXPORT    void    _malloc_bzero(void * buf,
  1947. X                  int len)
  1948. X{
  1949. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1950. X    if (_chunk_pnt_check("bzero", buf, 1, len) != NOERROR)
  1951. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1952. X    _malloc_message("bad pointer argument found in bzero");
  1953. X  }
  1954. X  bzero(buf, len);
  1955. X}
  1956. X#endif
  1957. X
  1958. X#if HAVE_MEMCCPY
  1959. X/*
  1960. X * dummy function for checking memccpy's arguments.
  1961. X */
  1962. XEXPORT    char    *_malloc_memccpy(char * s1, char * s2, char ch, int len)
  1963. X{
  1964. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1965. X    /* maybe len maybe first ch */
  1966. X    if (_chunk_pnt_check("memccpy", s1, 1, 0) != NOERROR
  1967. X    || _chunk_pnt_check("memccpy", s2, 1, 0) != NOERROR)
  1968. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1969. X    _malloc_message("bad pointer argument found in memccpy");
  1970. X  }
  1971. X  return (char *)memccpy(s1, s2, ch, len);
  1972. X}
  1973. X#endif
  1974. X
  1975. X#if HAVE_MEMCHR
  1976. X/*
  1977. X * dummy function for checking memchr's arguments.
  1978. X */
  1979. XEXPORT    char    *_malloc_memchr(char * s1, char ch, int len)
  1980. X{
  1981. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1982. X    if (_chunk_pnt_check("memchr", s1, 1, len) != NOERROR)
  1983. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1984. X    _malloc_message("bad pointer argument found in memchr");
  1985. X  }
  1986. X  return (char *)memchr(s1, ch, len);
  1987. X}
  1988. X#endif
  1989. X
  1990. X#if HAVE_STRCHR
  1991. X/*
  1992. X * dummy function for checking strchr's arguments.
  1993. X */
  1994. XEXPORT    char    *_malloc_strchr(char * str, char ch)
  1995. X{
  1996. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  1997. X    if (_chunk_pnt_check("strchr", str, 1, 0) != NOERROR)
  1998. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  1999. X    _malloc_message("bad pointer argument found in strchr");
  2000. X  }
  2001. X  return (char *)strchr(str, ch);
  2002. X}
  2003. X#endif
  2004. X
  2005. X#if HAVE_STRRCHR
  2006. X/*
  2007. X * dummy function for checking strrchr's arguments.
  2008. X */
  2009. XEXPORT    char    *_malloc_strrchr(char * str, char ch)
  2010. X{
  2011. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2012. X    if (_chunk_pnt_check("strrchr", str, 1, 0) != NOERROR)
  2013. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2014. X    _malloc_message("bad pointer argument found in strrchr");
  2015. X  }
  2016. X  return (char *)strrchr(str, ch);
  2017. X}
  2018. X#endif
  2019. X
  2020. X#if HAVE_STRCPY
  2021. X/*
  2022. X * dummy function for checking strcpy's arguments.
  2023. X */
  2024. XEXPORT    char    *_malloc_strcpy(char * to, char * from)
  2025. X{
  2026. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2027. X    /* maybe to, strlen(from) */
  2028. X    if (_chunk_pnt_check("strcpy", to, 1, 0) != NOERROR
  2029. X    || _chunk_pnt_check("strcpy", from, 1, 0) != NOERROR)
  2030. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2031. X    _malloc_message("bad pointer argument found in strcpy");
  2032. X  }
  2033. X  return (char *)strcpy(to, from);
  2034. X}
  2035. X#endif
  2036. X
  2037. X#if HAVE_STRNCPY
  2038. X/*
  2039. X * dummy function for checking strncpy's arguments.
  2040. X */
  2041. XEXPORT    char    *_malloc_strncpy(char * to, char * from, int len)
  2042. X{
  2043. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2044. X    /* len or until nullc */
  2045. X    if (_chunk_pnt_check("strncpy", to, 1, 0) != NOERROR
  2046. X    || _chunk_pnt_check("strncpy", from, 1, 0) != NOERROR)
  2047. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2048. X    _malloc_message("bad pointer argument found in strncpy");
  2049. X  }
  2050. X  return (char *)strncpy(to, from, len);
  2051. X}
  2052. X#endif
  2053. X
  2054. X#if HAVE_STRCASECMP
  2055. X/*
  2056. X * dummy function for checking strcasecmp's arguments.
  2057. X */
  2058. XEXPORT    int    _malloc_strcasecmp(char * s1, char * s2)
  2059. X{
  2060. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2061. X    if (_chunk_pnt_check("strcasecmp", s1, 1, 0) != NOERROR
  2062. X    || _chunk_pnt_check("strcasecmp", s2, 1, 0) != NOERROR)
  2063. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2064. X    _malloc_message("bad pointer argument found in strcasecmp");
  2065. X  }
  2066. X  return strcasecmp(s1, s2);
  2067. X}
  2068. X#endif
  2069. X
  2070. X#if HAVE_STRNCASECMP
  2071. X/*
  2072. X * dummy function for checking strncasecmp's arguments.
  2073. X */
  2074. XEXPORT    int    _malloc_strncasecmp(char * s1, char * s2, int len)
  2075. X{
  2076. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2077. X    /* len or until nullc */
  2078. X    if (_chunk_pnt_check("strncasecmp", s1, 1, 0) != NOERROR
  2079. X    || _chunk_pnt_check("strncasecmp", s2, 1, 0) != NOERROR)
  2080. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2081. X    _malloc_message("bad pointer argument found in strncasecmp");
  2082. X  }
  2083. X  return strncasecmp(s1, s2, len);
  2084. X}
  2085. X#endif
  2086. X
  2087. X#if HAVE_STRSPN
  2088. X/*
  2089. X * dummy function for checking strspn's arguments.
  2090. X */
  2091. XEXPORT    int    _malloc_strspn(char * str, char * list)
  2092. X{
  2093. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2094. X    if (_chunk_pnt_check("strspn", str, 1, 0) != NOERROR
  2095. X    || _chunk_pnt_check("strspn", list, 1, 0) != NOERROR)
  2096. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2097. X    _malloc_message("bad pointer argument found in strspn");
  2098. X  }
  2099. X  return strspn(str, list);
  2100. X}
  2101. X#endif
  2102. X
  2103. X#if HAVE_STRCSPN
  2104. X/*
  2105. X * dummy function for checking strcspn's arguments.
  2106. X */
  2107. XEXPORT    int    _malloc_strcspn(char * str, char * list)
  2108. X{
  2109. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2110. X    if (_chunk_pnt_check("strcspn", str, 1, 0) != NOERROR
  2111. X    || _chunk_pnt_check("strcspn", list, 1, 0) != NOERROR)
  2112. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2113. X    _malloc_message("bad pointer argument found in strcspn");
  2114. X  }
  2115. X  return strcspn(str, list);
  2116. X}
  2117. X#endif
  2118. X
  2119. X#if HAVE_STRNCAT
  2120. X/*
  2121. X * dummy function for checking strncat's arguments.
  2122. X */
  2123. XEXPORT    char    *_malloc_strncat(char * to, char * from, int len)
  2124. X{
  2125. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2126. X    /* either len or nullc */
  2127. X    if (_chunk_pnt_check("strncat", to, 1, 0) != NOERROR
  2128. X    || _chunk_pnt_check("strncat", from, 1, 0) != NOERROR)
  2129. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2130. X    _malloc_message("bad pointer argument found in strncat");
  2131. X  }
  2132. X  return (char *)strncat(to, from, len);
  2133. X}
  2134. X#endif
  2135. X
  2136. X#if HAVE_STRNCMP
  2137. X/*
  2138. X * dummy function for checking strncmp's arguments.
  2139. X */
  2140. XEXPORT    int    _malloc_strncmp(char * s1, char * s2, int len)
  2141. X{
  2142. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2143. X    /* either len or nullc */
  2144. X    if (_chunk_pnt_check("strncmp", s1, 1, 0) != NOERROR
  2145. X    || _chunk_pnt_check("strncmp", s2, 1, 0) != NOERROR)
  2146. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2147. X    _malloc_message("bad pointer argument found in strncmp");
  2148. X  }
  2149. X  return strncmp(s1, s2, len);
  2150. X}
  2151. X#endif
  2152. X
  2153. X#if HAVE_STRPBRK
  2154. X/*
  2155. X * dummy function for checking strpbrk's arguments.
  2156. X */
  2157. XEXPORT    char    *_malloc_strpbrk(char * str, char * list)
  2158. X{
  2159. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2160. X    if (_chunk_pnt_check("strpbrk", str, 1, 0) != NOERROR
  2161. X    || _chunk_pnt_check("strpbrk", list, 1, 0) != NOERROR)
  2162. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2163. X    _malloc_message("bad pointer argument found in strpbrk");
  2164. X  }
  2165. X  return (char *)strpbrk(str, list);
  2166. X}
  2167. X#endif
  2168. X
  2169. X#if HAVE_STRSTR
  2170. X/*
  2171. X * dummy function for checking strstr's arguments.
  2172. X */
  2173. XEXPORT    char    *_malloc_strstr(char * str, char * pat)
  2174. X{
  2175. X  if (BIT_IS_SET(_malloc_debug, DEBUG_CHECK_FUNCS)) {
  2176. X    if (_chunk_pnt_check("str", str, 1, 0) != NOERROR
  2177. X    || _chunk_pnt_check("str", pat, 1, 0) != NOERROR)
  2178. X      if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER))
  2179. X    _malloc_message("bad pointer argument found in strstr");
  2180. X  }
  2181. X  return (char *)strstr(str, pat);
  2182. X}
  2183. X#endif
  2184. END_OF_FILE
  2185. if test 13374 -ne `wc -c <'malloc_str.c'`; then
  2186.     echo shar: \"'malloc_str.c'\" unpacked with wrong size!
  2187. fi
  2188. # end of 'malloc_str.c'
  2189. fi
  2190. if test -f 'malloc_str.h' -a "${1}" != "-c" ; then 
  2191.   echo shar: Will not clobber existing file \"'malloc_str.h'\"
  2192. else
  2193. echo shar: Extracting \"'malloc_str.h'\" \(4281 characters\)
  2194. sed "s/^X//" >'malloc_str.h' <<'END_OF_FILE'
  2195. X/*
  2196. X * defines for malloc string routines...
  2197. X *
  2198. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  2199. X *
  2200. X * This file is part of the malloc-debug package.
  2201. X *
  2202. X * This library is free software; you can redistribute it and/or
  2203. X * modify it under the terms of the GNU Library General Public
  2204. X * License as published by the Free Software Foundation; either
  2205. X * version 2 of the License, or (at your option) any later version.
  2206. X *
  2207. X * This library is distributed in the hope that it will be useful,
  2208. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2209. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  2210. X * Library General Public License for more details.
  2211. X *
  2212. X * You should have received a copy of the GNU Library General Public
  2213. X * License along with this library (see COPYING-LIB); if not, write to the
  2214. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  2215. X *
  2216. X * The author of the program may be contacted at gray.watson@antaire.com
  2217. X *
  2218. X * $Id: malloc_str.h,v 1.4 1993/04/06 04:24:42 gray Exp $
  2219. X */
  2220. X
  2221. X#ifndef __MALLOC_STR_H__
  2222. X#define __MALLOC_STR_H__
  2223. X
  2224. X/*<<<<<<<<<<  The below prototypes are auto-generated by fillproto */
  2225. X
  2226. X/*
  2227. X * dummy function for checking bcmp's arguments.
  2228. X */
  2229. XIMPORT    int    _malloc_bcmp(void * b1, void * b2, int len);
  2230. X
  2231. X/*
  2232. X * dummy function for checking bcopy's arguments.
  2233. X */
  2234. XIMPORT    void    _malloc_bcopy(char * from, char * to, int len);
  2235. X
  2236. X/*
  2237. X * dummy function for checking memcmp's arguments.
  2238. X */
  2239. XIMPORT    int    _malloc_memcmp(void * b1,
  2240. X                   void * b2, int len);
  2241. X
  2242. X/*
  2243. X * dummy function for checking memcpy's arguments.
  2244. X */
  2245. XIMPORT    char    *_malloc_memcpy(char * to, char * from, int len);
  2246. X
  2247. X/*
  2248. X * dummy function for checking memset's arguments.
  2249. X */
  2250. XIMPORT    char    *_malloc_memset(void * buf, char ch, int len);
  2251. X
  2252. X/*
  2253. X * dummy function for checking index's arguments.
  2254. X */
  2255. XIMPORT    char    *_malloc_index(char * str, char ch);
  2256. X
  2257. X/*
  2258. X * dummy function for checking rindex's arguments.
  2259. X */
  2260. XIMPORT    char    *_malloc_rindex(char * str, char ch);
  2261. X
  2262. X/*
  2263. X * dummy function for checking strcat's arguments.
  2264. X */
  2265. XIMPORT    char    *_malloc_strcat(char * to, char * from);
  2266. X
  2267. X/*
  2268. X * dummy function for checking strcmp's arguments.
  2269. X */
  2270. XIMPORT    int    _malloc_strcmp(char * s1,
  2271. X                   char * s2);
  2272. X
  2273. X/*
  2274. X * dummy function for checking strlen's arguments.
  2275. X */
  2276. XIMPORT    int    _malloc_strlen(char * str);
  2277. X
  2278. X/*
  2279. X * dummy function for checking strtok's arguments.
  2280. X */
  2281. XIMPORT    char    *_malloc_strtok(char * str, char * sep);
  2282. X
  2283. X/*
  2284. X * dummy function for checking bzero's arguments.
  2285. X */
  2286. XIMPORT    void    _malloc_bzero(void * buf,
  2287. X                  int len);
  2288. X
  2289. X/*
  2290. X * dummy function for checking memccpy's arguments.
  2291. X */
  2292. XIMPORT    char    *_malloc_memccpy(char * s1, char * s2, char ch, int len);
  2293. X
  2294. X/*
  2295. X * dummy function for checking memchr's arguments.
  2296. X */
  2297. XIMPORT    char    *_malloc_memchr(char * s1, char ch, int len);
  2298. X
  2299. X/*
  2300. X * dummy function for checking strchr's arguments.
  2301. X */
  2302. XIMPORT    char    *_malloc_strchr(char * str, char ch);
  2303. X
  2304. X/*
  2305. X * dummy function for checking strrchr's arguments.
  2306. X */
  2307. XIMPORT    char    *_malloc_strrchr(char * str, char ch);
  2308. X
  2309. X/*
  2310. X * dummy function for checking strcpy's arguments.
  2311. X */
  2312. XIMPORT    char    *_malloc_strcpy(char * to, char * from);
  2313. X
  2314. X/*
  2315. X * dummy function for checking strncpy's arguments.
  2316. X */
  2317. XIMPORT    char    *_malloc_strncpy(char * to, char * from, int len);
  2318. X
  2319. X/*
  2320. X * dummy function for checking strcasecmp's arguments.
  2321. X */
  2322. XIMPORT    int    _malloc_strcasecmp(char * s1, char * s2);
  2323. X
  2324. X/*
  2325. X * dummy function for checking strncasecmp's arguments.
  2326. X */
  2327. XIMPORT    int    _malloc_strncasecmp(char * s1, char * s2, int len);
  2328. X
  2329. X/*
  2330. X * dummy function for checking strspn's arguments.
  2331. X */
  2332. XIMPORT    int    _malloc_strspn(char * str, char * list);
  2333. X
  2334. X/*
  2335. X * dummy function for checking strcspn's arguments.
  2336. X */
  2337. XIMPORT    int    _malloc_strcspn(char * str, char * list);
  2338. X
  2339. X/*
  2340. X * dummy function for checking strncat's arguments.
  2341. X */
  2342. XIMPORT    char    *_malloc_strncat(char * to, char * from, int len);
  2343. X
  2344. X/*
  2345. X * dummy function for checking strncmp's arguments.
  2346. X */
  2347. XIMPORT    int    _malloc_strncmp(char * s1, char * s2, int len);
  2348. X
  2349. X/*
  2350. X * dummy function for checking strpbrk's arguments.
  2351. X */
  2352. XIMPORT    char    *_malloc_strpbrk(char * str, char * list);
  2353. X
  2354. X/*
  2355. X * dummy function for checking strstr's arguments.
  2356. X */
  2357. XIMPORT    char    *_malloc_strstr(char * str, char * pat);
  2358. X
  2359. X/*<<<<<<<<<<   This is end of the auto-generated output from fillproto. */
  2360. X
  2361. X#endif /* ! __MALLOC_STR_H__ */
  2362. END_OF_FILE
  2363. if test 4281 -ne `wc -c <'malloc_str.h'`; then
  2364.     echo shar: \"'malloc_str.h'\" unpacked with wrong size!
  2365. fi
  2366. # end of 'malloc_str.h'
  2367. fi
  2368. if test -f 'sample.c' -a "${1}" != "-c" ; then 
  2369.   echo shar: Will not clobber existing file \"'sample.c'\"
  2370. else
  2371. echo shar: Extracting \"'sample.c'\" \(609 characters\)
  2372. sed "s/^X//" >'sample.c' <<'END_OF_FILE'
  2373. X/*
  2374. X * sample malloc library usage program.
  2375. X */
  2376. X
  2377. X#include "malloc.h"
  2378. X
  2379. Xstatic    char    *rcs_id =
  2380. X  "$Id: sample.c,v 1.2 1992/12/22 04:55:38 gray Exp $";
  2381. X
  2382. Xmain(int argc, char ** argv)
  2383. X{
  2384. X  char    *pnt;
  2385. X  long    *longp;
  2386. X  
  2387. X  /* allocate 10-bytes */
  2388. X  pnt = MALLOC(10);
  2389. X  
  2390. X  /* free the pointer */
  2391. X  FREE(pnt);
  2392. X  
  2393. X  /* allocate 50-longs */
  2394. X  longp = ALLOC(long, 50);
  2395. X  
  2396. X  /* realloc to 100-longs */
  2397. X  longp = REALLOC(longp, long, 100);
  2398. X  /* don't free them */
  2399. X  
  2400. X#ifdef MALLOC_DEBUG
  2401. X  /* check out the heap and shut everything down if we are in debug mode */
  2402. X  malloc_verify(0);
  2403. X  malloc_shutdown();
  2404. X#endif
  2405. X  
  2406. X  exit(0);
  2407. X}
  2408. END_OF_FILE
  2409. if test 609 -ne `wc -c <'sample.c'`; then
  2410.     echo shar: \"'sample.c'\" unpacked with wrong size!
  2411. fi
  2412. # end of 'sample.c'
  2413. fi
  2414. if test -f 'version.h' -a "${1}" != "-c" ; then 
  2415.   echo shar: Will not clobber existing file \"'version.h'\"
  2416. else
  2417. echo shar: Extracting \"'version.h'\" \(1036 characters\)
  2418. sed "s/^X//" >'version.h' <<'END_OF_FILE'
  2419. X/*
  2420. X * version string for the library
  2421. X *
  2422. X * Copyright 1992 by Gray Watson and the Antaire Corporation
  2423. X *
  2424. X * This file is part of the malloc-debug package.
  2425. X *
  2426. X * This library is free software; you can redistribute it and/or
  2427. X * modify it under the terms of the GNU Library General Public
  2428. X * License as published by the Free Software Foundation; either
  2429. X * version 2 of the License, or (at your option) any later version.
  2430. X *
  2431. X * This library is distributed in the hope that it will be useful,
  2432. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2433. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  2434. X * Library General Public License for more details.
  2435. X *
  2436. X * You should have received a copy of the GNU Library General Public
  2437. X * License along with this library (see COPYING-LIB); if not, write to the
  2438. X * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  2439. X *
  2440. X * The author of the program may be contacted at gray.watson@antaire.com
  2441. X */
  2442. X
  2443. X#include "malloc.h"
  2444. X
  2445. XLOCAL    char    *malloc_version = "1.2.0";
  2446. END_OF_FILE
  2447. if test 1036 -ne `wc -c <'version.h'`; then
  2448.     echo shar: \"'version.h'\" unpacked with wrong size!
  2449. fi
  2450. # end of 'version.h'
  2451. fi
  2452. echo shar: End of archive 5 \(of 5\).
  2453. cp /dev/null ark5isdone
  2454. MISSING=""
  2455. for I in 1 2 3 4 5 ; do
  2456.     if test ! -f ark${I}isdone ; then
  2457.     MISSING="${MISSING} ${I}"
  2458.     fi
  2459. done
  2460. if test "${MISSING}" = "" ; then
  2461.     echo You have unpacked all 5 archives.
  2462.     echo "Do a 'sh ./configure' to configure the library"
  2463.     rm -f ark[1-9]isdone
  2464. else
  2465.     echo You still need to unpack the following archives:
  2466.     echo "        " ${MISSING}
  2467. fi
  2468. ##  End of shell archive.
  2469. exit 0
  2470.