diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2002-05-24 18:37:39 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2002-05-24 18:37:39 +0000 |
commit | 145430bff0ed74669a662266006ca969385f68ec (patch) | |
tree | 7fea3decf2bc98b86d718c52e6437537715d48be /libexec/ld.so/util.h | |
parent | 53cab32a9208921ca8843c1e2550007ffc7b8b86 (diff) |
Change _dl_strcpy() to _dl_strlcpy(), implementation taken from libc.
Diffstat (limited to 'libexec/ld.so/util.h')
-rw-r--r-- | libexec/ld.so/util.h | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/libexec/ld.so/util.h b/libexec/ld.so/util.h index a6d1131a46e..0d2310bf58f 100644 --- a/libexec/ld.so/util.h +++ b/libexec/ld.so/util.h @@ -1,6 +1,8 @@ -/* $OpenBSD: util.h,v 1.3 2002/05/24 03:44:37 deraadt Exp $ */ +/* $OpenBSD: util.h,v 1.4 2002/05/24 18:37:38 drahn Exp $ */ /* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * All rights reserved. * Copyright (c) 1998 Per Fogelstrom, Opsycon AB * * Redistribution and use in source and binary forms, with or without @@ -73,14 +75,30 @@ _dl_strlen(const char *p) return(s - p); } -static inline char * -_dl_strcpy(char *d, const char *s) +static inline size_t +_dl_strlcpy(char *dst, const char *src, int siz) { - char *rd = d; + char *d = dst; + const char *s = src; + size_t n = siz; - while ((*d++ = *s++) != '\0') - ; - return(rd); + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ } static inline int |