Back to index

glibc  2.9
Defines | Functions
stpncpy.c File Reference
#include <sys/types.h>

Go to the source code of this file.

Defines

#define __stpncpy   stpncpy

Functions

char * __stpncpy (char *dest, const char *src, size_t n)

Define Documentation

#define __stpncpy   stpncpy

Definition at line 32 of file stpncpy.c.


Function Documentation

char* __stpncpy ( char *  dest,
const char *  src,
size_t  n 
)

Definition at line 38 of file stpncpy.c.

{
  char c;
  char *s = dest;

  if (n >= 4)
    {
      size_t n4 = n >> 2;

      for (;;)
       {
         c = *src++;
         *dest++ = c;
         if (c == '\0')
           break;
         c = *src++;
         *dest++ = c;
         if (c == '\0')
           break;
         c = *src++;
         *dest++ = c;
         if (c == '\0')
           break;
         c = *src++;
         *dest++ = c;
         if (c == '\0')
           break;
         if (--n4 == 0)
           goto last_chars;
       }
      n -= dest - s;
      goto zero_fill;
    }

 last_chars:
  n &= 3;
  if (n == 0)
    return dest;

  for (;;)
    {
      c = *src++;
      --n;
      *dest++ = c;
      if (c == '\0')
       break;
      if (n == 0)
       return dest;
    }

 zero_fill:
  while (n-- > 0)
    dest[n] = '\0';

  return dest - 1;
}

Here is the caller graph for this function: