Sat Aug 6 00:40:05 2011

Asterisk developer's documentation


main/strcompat.c File Reference

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

#include "asterisk.h"
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <alloca.h>

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 397 of file main/strcompat.c.

00398 {
00399    register char *d = dst;
00400    register const char *s = src;
00401    register size_t n = siz;
00402    size_t dlen;
00403 
00404    /* Find the end of dst and adjust bytes left but don't go past end */
00405    while (n-- != 0 && *d != '\0')
00406       d++;
00407    dlen = d - dst;
00408    n = siz - dlen;
00409 
00410    if (n == 0)
00411       return dlen + strlen(s);
00412 
00413    while (*s != '\0') {
00414       if (n != 1) {
00415          *d++ = *s;
00416          n--;
00417       }
00418       s++;
00419    }
00420    *d = '\0';
00421 
00422    return dlen + (s - src);   /* count does not include NUL */
00423 }

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

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

00462 {
00463    register char *d = dst;
00464    register const char *s = src;
00465    register size_t n = siz;
00466 
00467    /* Copy as many bytes as will fit */
00468    if (n != 0 && --n != 0) {
00469       do {
00470          if ((*d++ = *s++) == 0)
00471             break;
00472       } while (--n != 0);
00473    }
00474 
00475    /* Not enough room in dst, add NUL and traverse rest of src */
00476    if (n == 0) {
00477       if (siz != 0)
00478          *d = '\0';     /* NUL-terminate dst */
00479       while (*s++)
00480          ;
00481    }
00482 
00483    return s - src - 1;  /* count does not include NUL */
00484 }


Generated on Sat Aug 6 00:40:05 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7