diff options
author | Jeremy Allison <jra@samba.org> | 2002-04-30 13:28:41 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-04-30 13:28:41 +0000 |
commit | d04b55f2186fb8af998cf61c576771a5f72f4892 (patch) | |
tree | 9ff8c3a7cf34cefc0ee9a550a3bb1236a9e77595 /source/lib/replace.c | |
parent | 73267ca42d9eddabb71b31b4c5068ebbe7bc9f7c (diff) | |
download | samba-d04b55f2186fb8af998cf61c576771a5f72f4892.tar.gz samba-d04b55f2186fb8af998cf61c576771a5f72f4892.tar.xz samba-d04b55f2186fb8af998cf61c576771a5f72f4892.zip |
Start of merge to 2_2_RELEASE branch for release.
Jeremy.
Diffstat (limited to 'source/lib/replace.c')
-rw-r--r-- | source/lib/replace.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/source/lib/replace.c b/source/lib/replace.c index 16d7450d69e..dd50ff035e0 100644 --- a/source/lib/replace.c +++ b/source/lib/replace.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. replacement routines for broken systems Copyright (C) Andrew Tridgell 1992-1998 @@ -24,7 +23,6 @@ void replace_dummy(void); void replace_dummy(void) {} - #ifndef HAVE_FTRUNCATE /******************************************************************* ftruncate for operating systems that don't have it @@ -42,6 +40,42 @@ ftruncate for operating systems that don't have it #endif /* HAVE_FTRUNCATE */ +#ifndef HAVE_STRLCPY +/* like strncpy but does not 0 fill the buffer and always null + terminates. bufsize is the size of the destination buffer */ + size_t strlcpy(char *d, const char *s, size_t bufsize) +{ + size_t len = strlen(s); + size_t ret = len; + if (bufsize <= 0) return 0; + if (len >= bufsize) len = bufsize-1; + memcpy(d, s, len); + d[len] = 0; + return ret; +} +#endif + +#ifndef HAVE_STRLCAT +/* like strncat but does not 0 fill the buffer and always null + terminates. bufsize is the length of the buffer, which should + be one more than the maximum resulting string length */ + size_t strlcat(char *d, const char *s, size_t bufsize) +{ + size_t len1 = strlen(d); + size_t len2 = strlen(s); + size_t ret = len1 + len2; + + if (len1+len2 >= bufsize) { + len2 = bufsize - (len1+1); + } + if (len2 > 0) { + memcpy(d+len1, s, len2); + d[len1+len2] = 0; + } + return ret; +} +#endif + #ifndef HAVE_MKTIME /******************************************************************* a mktime() replacement for those who don't have it - contributed by @@ -125,7 +159,7 @@ Corrections by richard.kettlewell@kewill.com /* * Search for a match in a netgroup. This replaces it on broken systems. */ - int innetgr(char *group,char *host,char *user,char *dom) + int innetgr(const char *group,const char *host,const char *user,const char *dom) { char *hst, *usr, *dm; |