OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [string/] [strcat.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*
/*
FUNCTION
FUNCTION
        <<strcat>>---concatenate strings
        <<strcat>>---concatenate strings
 
 
INDEX
INDEX
        strcat
        strcat
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <string.h>
        #include <string.h>
        char *strcat(char *<[dst]>, const char *<[src]>);
        char *strcat(char *<[dst]>, const char *<[src]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <string.h>
        #include <string.h>
        char *strcat(<[dst]>, <[src]>)
        char *strcat(<[dst]>, <[src]>)
        char *<[dst]>;
        char *<[dst]>;
        char *<[src]>;
        char *<[src]>;
 
 
DESCRIPTION
DESCRIPTION
        <<strcat>> appends a copy of the string pointed to by <[src]>
        <<strcat>> appends a copy of the string pointed to by <[src]>
        (including the terminating null character) to the end of the
        (including the terminating null character) to the end of the
        string pointed to by <[dst]>.  The initial character of
        string pointed to by <[dst]>.  The initial character of
        <[src]> overwrites the null character at the end of <[dst]>.
        <[src]> overwrites the null character at the end of <[dst]>.
 
 
RETURNS
RETURNS
        This function returns the initial value of <[dst]>
        This function returns the initial value of <[dst]>
 
 
PORTABILITY
PORTABILITY
<<strcat>> is ANSI C.
<<strcat>> is ANSI C.
 
 
<<strcat>> requires no supporting OS subroutines.
<<strcat>> requires no supporting OS subroutines.
 
 
QUICKREF
QUICKREF
        strcat ansi pure
        strcat ansi pure
*/
*/
 
 
#include <string.h>
#include <string.h>
#include <limits.h>
#include <limits.h>
 
 
/* Nonzero if X is aligned on a "long" boundary.  */
/* Nonzero if X is aligned on a "long" boundary.  */
#define ALIGNED(X) \
#define ALIGNED(X) \
  (((long)X & (sizeof (long) - 1)) == 0)
  (((long)X & (sizeof (long) - 1)) == 0)
 
 
#if LONG_MAX == 2147483647L
#if LONG_MAX == 2147483647L
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
#else
#else
#if LONG_MAX == 9223372036854775807L
#if LONG_MAX == 9223372036854775807L
/* Nonzero if X (a long int) contains a NULL byte. */
/* Nonzero if X (a long int) contains a NULL byte. */
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
#else
#else
#error long int is not a 32bit or 64bit type.
#error long int is not a 32bit or 64bit type.
#endif
#endif
#endif
#endif
 
 
#ifndef DETECTNULL
#ifndef DETECTNULL
#error long int is not a 32bit or 64bit byte
#error long int is not a 32bit or 64bit byte
#endif
#endif
 
 
 
 
/*SUPPRESS 560*/
/*SUPPRESS 560*/
/*SUPPRESS 530*/
/*SUPPRESS 530*/
 
 
char *
char *
_DEFUN (strcat, (s1, s2),
_DEFUN (strcat, (s1, s2),
        char *s1 _AND
        char *s1 _AND
        _CONST char *s2)
        _CONST char *s2)
{
{
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
  char *s = s1;
  char *s = s1;
 
 
  while (*s1)
  while (*s1)
    s1++;
    s1++;
 
 
  while (*s1++ = *s2++)
  while (*s1++ = *s2++)
    ;
    ;
  return s;
  return s;
#else
#else
  char *s = s1;
  char *s = s1;
 
 
 
 
  /* Skip over the data in s1 as quickly as possible.  */
  /* Skip over the data in s1 as quickly as possible.  */
  if (ALIGNED (s1))
  if (ALIGNED (s1))
    {
    {
      unsigned long *aligned_s1 = (unsigned long *)s1;
      unsigned long *aligned_s1 = (unsigned long *)s1;
      while (!DETECTNULL (*aligned_s1))
      while (!DETECTNULL (*aligned_s1))
        aligned_s1++;
        aligned_s1++;
 
 
      s1 = (char *)aligned_s1;
      s1 = (char *)aligned_s1;
    }
    }
 
 
  while (*s1)
  while (*s1)
    s1++;
    s1++;
 
 
  /* s1 now points to the its trailing null character, we can
  /* s1 now points to the its trailing null character, we can
     just use strcpy to do the work for us now.
     just use strcpy to do the work for us now.
 
 
     ?!? We might want to just include strcpy here.
     ?!? We might want to just include strcpy here.
     Also, this will cause many more unaligned string copies because
     Also, this will cause many more unaligned string copies because
     s1 is much less likely to be aligned.  I don't know if its worth
     s1 is much less likely to be aligned.  I don't know if its worth
     tweaking strcpy to handle this better.  */
     tweaking strcpy to handle this better.  */
  strcpy (s1, s2);
  strcpy (s1, s2);
 
 
  return s;
  return s;
#endif /* not PREFER_SIZE_OVER_SPEED */
#endif /* not PREFER_SIZE_OVER_SPEED */
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.