Logo Search packages:      
Sourcecode: libnl version File versions  Download package

size_t nla_strlcpy ( char *  dst,
const struct nlattr nla,
size_t  dstsize 
)

Copy string attribute payload into a sized buffer

  • dst where to copy the string to
  • nla attribute to copy the string from
  • dstsize size of destination buffer
Copies at most dstsize - 1 bytes into the destination buffer. The result is always a valid NUL-terminated string. Unlike strlcpy the destination buffer is always padded out.

Returns:
the length of the source buffer.

Definition at line 401 of file attr.c.

References nla_data(), and nla_len().

{
      size_t srclen = nla_len(nla);
      char *src = nla_data(nla);

      if (srclen > 0 && src[srclen - 1] == '\0')
            srclen--;

      if (dstsize > 0) {
            size_t len = (srclen >= dstsize) ? dstsize - 1 : srclen;

            memset(dst, 0, dstsize);
            memcpy(dst, src, len);
      }

      return srclen;
}


Generated by  Doxygen 1.6.0   Back to index