Back to index

php5  5.3.10
Functions
strlcpy.c File Reference
#include "php.h"
#include <sys/types.h>
#include <string.h>

Go to the source code of this file.

Functions

PHPAPI size_t php_strlcpy (char *dst, const char *src, size_t siz)

Function Documentation

PHPAPI size_t php_strlcpy ( char *  dst,
const char *  src,
size_t  siz 
)

Definition at line 66 of file strlcpy.c.

{
       register char *d = dst;
       register const char *s = src;
       register size_t n = siz;

       /* Copy as many bytes as will fit */
       if (n != 0 && --n != 0) {
              do {
                     if ((*d++ = *s++) == 0)
                            break;
              } while (--n != 0);
       }

       /* Not enough room in dst, add NUL and traverse rest of src */
       if (n == 0) {
              if (siz != 0)
                     *d = '\0';           /* NUL-terminate dst */
              while (*s++)
                     ;
       }

       return(s - src - 1); /* count does not include NUL */
}