#include <stdio.h>
#include <string.h>
#include "strlcpy.h"
 
Go to the source code of this file.
 | 
| size_t  | strlcpy (char *dst, const char *src, size_t size) | 
|   | 
| size_t  | strlcat (char *dst, const char *src, size_t size) | 
|   | 
◆ strlcpy()
      
        
          | size_t strlcpy  | 
          ( | 
          char * |           dst,  | 
        
        
           | 
           | 
          const char * |           src,  | 
        
        
           | 
           | 
          size_t |           size ) | 
        
      
 
Definition at line 39 of file strlcpy.cc.
   40{
   41  char *d = dst;
   42  const char *s = src;
   44 
   45  
   46  if (n != 0 && --n != 0) {
   47    do {
   48      if ((*d++ = *s++) == 0)
   49        break;
   50    } while (--n != 0);
   51  }
   52 
   53  
   54  if (n == 0) {
   55    if (size != 0)
   56      *d = '\0';             
   57    while (*s++);
   58  }
   59 
   60  return (s - src - 1);        
   61}
 
 
 
◆ strlcat()
      
        
          | size_t strlcat  | 
          ( | 
          char * |           dst,  | 
        
        
           | 
           | 
          const char * |           src,  | 
        
        
           | 
           | 
          size_t |           size ) | 
        
      
 
Definition at line 72 of file strlcpy.cc.
   73{
   74  char *d = dst;
   75  const char *s = src;
   77  size_t dlen;
   78 
   79  
   80  while (n-- != 0 && *d != '\0')
   81    d++;
   82  dlen = d - dst;
   84 
   85  if (n == 0)
   86    return (dlen + strlen(s));
   87  while (*s != '\0') {
   88    if (n != 1) {
   89      *d++ = *s;
   91    }
   92    s++;
   93  }
   94  *d = '\0';
   95 
   96  return (dlen + (s - src));   
   97}