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

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

Copy string attribute payload to a buffer.

  • dst Pointer to destination buffer.
  • nla Attribute of type NLA_STRING.
  • dstsize Size of destination buffer in bytes.
Copies at most dstsize - 1 bytes to 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 string attribute without the terminating NUL.

Definition at line 720 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