/** * This program is inspired by the strlcpy function available in OpenBSD. * Author: Rahul Jadhav * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include #include size_t strlcpy(char *dst, const char *src, size_t sz){ char *d = dst; const char *s = src; size_t n = sz; if (sz > 0){ while (n > 0 && (*d++ = *s++)) --n; if (n == 0){ *d = '\0'; while (*s++); } } return (s - src - 1); }