Back to index

glibc  2.9
Functions
strcpy_chk.c File Reference
#include <stddef.h>
#include <string.h>
#include <memcopy.h>

Go to the source code of this file.

Functions

char * __strcpy_chk (char *dest, const char *src, size_t destlen)

Function Documentation

char* __strcpy_chk ( char *  dest,
const char *  src,
size_t  destlen 
)

Definition at line 27 of file strcpy_chk.c.

{
  reg_char c;
  char *s = (char *) src;
  const ptrdiff_t off = dest - s;

  while (__builtin_expect (destlen >= 4, 0))
    {
      c = s[0];
      s[off] = c;
      if (c == '\0')
        return dest;
      c = s[1];
      s[off + 1] = c;
      if (c == '\0')
        return dest;
      c = s[2];
      s[off + 2] = c;
      if (c == '\0')
        return dest;
      c = s[3];
      s[off + 3] = c;
      if (c == '\0')
        return dest;
      destlen -= 4;
      s += 4;
    }

  do
    {
      if (__builtin_expect (destlen-- == 0, 0))
        __chk_fail ();
      c = *s;
      *(s++ + off) = c;
    }
  while (c != '\0');

  return dest;
}

Here is the call graph for this function: