/*
 * Quelques fonctions UNIX qui n'existent pas sur l'Aztec
 * (c)1991 par Denis GOUNELLE
 */

long strtol( str , ptr , base )
register unsigned char *str ;
unsigned char **ptr ;
long base ;

{
  register long result, sign , digit ;

  sign = 1 ;
  result = 0 ;

/* passe les espaces en tête */

  while ( isspace( *str ) ) str++ ;

/* regarde s'il y a un signe */

  if ( *str == '-' )
  {
    sign = -1 ;
    str++ ;
  }
  else if ( *str == '+' ) str++ ;

/* decode le nombre */

  while ( isascii( *str ) && isalnum( *str ) )
  {
    digit = (long)toupper( *str ) - 48 ;
    if ( digit > 9 ) digit -= 7 ;
    if ( digit > base ) break ;
    result *= base ;
    result += digit ;
    str++ ;
  }

  if ( ptr ) *ptr = str ;
  if ( sign < 0 ) result = - result ;
  return( result ) ;
}

/****************************************************************************
 *
 * bzero() and bcopy() have been rewritten in assembly language : that makes
 * ARoff about 2 times faster...
 * I've left the old C fonction code so that you can see what they do
 *
 ****************************************************************************

void bzero( ptr , len )
register char *ptr ;
register long len ;

{
  while ( len > 0 )
  {
    *ptr = '\0' ;
    ptr++ ;
    len-- ;
  }
}

void bcopy( src , dst , len )
register char *src , *dst ;
register long len ;

{
  while ( len > 0 )
  {
    *dst = *src ;
    dst++ ;
    src++ ;
    len-- ;
  }
}
*****************************************************************************/

#asm

_bzero:
	move.l	4(sp),a0
	move.l	8(sp),d0
	beq.s	_bzend
	subq.l	#1,d0
	moveq	#0,d1
_bzbcl:
	move.b	d1,(a0)+
	dbra	d0,_bzbcl
_bzend:
	rts
_bcopy:
	move.l	4(sp),a0
	move.l	8(sp),a1
	move.l	12(sp),d1
	beq.s	_bcend
	subq.l	#1,d1
_bcbcl:
	move.b	(a0)+,(a1)+
	dbra	d1,_bcbcl
_bcend:
	rts
;
	public	_bzero
	public	_bcopy

#endasm

/*************************************************************************/

#ifdef AZTEC_C

long Chk_Abort()
{
  return( 0 ) ;
}

#endif

