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

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [common/] [string.c] - Diff between revs 175 and 406

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 175 Rev 406
Line 49... Line 49...
char *strcpy(char *dest, const char *src)
char *strcpy(char *dest, const char *src)
{
{
  char *d = dest;
  char *d = dest;
 
 
  /* copy src to dest */
  /* copy src to dest */
  while ( (*dest++ = *src++) )
        while ((*dest++ = *src++)) ;
  ;
 
 
 
  return d;
  return d;
}
}
 
 
 
 
char *strncpy(char *dest, const char *src, size_t n)
char *strncpy(char *dest, const char *src, size_t n)
{
{
  char *d = dest;
  char *d = dest;
 
 
  /* copy src to dest */
  /* copy src to dest */
Line 73... Line 71...
    *dest++ = '\0';
    *dest++ = '\0';
 
 
  return d;
  return d;
}
}
 
 
 
 
char *strcat(char *dest, const char *src)
char *strcat(char *dest, const char *src)
{
{
  char *d = dest;
  char *d = dest;
 
 
  /* find the end of the destination string */
  /* find the end of the destination string */
  while (*dest++)
        while (*dest++) ;
  ;
 
 
 
  /* append the source string to the destination string */
  /* append the source string to the destination string */
  while ( (*dest++ = *src++) )
        while ((*dest++ = *src++)) ;
  ;
 
 
 
  return d;
  return d;
}
}
 
 
 
 
char *strncat(char *dest, const char *src, size_t n)
char *strncat(char *dest, const char *src, size_t n)
{
{
  char *d = dest;
  char *d = dest;
 
 
  /* find the end of the destination string */
  /* find the end of the destination string */
  while (*dest++)
        while (*dest++) ;
  ;
 
 
 
  /* copy src to dest */
  /* copy src to dest */
  while ( (*dest = *src) && n-- ) {
  while ( (*dest = *src) && n-- ) {
    dest++;
    dest++;
    src++;
    src++;
  }
  }
 
 
 
 
  /* add terminating '\0' character */
  /* add terminating '\0' character */
  *dest = '\0';
  *dest = '\0';
 
 
  return d;
  return d;
}
}
 
 
 
 
int strcmp(const char *s1, const char *s2)
int strcmp(const char *s1, const char *s2)
{
{
  while ( *s1 && (*s1 == *s2) ) {
  while ( *s1 && (*s1 == *s2) ) {
    s1++;
    s1++;
    s2++;
    s2++;
  }
  }
 
 
  return *s1 - *s2;
  return *s1 - *s2;
}
}
 
 
 
 
int strncmp(const char *s1, const char *s2, size_t n)
int strncmp(const char *s1, const char *s2, size_t n)
{
{
  while ( *s1 && (*s1 == *s2) && n-- ) {
  while ( *s1 && (*s1 == *s2) && n-- ) {
    s1++;
    s1++;
    s2++;
    s2++;
  }
  }
 
 
  return *s1 - *s2;
  return *s1 - *s2;
}
}
 
 
 
 
char *strchr(const char *s, int c)
char *strchr(const char *s, int c)
{
{
  /* search for the character c */
  /* search for the character c */
  while (*s && (*s != c) )
  while (*s && (*s != c) )
    s++;
    s++;
 
 
  return (char *)s;
  return (char *)s;
}
}
 
 
 
 
char *strrchr(const char *s, int c)
char *strrchr(const char *s, int c)
{
{
  char *fnd = NULL;
  char *fnd = NULL;
 
 
  /* search for the character c */
  /* search for the character c */
Line 158... Line 146...
  }
  }
 
 
  return fnd;
  return fnd;
}
}
 
 
 
 
/* Basic mem functions */
/* Basic mem functions */
void *memcpy(void *dest, const void *src, size_t n)
void *memcpy(void *dest, const void *src, size_t n)
{
{
  /* check if 'src' and 'dest' are on LONG boundaries */
  /* check if 'src' and 'dest' are on LONG boundaries */
  if ( (sizeof(unsigned long) -1) & ((unsigned long)dest | (unsigned long)src) )
        if ((sizeof(unsigned long) -
  {
             1) & ((unsigned long)dest | (unsigned long)src)) {
      /* no, do a byte-wide copy */
      /* no, do a byte-wide copy */
      char *cs = (char *) src;
      char *cs = (char *) src;
      char *cd = (char *) dest;
      char *cd = (char *) dest;
 
 
      while (n--)
      while (n--)
          *cd++ = *cs++;
          *cd++ = *cs++;
  }
        } else {
  else
 
  {
 
      /* yes, speed up copy process */
      /* yes, speed up copy process */
      /* copy as many LONGs as possible */
      /* copy as many LONGs as possible */
      long *ls = (long *)src;
      long *ls = (long *)src;
      long *ld = (long *)dest;
      long *ld = (long *)dest;
 
 
Line 204... Line 189...
  unsigned char tmp;
  unsigned char tmp;
 
 
  char *cs = (char *) src;
  char *cs = (char *) src;
  char *cd = (char *) dest;
  char *cd = (char *) dest;
 
 
  while (n--)
        while (n--) {
    {
 
      tmp = *cs++;
      tmp = *cs++;
      sum += tmp;
      sum += tmp;
      *cd++ = tmp;
      *cd++ = tmp;
    }
    }
  return sum;
  return sum;
Line 224... Line 208...
    *d++ = *s++;
    *d++ = *s++;
 
 
  return dest;
  return dest;
}
}
 
 
 
 
int memcmp(const void *s1, const void *s2, size_t n)
int memcmp(const void *s1, const void *s2, size_t n)
{
{
  char *p1 = (void *)s1;
  char *p1 = (void *)s1;
  char *p2 = (void *)s2;
  char *p2 = (void *)s2;
 
 
Line 238... Line 221...
  }
  }
 
 
  return *p1 - *p2;
  return *p1 - *p2;
}
}
 
 
 
 
void *memchr(const void *s, char c, size_t n)
void *memchr(const void *s, char c, size_t n)
{
{
  char *p = (void *)s;
  char *p = (void *)s;
 
 
  /* search for the character c */
  /* search for the character c */
Line 250... Line 232...
    p++;
    p++;
 
 
  return (*p == c) ? p : NULL;
  return (*p == c) ? p : NULL;
}
}
 
 
 
 
void *memset(void *s, int c, size_t n)
void *memset(void *s, int c, size_t n)
{
{
  char *p = s;
  char *p = s;
 
 
  while (n--)
  while (n--)

powered by: WebSVN 2.1.0

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