Fri Apr 24 16:26:29 2009

Asterisk developer's documentation


compat.h File Reference

General Definitions for Asterisk top level program. More...

#include "asterisk/autoconfig.h"
#include <inttypes.h>
#include <sys/types.h>
#include <stdarg.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

General Definitions for Asterisk top level program.

Definition in file compat.h.


Function Documentation

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

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

00385 {
00386    register char *d = dst;
00387    register const char *s = src;
00388    register size_t n = siz;
00389    size_t dlen;
00390 
00391    /* Find the end of dst and adjust bytes left but don't go past end */
00392    while (n-- != 0 && *d != '\0')
00393       d++;
00394    dlen = d - dst;
00395    n = siz - dlen;
00396 
00397    if (n == 0)
00398       return dlen + strlen(s);
00399 
00400    while (*s != '\0') {
00401       if (n != 1) {
00402          *d++ = *s;
00403          n--;
00404       }
00405       s++;
00406    }
00407    *d = '\0';
00408 
00409    return dlen + (s - src);   /* count does not include NUL */
00410 }

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

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

00449 {
00450    register char *d = dst;
00451    register const char *s = src;
00452    register size_t n = siz;
00453 
00454    /* Copy as many bytes as will fit */
00455    if (n != 0 && --n != 0) {
00456       do {
00457          if ((*d++ = *s++) == 0)
00458             break;
00459       } while (--n != 0);
00460    }
00461 
00462    /* Not enough room in dst, add NUL and traverse rest of src */
00463    if (n == 0) {
00464       if (siz != 0)
00465          *d = '\0';     /* NUL-terminate dst */
00466       while (*s++)
00467          ;
00468    }
00469 
00470    return s - src - 1;  /* count does not include NUL */
00471 }


Generated on Fri Apr 24 16:26:29 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7