home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-01-29 | 40.1 KB | 1,613 lines |
- Newsgroups: comp.sources.misc
- From: dvadura@plg.waterloo.edu (Dennis Vadura)
- Subject: v27i107: dmake - dmake Version 3.8, Part06/41
- Message-ID: <1992Jan28.031325.7080@sparky.imd.sterling.com>
- X-Md4-Signature: 5905e441a96d0f300b3d5765afceea14
- Date: Tue, 28 Jan 1992 03:13:25 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: dvadura@plg.waterloo.edu (Dennis Vadura)
- Posting-number: Volume 27, Issue 107
- Archive-name: dmake/part06
- Environment: Atari-ST, Coherent, Mac, MSDOS, OS/2, UNIX
- Supersedes: dmake: Volume 19, Issue 22-58
-
- ---- Cut Here and feed the following to sh ----
- # this is dmake.shar.06 (part 6 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file dmake/dbug/malloc/mlc_chn.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 6; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test -f _shar_wnt_.tmp; then
- sed 's/^X//' << 'SHAR_EOF' >> 'dmake/dbug/malloc/mlc_chn.c' &&
- X rtn++;
- X continue;
- X }
- X
- X /*
- X * verify segments are correctly linked together
- X */
- X
- X if( (ptr->prev && (ptr->prev->next != ptr) ) ||
- X (ptr->next && (ptr->next->prev != ptr) ) ||
- X ((ptr->next == NULL) && (ptr->prev == NULL)) )
- X {
- X malloc_errno = M_CODE_BAD_CONNECT;
- X if( todo )
- X {
- X malloc_warning(func);
- X }
- X rtn++;
- X continue;
- X }
- X
- X /*
- X * If this segment is allocated
- X */
- X
- X if( (ptr->flag & M_INUSE) != 0 )
- X {
- X /*
- X * verify no overflow of data area
- X */
- X
- X for(i=ptr->r_size; i < ptr->s.size; i++)
- X {
- X if( ptr->data[i] != M_FILL )
- X {
- X malloc_errno = M_CODE_OVERRUN;
- X if( todo )
- X {
- X malloc_warning(func);
- X }
- X rtn++;
- X break;
- X }
- X }
- X }
- X else /* it's not allocated so */
- X {
- X /*
- X * verify no reuse of freed data blocks
- X */
- X
- X for(i=0; i < ptr->s.size; i++)
- X {
- X if( ptr->data[i] != M_FREE_FILL )
- X {
- X malloc_errno = M_CODE_REUSE;
- X if( todo )
- X {
- X malloc_warning(func);
- X }
- X rtn++;
- X break;
- X }
- X }
- X }
- X
- X } /* for(... */
- X
- X return(rtn);
- X
- } /* malloc_chain_check(... */
- SHAR_EOF
- chmod 0640 dmake/dbug/malloc/mlc_chn.c ||
- echo 'restore of dmake/dbug/malloc/mlc_chn.c failed'
- Wc_c="`wc -c < 'dmake/dbug/malloc/mlc_chn.c'`"
- test 3448 -eq "$Wc_c" ||
- echo 'dmake/dbug/malloc/mlc_chn.c: original size 3448, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= dmake/dbug/malloc/patchlevel ==============
- if test -f 'dmake/dbug/malloc/patchlevel' -a X"$1" != X"-c"; then
- echo 'x - skipping dmake/dbug/malloc/patchlevel (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/malloc/patchlevel' &&
- 3
- SHAR_EOF
- chmod 0640 dmake/dbug/malloc/patchlevel ||
- echo 'restore of dmake/dbug/malloc/patchlevel failed'
- Wc_c="`wc -c < 'dmake/dbug/malloc/patchlevel'`"
- test 2 -eq "$Wc_c" ||
- echo 'dmake/dbug/malloc/patchlevel: original size 2, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= dmake/dbug/malloc/realloc.c ==============
- if test -f 'dmake/dbug/malloc/realloc.c' -a X"$1" != X"-c"; then
- echo 'x - skipping dmake/dbug/malloc/realloc.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/malloc/realloc.c' &&
- /*
- X * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).
- X * You may copy, distribute, and use this software as long as this
- X * copyright statement is not removed.
- X */
- #include <stdio.h>
- #include "malloc.h"
- X
- /*
- X * Function: realloc()
- X *
- X * Purpose: to re-allocate a data area.
- X *
- X * Arguments: cptr - pointer to area to reallocate
- X * size - size to change area to
- X *
- X * Returns: pointer to new area (may be same area)
- X *
- X * Narrative: verify pointer is within malloc region
- X * obtain mlist pointer from cptr
- X * verify magic number is correct
- X * verify inuse flag is set
- X * verify connection to adjoining segments is correct
- X * save requested size
- X * round-up size to appropriate boundry
- X * IF size is bigger than what is in this segment
- X * try to join next segment to this segment
- X * IF size is less than what is is this segment
- X * determine leftover amount of space
- X * ELSE
- X * allocate new segment of size bites
- X * IF allocation failed
- X * return NULL
- X * copy previous data to new segment
- X * free previous segment
- X * return new pointer
- X * split of extra space in this segment (if any)
- X * clear bytes beyound what they had before
- X * return pointer to data
- X */
- #ifndef lint
- static
- char rcs_hdr[] = "$Id: realloc.c,v 1.1 1992/01/24 03:29:11 dvadura Exp $";
- #endif
- X
- char *
- realloc(cptr,size)
- X char * cptr;
- X unsigned int size;
- {
- X void free();
- X char * func = "realloc";
- X int i;
- X char * malloc();
- X extern int malloc_checking;
- X extern struct mlist * malloc_end;
- X extern int malloc_errno;
- X extern char * malloc_data_end;
- X extern char * malloc_data_start;
- X void malloc_join();
- X void malloc_memset();
- X void malloc_split();
- X char * memcpy();
- X char * new_cptr;
- X struct mlist * ptr;
- X int r_size;
- X
- X /*
- X * IF malloc chain checking is on, go do it.
- X */
- X if( malloc_checking )
- X {
- X (void) malloc_chain_check(1);
- X }
- X
- X /*
- X * verify that cptr is within the malloc region...
- X */
- X if( cptr < malloc_data_start || cptr > malloc_data_end )
- X {
- X malloc_errno = M_CODE_BAD_PTR;
- X malloc_warning(func);
- X return (NULL);
- X }
- X
- X /*
- X * convert pointer to mlist struct pointer. To do this we must
- X * move the pointer backwards the correct number of bytes...
- X */
- X
- X ptr = (struct mlist *) (cptr - M_SIZE);
- X
- X if( (ptr->flag&M_MAGIC) != M_MAGIC )
- X {
- X malloc_errno = M_CODE_BAD_MAGIC;
- X malloc_warning(func);
- X return(NULL);
- X }
- X
- X if( ! (ptr->flag & M_INUSE) )
- X {
- X malloc_errno = M_CODE_NOT_INUSE ;
- X malloc_warning(func);
- X return(NULL);
- X }
- X
- X if( (ptr->prev && (ptr->prev->next != ptr) ) ||
- X (ptr->next && (ptr->next->prev != ptr) ) ||
- X ((ptr->next == NULL) && (ptr->prev == NULL)) )
- X {
- X malloc_errno = M_CODE_BAD_CONNECT;
- X malloc_warning(func);
- X return(NULL);
- X }
- X
- X r_size = ++size;
- X
- X M_ROUNDUP(size);
- X
- X if( size > ptr->s.size )
- X {
- X malloc_join(ptr,ptr->next,1,1);
- X }
- X
- X if( size > ptr->s.size )
- X {
- X /*
- X * else we can't combine it, so lets allocate a new chunk,
- X * copy the data and free the old chunk...
- X */
- X new_cptr = malloc(size);
- X
- X if( new_cptr == (char *) 0)
- X {
- X return(new_cptr);
- X }
- X
- X if( r_size < ptr->r_size )
- X {
- X i = r_size;
- X }
- X else
- X {
- X i = ptr->r_size;
- X }
- X (void)memcpy(new_cptr,ptr->data,i);
- X free(cptr);
- X return(new_cptr);
- X
- X } /* else... */
- X
- X /*
- X * save amount of real data in new segment (this will be used in the
- X * memset later) and then save requested size of this segment.
- X */
- X
- X if( ptr->r_size < r_size )
- X {
- X i = ptr->r_size;
- X }
- X else
- X {
- X i = r_size;
- X }
- X
- X ptr->r_size = r_size;
- X
- X /*
- X * split off extra free space at end of this segment, if possible...
- X */
- X
- X malloc_split(ptr);
- X
- X malloc_memset( ptr->data+i, M_FILL, (int) (ptr->s.size - i));
- X
- X return(ptr->data);
- X
- } /* realloc(... */
- X
- X
- /*
- X * $Log: realloc.c,v $
- X * Revision 1.1 1992/01/24 03:29:11 dvadura
- X * dmake Version 3.8, Initial revision
- X *
- X * Revision 1.8 90/08/29 21:22:52 cpcahil
- X * miscellaneous lint fixes
- X *
- X * Revision 1.7 90/05/11 00:13:10 cpcahil
- X * added copyright statment
- X *
- X * Revision 1.6 90/02/25 11:01:20 cpcahil
- X * added support for malloc chain checking.
- X *
- X * Revision 1.5 90/02/24 21:50:31 cpcahil
- X * lots of lint fixes
- X *
- X * Revision 1.4 90/02/24 17:29:39 cpcahil
- X * changed $Header to $Id so full path wouldnt be included as part of rcs
- X * id string
- X *
- X * Revision 1.3 90/02/24 17:20:00 cpcahil
- X * attempt to get rid of full path in rcs header.
- X *
- X * Revision 1.2 90/02/24 15:14:20 cpcahil
- X * 1. added function header
- X * 2. changed calls to malloc_warning to conform to new usage
- X * 3. added setting of malloc_errno
- X * 4. broke up bad pointer determination so that errno's would be more
- X * descriptive
- X *
- X * Revision 1.1 90/02/22 23:17:43 cpcahil
- X * Initial revision
- X *
- X */
- SHAR_EOF
- chmod 0640 dmake/dbug/malloc/realloc.c ||
- echo 'restore of dmake/dbug/malloc/realloc.c failed'
- Wc_c="`wc -c < 'dmake/dbug/malloc/realloc.c'`"
- test 4750 -eq "$Wc_c" ||
- echo 'dmake/dbug/malloc/realloc.c: original size 4750, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= dmake/dbug/malloc/string.c ==============
- if test -f 'dmake/dbug/malloc/string.c' -a X"$1" != X"-c"; then
- echo 'x - skipping dmake/dbug/malloc/string.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/malloc/string.c' &&
- /*
- X * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).
- X * You may copy, distribute, and use this software as long as this
- X * copyright statement is not removed.
- X */
- X
- #include <stdio.h>
- #include <string.h>
- #include <sys/types.h>
- #include "malloc.h"
- X
- #ifndef lint
- static
- char rcs_hdr[] = "$Id: string.c,v 1.1 1992/01/24 03:29:13 dvadura Exp $";
- #endif
- X
- int malloc_checking = 0;
- X
- char *
- strcat(str1,str2)
- X register char * str1;
- X register char * str2;
- {
- X char * rtn;
- X int len;
- X
- X /*
- X * check pointers agains malloc region. The malloc* functions
- X * will properly handle the case where a pointer does not
- X * point into malloc space.
- X */
- X malloc_checking = 1;
- X
- X len = strlen(str2);
- X malloc_check_str("strcat", str2);
- X
- X len += strlen(str1) + 1;
- X malloc_checking = 0;
- X
- X malloc_check_data("strcat", str1, len);
- X
- X rtn = str1;
- X
- X while( *str1 )
- X {
- X str1++;
- X }
- X
- X while( (*str1 = *str2) != '\0' )
- X {
- X str1++;
- X str2++;
- X }
- X
- X return(rtn);
- }
- X
- char *
- strdup(str1)
- X register char * str1;
- {
- X char * malloc();
- X char * rtn;
- X register char * str2;
- X
- X malloc_check_str("strdup", str1);
- X
- X rtn = str2 = malloc((unsigned)strlen(str1)+1);
- X
- X if( rtn != (char *) 0)
- X {
- X while( (*str2 = *str1) != '\0' )
- X {
- X str1++;
- X str2++;
- X }
- X }
- X
- X return(rtn);
- }
- X
- char *
- strncat(str1,str2,len)
- X register char * str1;
- X register char * str2;
- X register int len;
- {
- X int len1;
- X int len2;
- X char * rtn;
- X
- X malloc_check_strn("strncat", str2, len);
- X
- X malloc_checking = 1;
- X
- X len2 = strlen(str2) + 1;
- X len1 = strlen(str1);
- X
- X malloc_checking = 0;
- X
- X
- X if( (len+1) < len2 )
- X {
- X len1 += len + 1;
- X }
- X else
- X {
- X len1 += len2;
- X }
- X malloc_check_data("strncat", str1, len1);
- X
- X rtn = str1;
- X
- X while( *str1 )
- X {
- X str1++;
- X }
- X
- X while( len-- && ((*str1++ = *str2++) != '\0') )
- X {
- X }
- X
- X if( ! len )
- X {
- X *str1 = '\0';
- X }
- X
- X return(rtn);
- }
- X
- int
- strcmp(str1,str2)
- X register char * str1;
- X register char * str2;
- {
- X malloc_check_str("strcmp", str1);
- X malloc_check_str("strcmp", str2);
- X
- X while( *str1 && (*str1 == *str2) )
- X {
- X str1++;
- X str2++;
- X }
- X
- X
- X /*
- X * in order to deal with the case of a negative last char of either
- X * string when the other string has a null
- X */
- X if( (*str2 == '\0') && (*str1 == '\0') )
- X {
- X return(0);
- X }
- X else if( *str2 == '\0' )
- X {
- X return(1);
- X }
- X else if( *str1 == '\0' )
- X {
- X return(-1);
- X }
- X
- X return( *str1 - *str2 );
- }
- X
- int
- strncmp(str1,str2,len)
- X register char * str1;
- X register char * str2;
- X register int len;
- {
- X malloc_check_strn("strncmp", str1, len);
- X malloc_check_strn("strncmp", str2, len);
- X
- X while( --len >= 0 && *str1 && (*str1 == *str2) )
- X {
- X str1++;
- X str2++;
- X }
- X
- X if( len < 0 )
- X {
- X return(0);
- X }
- X /*
- X * in order to deal with the case of a negative last char of either
- X * string when the other string has a null
- X */
- X if( (*str2 == '\0') && (*str1 == '\0') )
- X {
- X return(0);
- X }
- X else if( *str2 == '\0' )
- X {
- X return(1);
- X }
- X else if( *str1 == '\0' )
- X {
- X return(-1);
- X }
- X
- X return( *str1 - *str2 );
- }
- X
- char *
- strcpy(str1,str2)
- X register char * str1;
- X register char * str2;
- {
- X char * rtn;
- X int len;
- X
- X malloc_checking = 1;
- X len = strlen(str2) + 1;
- X malloc_checking = 0;
- X
- X malloc_check_data("strcpy", str1, len);
- X malloc_check_data("strcpy", str2, len);
- X
- X rtn = str1;
- X
- X while( (*str1++ = *str2++) != '\0')
- X {
- X }
- X
- X return(rtn);
- }
- X
- char *
- strncpy(str1,str2,len)
- X register char * str1;
- X register char * str2;
- X register int len;
- {
- X extern int malloc_checking;
- X char * rtn;
- X
- X malloc_check_data("strncpy", str1, len);
- X malloc_check_strn("strncpy", str2, len);
- X
- X rtn = str1;
- X
- X while((len-- > 0) && (*str1++ = *str2++) != '\0')
- X {
- X }
- X while( (len-- > 0) )
- X {
- X *str1++ = '\0';
- X }
- X
- X return(rtn);
- }
- X
- int
- strlen(str1)
- X register char * str1;
- {
- X register char * s;
- X
- X if(! malloc_checking )
- X {
- X malloc_check_str("strlen", str1);
- X }
- X
- X for( s = str1; *s; s++)
- X {
- X }
- X
- X return( s - str1 );
- }
- X
- char *
- strchr(str1,c)
- X register char * str1;
- X register int c;
- {
- X malloc_check_str("strchr", str1);
- X
- X while( *str1 && (*str1 != (char) c) )
- X {
- X str1++;
- X }
- X
- X if(*str1 != (char) c)
- X {
- X str1 = (char *) 0;
- X }
- X
- X return(str1);
- }
- X
- char *
- strrchr(str1,c)
- X register char * str1;
- X register int c;
- {
- X register char * rtn = (char *) 0;
- X
- X malloc_check_str("strrchr", str1);
- X
- X while( *str1 )
- X {
- X if(*str1 == (char) c )
- X {
- X rtn = str1;
- X }
- X str1++;
- X }
- X
- X if( *str1 == (char) c)
- X {
- X rtn = str1;
- X }
- X
- X return(rtn);
- }
- X
- char *
- index(str1,c)
- X char * str1;
- X char c;
- {
- X return( strchr(str1,c) );
- }
- X
- char *
- rindex(str1,c)
- X char * str1;
- X char c;
- {
- X return( strrchr(str1,c) );
- }
- X
- char *
- strpbrk(str1,str2)
- X register char * str1;
- X register char * str2;
- {
- X register char * tmp;
- X
- X malloc_check_str("strpbrk", str1);
- X malloc_check_str("strpbrk", str2);
- X
- X while(*str1)
- X {
- X for( tmp=str2; *tmp && *tmp != *str1; tmp++)
- X {
- X }
- X if( *tmp )
- X {
- X break;
- X }
- X str1++;
- X }
- X
- X if( ! *str1 )
- X {
- X str1 = (char *) 0;
- X }
- X
- X return(str1);
- }
- X
- int
- strspn(str1,str2)
- X register char * str1;
- X register char * str2;
- {
- X register char * tmp;
- X char * orig = str1;
- X
- X malloc_check_str("strspn", str1);
- X malloc_check_str("strspn", str2);
- X
- X while(*str1)
- X {
- X for( tmp=str2; *tmp && *tmp != *str1; tmp++)
- X {
- X }
- X if(! *tmp )
- X {
- X break;
- X }
- X str1++;
- X }
- X
- X return( (int) (str1 - orig) );
- }
- X
- int
- strcspn(str1,str2)
- X register char * str1;
- X register char * str2;
- {
- X register char * tmp;
- X char * orig = str1;
- X
- X malloc_check_str("strcspn", str1);
- X malloc_check_str("strcspn", str2);
- X
- X while(*str1)
- X {
- X for( tmp=str2; *tmp && *tmp != *str1; tmp++)
- X {
- X }
- X if( *tmp )
- X {
- X break;
- X }
- X str1++;
- X }
- X
- X return( (int) (str1 - orig) );
- }
- X
- /*
- X * strtok() source taken from that posted to comp.lang.c by Chris Torek
- X * in Jan 1990.
- X */
- X
- /*
- X * Copyright (c) 1989 The Regents of the University of California.
- X * All rights reserved.
- X *
- X * Redistribution and use in source and binary forms are permitted
- X * provided that the above copyright notice and this paragraph are
- X * duplicated in all such forms and that any documentation,
- X * advertising materials, and other materials related to such
- X * distribution and use acknowledge that the software was developed
- X * by the University of California, Berkeley. The name of the
- X * University may not be used to endorse or promote products derived
- X * from this software without specific prior written permission.
- X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- X */
- X
- /*
- X * Get next token from string s (NULL on 2nd, 3rd, etc. calls),
- X * where tokens are nonempty strings separated by runs of
- X * chars from delim. Writes NULs into s to end tokens. delim need not
- X * remain constant from call to call.
- X *
- X * Modified by cpc: changed variable names to conform with naming
- X * conventions used in rest of code. Added malloc pointer
- X * check calls.
- X */
- char *
- strtok(str1, str2)
- X char * str1;
- X char * str2;
- {
- X static char * last;
- X char * strtoken();
- X
- X if( str1 )
- X {
- X malloc_check_str("strtok", str1);
- X last = str1;
- X }
- X malloc_check_str("strtok", str2);
- X
- X return (strtoken(&last, str2, 1));
- }
- X
- X
- /*
- X * Get next token from string *stringp, where tokens are (possibly empty)
- X * strings separated by characters from delim. Tokens are separated
- X * by exactly one delimiter iff the skip parameter is false; otherwise
- X * they are separated by runs of characters from delim, because we
- X * skip over any initial `delim' characters.
- X *
- X * Writes NULs into the string at *stringp to end tokens.
- X * delim will usually, but need not, remain constant from call to call.
- X * On return, *stringp points past the last NUL written (if there might
- X * be further tokens), or is NULL (if there are definitely no more tokens).
- X *
- X * If *stringp is NULL, strtoken returns NULL.
- X */
- char *
- strtoken(stringp, delim, skip)
- X register char **stringp;
- X register char *delim;
- X int skip;
- {
- X register char *s;
- X register char *spanp;
- X register int c, sc;
- X char *tok;
- X
- X if ((s = *stringp) == NULL)
- X return (NULL);
- X
- X if (skip) {
- X /*
- X * Skip (span) leading delimiters (s += strspn(s, delim)).
- X */
- X cont:
- X c = *s;
- X for (spanp = delim; (sc = *spanp++) != 0;) {
- X if (c == sc) {
- X s++;
- X goto cont;
- X }
- X }
- X if (c == 0) { /* no token found */
- X *stringp = NULL;
- X return (NULL);
- X }
- X }
- X
- X /*
- X * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
- X * Note that delim must have one NUL; we stop if we see that, too.
- X */
- X for (tok = s;;) {
- X c = *s++;
- X spanp = delim;
- X do {
- X if ((sc = *spanp++) == c) {
- X if (c == 0)
- X s = NULL;
- X else
- X s[-1] = 0;
- X *stringp = s;
- X return (tok);
- X }
- X } while (sc != 0);
- X }
- X /* NOTREACHED */
- }
- X
- /*
- X * $Log: string.c,v $
- X * Revision 1.1 1992/01/24 03:29:13 dvadura
- X * dmake Version 3.8, Initial revision
- X *
- X * Revision 1.7 90/08/29 22:24:19 cpcahil
- X * added new function to check on strings up to a specified length
- X * and used it within several strn* functions.
- X *
- X * Revision 1.6 90/07/16 20:06:56 cpcahil
- X * fixed several minor bugs found with Henry Spencer's string/mem function
- X * tester program.
- X *
- X * Revision 1.5 90/06/10 14:59:49 cpcahil
- X * Fixed a couple of bugs in strncpy & strdup
- X *
- X * Revision 1.4 90/05/11 00:13:10 cpcahil
- X * added copyright statment
- X *
- X * Revision 1.3 90/02/24 21:50:32 cpcahil
- X * lots of lint fixes
- X *
- X * Revision 1.2 90/02/24 17:29:40 cpcahil
- X * changed $Header to $Id so full path wouldnt be included as part of rcs
- X * id string
- X *
- X * Revision 1.1 90/02/22 23:17:44 cpcahil
- X * Initial revision
- X *
- X */
- SHAR_EOF
- chmod 0640 dmake/dbug/malloc/string.c ||
- echo 'restore of dmake/dbug/malloc/string.c failed'
- Wc_c="`wc -c < 'dmake/dbug/malloc/string.c'`"
- test 9473 -eq "$Wc_c" ||
- echo 'dmake/dbug/malloc/string.c: original size 9473, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= dmake/dbug/malloc/testmem.c ==============
- if test -f 'dmake/dbug/malloc/testmem.c' -a X"$1" != X"-c"; then
- echo 'x - skipping dmake/dbug/malloc/testmem.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/malloc/testmem.c' &&
- /*
- X * This stuff is all stolen (with permission, since it was in the public
- X * domain) from Henry Spencer's string and memory library. Thanks Henry.
- X */
- X
- /*
- X * Test program for string(3) routines.
- X *
- X * Note that at least one Bell Labs implementation of the string
- X * routines flunks a couple of these tests -- the ones which test
- X * behavior on "negative" characters.
- X */
- X
- #include <stdio.h>
- #include <string.h>
- X
- char * index();
- char * rindex();
- X
- #define STREQ(a, b) (strcmp((a), (b)) == 0)
- X
- char *it = "<UNSET>"; /* Routine name for message routines. */
- int waserror = 0; /* For exit status. */
- X
- char uctest[] = "\004\203"; /* For testing signedness of chars. */
- int charsigned; /* Result. */
- X
- /*
- X - check - complain if condition is not true
- X */
- void
- check(thing, number)
- int thing;
- int number; /* Test number for error message. */
- {
- X if (!thing) {
- X printf("%s flunked test %d\n", it, number);
- X waserror = 1;
- X }
- }
- X
- /*
- X - equal - complain if first two args don't strcmp as equal
- X */
- void
- equal(a, b, number)
- char *a;
- char *b;
- int number; /* Test number for error message. */
- {
- X check(a != NULL && b != NULL && STREQ(a, b), number);
- }
- X
- char one[50];
- char two[50];
- X
- #ifdef UNIXERR
- #define ERR 1
- #endif
- #ifdef BERKERR
- #define ERR 1
- #endif
- #ifdef ERR
- int f;
- extern char *sys_errlist[];
- extern int sys_nerr;
- extern int errno;
- #endif
- X
- /* ARGSUSED */
- main(argc, argv)
- int argc;
- char *argv[];
- {
- X /*
- X * First, establish whether chars are signed.
- X */
- X if (uctest[0] < uctest[1])
- X charsigned = 0;
- X else
- X charsigned = 1;
- X
- X /*
- X * Then, do the rest of the work. Split into two functions because
- X * some compilers get unhappy about a single immense function.
- X */
- X first();
- X second();
- X
- X exit((waserror) ? 1 : 0);
- }
- X
- first()
- {
- X /*
- X * Test strcmp first because we use it to test other things.
- X */
- X it = "strcmp";
- X check(strcmp("", "") == 0, 1); /* Trivial case. */
- X check(strcmp("a", "a") == 0, 2); /* Identity. */
- X check(strcmp("abc", "abc") == 0, 3); /* Multicharacter. */
- X check(strcmp("abc", "abcd") < 0, 4); /* Length mismatches. */
- X check(strcmp("abcd", "abc") > 0, 5);
- X check(strcmp("abcd", "abce") < 0, 6); /* Honest miscompares. */
- X check(strcmp("abce", "abcd") > 0, 7);
- X check(strcmp("a\203", "a") > 0, 8); /* Tricky if char signed. */
- X if (charsigned) /* Sign-bit comparison. */
- X check(strcmp("a\203", "a\003") < 0, 9);
- X else
- X check(strcmp("a\203", "a\003") > 0, 9);
- X check(strcmp("a", "a\203") < 0, 10); /* Tricky if char signed. */
- X
- X /*
- X * Test strcpy next because we need it to set up other tests.
- X */
- X it = "strcpy";
- X check(strcpy(one, "abcd") == one, 1); /* Returned value. */
- X equal(one, "abcd", 2); /* Basic test. */
- X
- X (void) strcpy(one, "x");
- X equal(one, "x", 3); /* Writeover. */
- X equal(one+2, "cd", 4); /* Wrote too much? */
- X
- X (void) strcpy(two, "hi there");
- X (void) strcpy(one, two);
- X equal(one, "hi there", 5); /* Basic test encore. */
- X equal(two, "hi there", 6); /* Stomped on source? */
- X
- X (void) strcpy(one, "");
- X equal(one, "", 7); /* Boundary condition. */
- X
- X /*
- X * strcat
- X */
- X it = "strcat";
- X (void) strcpy(one, "ijk");
- X check(strcat(one, "lmn") == one, 1); /* Returned value. */
- X equal(one, "ijklmn", 2); /* Basic test. */
- X
- X (void) strcpy(one, "x");
- X (void) strcat(one, "yz");
- X equal(one, "xyz", 3); /* Writeover. */
- X equal(one+4, "mn", 4); /* Wrote too much? */
- X
- X (void) strcpy(one, "gh");
- X (void) strcpy(two, "ef");
- X (void) strcat(one, two);
- X equal(one, "ghef", 5); /* Basic test encore. */
- X equal(two, "ef", 6); /* Stomped on source? */
- X
- X (void) strcpy(one, "");
- X (void) strcat(one, "");
- X equal(one, "", 7); /* Boundary conditions. */
- X (void) strcpy(one, "ab");
- X (void) strcat(one, "");
- X equal(one, "ab", 8);
- X (void) strcpy(one, "");
- X (void) strcat(one, "cd");
- X equal(one, "cd", 9);
- X
- X /*
- X * strncat - first test it as strcat, with big counts, then
- X * test the count mechanism.
- X */
- X it = "strncat";
- X (void) strcpy(one, "ijk");
- X check(strncat(one, "lmn", 99) == one, 1); /* Returned value. */
- X equal(one, "ijklmn", 2); /* Basic test. */
- X
- X (void) strcpy(one, "x");
- X (void) strncat(one, "yz", 99);
- X equal(one, "xyz", 3); /* Writeover. */
- X equal(one+4, "mn", 4); /* Wrote too much? */
- X
- X (void) strcpy(one, "gh");
- X (void) strcpy(two, "ef");
- X (void) strncat(one, two, 99);
- X equal(one, "ghef", 5); /* Basic test encore. */
- X equal(two, "ef", 6); /* Stomped on source? */
- X
- X (void) strcpy(one, "");
- X (void) strncat(one, "", 99);
- X equal(one, "", 7); /* Boundary conditions. */
- X (void) strcpy(one, "ab");
- X (void) strncat(one, "", 99);
- X equal(one, "ab", 8);
- X (void) strcpy(one, "");
- X (void) strncat(one, "cd", 99);
- X equal(one, "cd", 9);
- X
- X (void) strcpy(one, "ab");
- X (void) strncat(one, "cdef", 2);
- X equal(one, "abcd", 10); /* Count-limited. */
- X
- X (void) strncat(one, "gh", 0);
- X equal(one, "abcd", 11); /* Zero count. */
- X
- X (void) strncat(one, "gh", 2);
- X equal(one, "abcdgh", 12); /* Count and length equal. */
- X
- X /*
- X * strncmp - first test as strcmp with big counts, then test
- X * count code.
- X */
- X it = "strncmp";
- X check(strncmp("", "", 99) == 0, 1); /* Trivial case. */
- X check(strncmp("a", "a", 99) == 0, 2); /* Identity. */
- X check(strncmp("abc", "abc", 99) == 0, 3); /* Multicharacter. */
- X check(strncmp("abc", "abcd", 99) < 0, 4); /* Length unequal. */
- X check(strncmp("abcd", "abc", 99) > 0, 5);
- X check(strncmp("abcd", "abce", 99) < 0, 6); /* Honestly unequal. */
- X check(strncmp("abce", "abcd", 99) > 0, 7);
- X check(strncmp("a\203", "a", 2) > 0, 8); /* Tricky if '\203' < 0 */
- X if (charsigned) /* Sign-bit comparison. */
- X check(strncmp("a\203", "a\003", 2) < 0, 9);
- X else
- X check(strncmp("a\203", "a\003", 2) > 0, 9);
- X check(strncmp("abce", "abcd", 3) == 0, 10); /* Count limited. */
- X check(strncmp("abce", "abc", 3) == 0, 11); /* Count == length. */
- X check(strncmp("abcd", "abce", 4) < 0, 12); /* Nudging limit. */
- X check(strncmp("abc", "def", 0) == 0, 13); /* Zero count. */
- X
- X /*
- X * strncpy - testing is a bit different because of odd semantics
- X */
- X it = "strncpy";
- X check(strncpy(one, "abc", 4) == one, 1); /* Returned value. */
- X equal(one, "abc", 2); /* Did the copy go right? */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) strncpy(one, "xyz", 2);
- X equal(one, "xycdefgh", 3); /* Copy cut by count. */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) strncpy(one, "xyz", 3); /* Copy cut just before NUL. */
- X equal(one, "xyzdefgh", 4);
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) strncpy(one, "xyz", 4); /* Copy just includes NUL. */
- X equal(one, "xyz", 5);
- X equal(one+4, "efgh", 6); /* Wrote too much? */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) strncpy(one, "xyz", 5); /* Copy includes padding. */
- X equal(one, "xyz", 7);
- X equal(one+4, "", 8);
- X equal(one+5, "fgh", 9);
- X
- X (void) strcpy(one, "abc");
- X (void) strncpy(one, "xyz", 0); /* Zero-length copy. */
- X equal(one, "abc", 10);
- X
- X (void) strncpy(one, "", 2); /* Zero-length source. */
- X equal(one, "", 11);
- X equal(one+1, "", 12);
- X equal(one+2, "c", 13);
- X
- X (void) strcpy(one, "hi there");
- X (void) strncpy(two, one, 9);
- X equal(two, "hi there", 14); /* Just paranoia. */
- X equal(one, "hi there", 15); /* Stomped on source? */
- X
- X /*
- X * strlen
- X */
- X it = "strlen";
- X check(strlen("") == 0, 1); /* Empty. */
- X check(strlen("a") == 1, 2); /* Single char. */
- X check(strlen("abcd") == 4, 3); /* Multiple chars. */
- X
- X /*
- X * strchr
- X */
- X it = "strchr";
- X check(strchr("abcd", 'z') == NULL, 1); /* Not found. */
- X (void) strcpy(one, "abcd");
- X check(strchr(one, 'c') == one+2, 2); /* Basic test. */
- X check(strchr(one, 'd') == one+3, 3); /* End of string. */
- X check(strchr(one, 'a') == one, 4); /* Beginning. */
- X check(strchr(one, '\0') == one+4, 5); /* Finding NUL. */
- X (void) strcpy(one, "ababa");
- X check(strchr(one, 'b') == one+1, 6); /* Finding first. */
- X (void) strcpy(one, "");
- X check(strchr(one, 'b') == NULL, 7); /* Empty string. */
- X check(strchr(one, '\0') == one, 8); /* NUL in empty string. */
- X
- X /*
- X * index - just like strchr
- X */
- X it = "index";
- X check(index("abcd", 'z') == NULL, 1); /* Not found. */
- X (void) strcpy(one, "abcd");
- X check(index(one, 'c') == one+2, 2); /* Basic test. */
- X check(index(one, 'd') == one+3, 3); /* End of string. */
- X check(index(one, 'a') == one, 4); /* Beginning. */
- X check(index(one, '\0') == one+4, 5); /* Finding NUL. */
- X (void) strcpy(one, "ababa");
- X check(index(one, 'b') == one+1, 6); /* Finding first. */
- X (void) strcpy(one, "");
- X check(index(one, 'b') == NULL, 7); /* Empty string. */
- X check(index(one, '\0') == one, 8); /* NUL in empty string. */
- X
- X /*
- X * strrchr
- X */
- X it = "strrchr";
- X check(strrchr("abcd", 'z') == NULL, 1); /* Not found. */
- X (void) strcpy(one, "abcd");
- X check(strrchr(one, 'c') == one+2, 2); /* Basic test. */
- X check(strrchr(one, 'd') == one+3, 3); /* End of string. */
- X check(strrchr(one, 'a') == one, 4); /* Beginning. */
- X check(strrchr(one, '\0') == one+4, 5); /* Finding NUL. */
- X (void) strcpy(one, "ababa");
- X check(strrchr(one, 'b') == one+3, 6); /* Finding last. */
- X (void) strcpy(one, "");
- X check(strrchr(one, 'b') == NULL, 7); /* Empty string. */
- X check(strrchr(one, '\0') == one, 8); /* NUL in empty string. */
- X
- X /*
- X * rindex - just like strrchr
- X */
- X it = "rindex";
- X check(rindex("abcd", 'z') == NULL, 1); /* Not found. */
- X (void) strcpy(one, "abcd");
- X check(rindex(one, 'c') == one+2, 2); /* Basic test. */
- X check(rindex(one, 'd') == one+3, 3); /* End of string. */
- X check(rindex(one, 'a') == one, 4); /* Beginning. */
- X check(rindex(one, '\0') == one+4, 5); /* Finding NUL. */
- X (void) strcpy(one, "ababa");
- X check(rindex(one, 'b') == one+3, 6); /* Finding last. */
- X (void) strcpy(one, "");
- X check(rindex(one, 'b') == NULL, 7); /* Empty string. */
- X check(rindex(one, '\0') == one, 8); /* NUL in empty string. */
- }
- X
- second()
- {
- X /*
- X * strpbrk - somewhat like strchr
- X */
- X it = "strpbrk";
- X check(strpbrk("abcd", "z") == NULL, 1); /* Not found. */
- X (void) strcpy(one, "abcd");
- X check(strpbrk(one, "c") == one+2, 2); /* Basic test. */
- X check(strpbrk(one, "d") == one+3, 3); /* End of string. */
- X check(strpbrk(one, "a") == one, 4); /* Beginning. */
- X check(strpbrk(one, "") == NULL, 5); /* Empty search list. */
- X check(strpbrk(one, "cb") == one+1, 6); /* Multiple search. */
- X (void) strcpy(one, "abcabdea");
- X check(strpbrk(one, "b") == one+1, 7); /* Finding first. */
- X check(strpbrk(one, "cb") == one+1, 8); /* With multiple search. */
- X check(strpbrk(one, "db") == one+1, 9); /* Another variant. */
- X (void) strcpy(one, "");
- X check(strpbrk(one, "bc") == NULL, 10); /* Empty string. */
- X check(strpbrk(one, "") == NULL, 11); /* Both strings empty. */
- X
- #if 0
- X /*
- X * strstr - somewhat like strchr
- X */
- X it = "strstr";
- X check(strstr("abcd", "z") == NULL, 1); /* Not found. */
- X check(strstr("abcd", "abx") == NULL, 2); /* Dead end. */
- X (void) strcpy(one, "abcd");
- X check(strstr(one, "c") == one+2, 3); /* Basic test. */
- X check(strstr(one, "bc") == one+1, 4); /* Multichar. */
- X check(strstr(one, "d") == one+3, 5); /* End of string. */
- X check(strstr(one, "cd") == one+2, 6); /* Tail of string. */
- X check(strstr(one, "abc") == one, 7); /* Beginning. */
- X check(strstr(one, "abcd") == one, 8); /* Exact match. */
- X check(strstr(one, "abcde") == NULL, 9); /* Too long. */
- X check(strstr(one, "de") == NULL, 10); /* Past end. */
- X check(strstr(one, "") == one+4, 11); /* Finding empty. */
- X (void) strcpy(one, "ababa");
- X check(strstr(one, "ba") == one+1, 12); /* Finding first. */
- X (void) strcpy(one, "");
- X check(strstr(one, "b") == NULL, 13); /* Empty string. */
- X check(strstr(one, "") == one, 14); /* Empty in empty string. */
- X (void) strcpy(one, "bcbca");
- X check(strstr(one, "bca") == one+2, 15); /* False start. */
- X (void) strcpy(one, "bbbcabbca");
- X check(strstr(one, "bbca") == one+1, 16); /* With overlap. */
- #endif
- X
- X /*
- X * strspn
- X */
- X it = "strspn";
- X check(strspn("abcba", "abc") == 5, 1); /* Whole string. */
- X check(strspn("abcba", "ab") == 2, 2); /* Partial. */
- X check(strspn("abc", "qx") == 0, 3); /* None. */
- X check(strspn("", "ab") == 0, 4); /* Null string. */
- X check(strspn("abc", "") == 0, 5); /* Null search list. */
- X
- X /*
- X * strcspn
- X */
- X it = "strcspn";
- X check(strcspn("abcba", "qx") == 5, 1); /* Whole string. */
- X check(strcspn("abcba", "cx") == 2, 2); /* Partial. */
- X check(strcspn("abc", "abc") == 0, 3); /* None. */
- X check(strcspn("", "ab") == 0, 4); /* Null string. */
- X check(strcspn("abc", "") == 3, 5); /* Null search list. */
- X
- X /*
- X * strtok - the hard one
- X */
- X it = "strtok";
- X (void) strcpy(one, "first, second, third");
- X equal(strtok(one, ", "), "first", 1); /* Basic test. */
- X equal(one, "first", 2);
- X equal(strtok((char *)NULL, ", "), "second", 3);
- X equal(strtok((char *)NULL, ", "), "third", 4);
- X check(strtok((char *)NULL, ", ") == NULL, 5);
- X (void) strcpy(one, ", first, ");
- X equal(strtok(one, ", "), "first", 6); /* Extra delims, 1 tok. */
- X check(strtok((char *)NULL, ", ") == NULL, 7);
- X (void) strcpy(one, "1a, 1b; 2a, 2b");
- X equal(strtok(one, ", "), "1a", 8); /* Changing delim lists. */
- X equal(strtok((char *)NULL, "; "), "1b", 9);
- X equal(strtok((char *)NULL, ", "), "2a", 10);
- X (void) strcpy(two, "x-y");
- X equal(strtok(two, "-"), "x", 11); /* New string before done. */
- X equal(strtok((char *)NULL, "-"), "y", 12);
- X check(strtok((char *)NULL, "-") == NULL, 13);
- X (void) strcpy(one, "a,b, c,, ,d");
- X equal(strtok(one, ", "), "a", 14); /* Different separators. */
- X equal(strtok((char *)NULL, ", "), "b", 15);
- X equal(strtok((char *)NULL, " ,"), "c", 16); /* Permute list too. */
- X equal(strtok((char *)NULL, " ,"), "d", 17);
- X check(strtok((char *)NULL, ", ") == NULL, 18);
- X check(strtok((char *)NULL, ", ") == NULL, 19); /* Persistence. */
- X (void) strcpy(one, ", ");
- X check(strtok(one, ", ") == NULL, 20); /* No tokens. */
- X (void) strcpy(one, "");
- X check(strtok(one, ", ") == NULL, 21); /* Empty string. */
- X (void) strcpy(one, "abc");
- X equal(strtok(one, ", "), "abc", 22); /* No delimiters. */
- X check(strtok((char *)NULL, ", ") == NULL, 23);
- X (void) strcpy(one, "abc");
- X equal(strtok(one, ""), "abc", 24); /* Empty delimiter list. */
- X check(strtok((char *)NULL, "") == NULL, 25);
- X (void) strcpy(one, "abcdefgh");
- X (void) strcpy(one, "a,b,c");
- X equal(strtok(one, ","), "a", 26); /* Basics again... */
- X equal(strtok((char *)NULL, ","), "b", 27);
- X equal(strtok((char *)NULL, ","), "c", 28);
- X check(strtok((char *)NULL, ",") == NULL, 29);
- X equal(one+6, "gh", 30); /* Stomped past end? */
- X equal(one, "a", 31); /* Stomped old tokens? */
- X equal(one+2, "b", 32);
- X equal(one+4, "c", 33);
- X
- X /*
- X * memcmp
- X */
- X it = "memcmp";
- X check(memcmp("a", "a", 1) == 0, 1); /* Identity. */
- X check(memcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */
- X check(memcmp("abcd", "abce", 4) < 0, 3); /* Honestly unequal. */
- X check(memcmp("abce", "abcd", 4) > 0, 4);
- X check(memcmp("alph", "beta", 4) < 0, 5);
- X if (charsigned) /* Sign-bit comparison. */
- X check(memcmp("a\203", "a\003", 2) < 0, 6);
- X else
- X check(memcmp("a\203", "a\003", 2) > 0, 6);
- X check(memcmp("abce", "abcd", 3) == 0, 7); /* Count limited. */
- X check(memcmp("abc", "def", 0) == 0, 8); /* Zero count. */
- X
- X /*
- X * memchr
- X */
- X it = "memchr";
- X check(memchr("abcd", 'z', 4) == NULL, 1); /* Not found. */
- X (void) strcpy(one, "abcd");
- X check(memchr(one, 'c', 4) == one+2, 2); /* Basic test. */
- X check(memchr(one, 'd', 4) == one+3, 3); /* End of string. */
- X check(memchr(one, 'a', 4) == one, 4); /* Beginning. */
- X check(memchr(one, '\0', 5) == one+4, 5); /* Finding NUL. */
- X (void) strcpy(one, "ababa");
- X check(memchr(one, 'b', 5) == one+1, 6); /* Finding first. */
- X check(memchr(one, 'b', 0) == NULL, 7); /* Zero count. */
- X check(memchr(one, 'a', 1) == one, 8); /* Singleton case. */
- X (void) strcpy(one, "a\203b");
- X check(memchr(one, 0203, 3) == one+1, 9); /* Unsignedness. */
- X
- X /*
- X * memcpy
- X *
- X * Note that X3J11 says memcpy must work regardless of overlap.
- X * The SVID says it might fail.
- X */
- X it = "memcpy";
- X check(memcpy(one, "abc", 4) == one, 1); /* Returned value. */
- X equal(one, "abc", 2); /* Did the copy go right? */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) memcpy(one+1, "xyz", 2);
- X equal(one, "axydefgh", 3); /* Basic test. */
- X
- X (void) strcpy(one, "abc");
- X (void) memcpy(one, "xyz", 0);
- X equal(one, "abc", 4); /* Zero-length copy. */
- X
- X (void) strcpy(one, "hi there");
- X (void) strcpy(two, "foo");
- X (void) memcpy(two, one, 9);
- X equal(two, "hi there", 5); /* Just paranoia. */
- X equal(one, "hi there", 6); /* Stomped on source? */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) memcpy(one+1, one, 9);
- X equal(one, "aabcdefgh", 7); /* Overlap, right-to-left. */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) memcpy(one+1, one+2, 7);
- X equal(one, "acdefgh", 8); /* Overlap, left-to-right. */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) memcpy(one, one, 9);
- X equal(one, "abcdefgh", 9); /* 100% overlap. */
- X
- X /*
- X * memccpy - first test like memcpy, then the search part
- X *
- X * The SVID, the only place where memccpy is mentioned, says
- X * overlap might fail, so we don't try it. Besides, it's hard
- X * to see the rationale for a non-left-to-right memccpy.
- X */
- X it = "memccpy";
- X check(memccpy(one, "abc", 'q', 4) == NULL, 1); /* Returned value. */
- X equal(one, "abc", 2); /* Did the copy go right? */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) memccpy(one+1, "xyz", 'q', 2);
- X equal(one, "axydefgh", 3); /* Basic test. */
- X
- X (void) strcpy(one, "abc");
- X (void) memccpy(one, "xyz", 'q', 0);
- X equal(one, "abc", 4); /* Zero-length copy. */
- X
- X (void) strcpy(one, "hi there");
- X (void) strcpy(two, "foo");
- X (void) memccpy(two, one, 'q', 9);
- X equal(two, "hi there", 5); /* Just paranoia. */
- X equal(one, "hi there", 6); /* Stomped on source? */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) strcpy(two, "horsefeathers");
- X check(memccpy(two, one, 'f', 9) == two+6, 7); /* Returned value. */
- X equal(one, "abcdefgh", 8); /* Source intact? */
- X equal(two, "abcdefeathers", 9); /* Copy correct? */
- X
- X (void) strcpy(one, "abcd");
- X (void) strcpy(two, "bumblebee");
- X check(memccpy(two, one, 'a', 4) == two+1, 10); /* First char. */
- X equal(two, "aumblebee", 11);
- X check(memccpy(two, one, 'd', 4) == two+4, 12); /* Last char. */
- X equal(two, "abcdlebee", 13);
- X (void) strcpy(one, "xyz");
- X check(memccpy(two, one, 'x', 1) == two+1, 14); /* Singleton. */
- X equal(two, "xbcdlebee", 15);
- X
- X /*
- X * memset
- X */
- X it = "memset";
- X (void) strcpy(one, "abcdefgh");
- X check(memset(one+1, 'x', 3) == one+1, 1); /* Return value. */
- X equal(one, "axxxefgh", 2); /* Basic test. */
- X
- X (void) memset(one+2, 'y', 0);
- X equal(one, "axxxefgh", 3); /* Zero-length set. */
- X
- X (void) memset(one+5, 0, 1);
- X equal(one, "axxxe", 4); /* Zero fill. */
- X equal(one+6, "gh", 5); /* And the leftover. */
- X
- X (void) memset(one+2, 010045, 1);
- X equal(one, "ax\045xe", 6); /* Unsigned char convert. */
- X
- X /*
- X * bcopy - much like memcpy
- X *
- X * Berklix manual is silent about overlap, so don't test it.
- X */
- X it = "bcopy";
- X (void) bcopy("abc", one, 4);
- X equal(one, "abc", 1); /* Simple copy. */
- X
- X (void) strcpy(one, "abcdefgh");
- X (void) bcopy("xyz", one+1, 2);
- X equal(one, "axydefgh", 2); /* Basic test. */
- X
- X (void) strcpy(one, "abc");
- X (void) bcopy("xyz", one, 0);
- X equal(one, "abc", 3); /* Zero-length copy. */
- X
- X (void) strcpy(one, "hi there");
- X (void) strcpy(two, "foo");
- X (void) bcopy(one, two, 9);
- X equal(two, "hi there", 4); /* Just paranoia. */
- X equal(one, "hi there", 5); /* Stomped on source? */
- X
- X /*
- X * bzero
- X */
- X it = "bzero";
- X (void) strcpy(one, "abcdef");
- X bzero(one+2, 2);
- X equal(one, "ab", 1); /* Basic test. */
- X equal(one+3, "", 2);
- X equal(one+4, "ef", 3);
- X
- X (void) strcpy(one, "abcdef");
- X bzero(one+2, 0);
- X equal(one, "abcdef", 4); /* Zero-length copy. */
- X
- X /*
- X * bcmp - somewhat like memcmp
- X */
- X it = "bcmp";
- X check(bcmp("a", "a", 1) == 0, 1); /* Identity. */
- X check(bcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */
- X check(bcmp("abcd", "abce", 4) != 0, 3); /* Honestly unequal. */
- X check(bcmp("abce", "abcd", 4) != 0, 4);
- X check(bcmp("alph", "beta", 4) != 0, 5);
- X check(bcmp("abce", "abcd", 3) == 0, 6); /* Count limited. */
- X check(bcmp("abc", "def", 0) == 0, 8); /* Zero count. */
- X
- #ifdef ERR
- X /*
- X * strerror - VERY system-dependent
- X */
- X it = "strerror";
- X f = open("/", 1); /* Should always fail. */
- X check(f < 0 && errno > 0 && errno < sys_nerr, 1);
- X equal(strerror(errno), sys_errlist[errno], 2);
- #ifdef UNIXERR
- X equal(strerror(errno), "Is a directory", 3);
- #endif
- #ifdef BERKERR
- X equal(strerror(errno), "Permission denied", 3);
- #endif
- #endif
- }
- SHAR_EOF
- chmod 0640 dmake/dbug/malloc/testmem.c ||
- echo 'restore of dmake/dbug/malloc/testmem.c failed'
- Wc_c="`wc -c < 'dmake/dbug/malloc/testmem.c'`"
- test 20192 -eq "$Wc_c" ||
- echo 'dmake/dbug/malloc/testmem.c: original size 20192, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= dmake/dbug/malloc/testmlc.c ==============
- if test -f 'dmake/dbug/malloc/testmlc.c' -a X"$1" != X"-c"; then
- echo 'x - skipping dmake/dbug/malloc/testmlc.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- sed 's/^X//' << 'SHAR_EOF' > 'dmake/dbug/malloc/testmlc.c' &&
- /* NOT copyright by SoftQuad Inc. -- msb, 1988 */
- SHAR_EOF
- true || echo 'restore of dmake/dbug/malloc/testmlc.c failed'
- fi
- echo 'End of part 6, continue with part 7'
- echo 7 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
-