Mon Sep 20 2010 00:33:59

Asterisk developer's documentation


Functions

main/strcompat.c File Reference

Compatibility functions for strsep and strtoq missing on Solaris. More...

#include "asterisk.h"
#include <ctype.h>
Include dependency graph for main/strcompat.c:

Go to the source code of this file.

Functions

size_t strlcat (char *dst, const char *src, size_t siz)
size_t strlcpy (char *dst, const char *src, size_t siz)

Detailed Description

Compatibility functions for strsep and strtoq missing on Solaris.

Definition in file main/strcompat.c.


Function Documentation

size_t strlcat ( char *  dst,
const char *  src,
size_t  siz 
)

Definition at line 375 of file main/strcompat.c.

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

   /* Find the end of dst and adjust bytes left but don't go past end */
   while (n-- != 0 && *d != '\0')
      d++;
   dlen = d - dst;
   n = siz - dlen;

   if (n == 0)
      return dlen + strlen(s);

   while (*s != '\0') {
      if (n != 1) {
         *d++ = *s;
         n--;
      }
      s++;
   }
   *d = '\0';

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

size_t strlcpy ( char *  dst,
const char *  src,
size_t  siz 
)

Definition at line 439 of file main/strcompat.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 */
}