X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_libc_wrapper.c;h=1852141c9378c7baa9b389013ed838a90a2d9871;hp=4b39b6f47627826fd09c836af3a7869b1830c58e;hb=f943722e0a0485d030cae171b8758dba68564398;hpb=a5b9e2994a6d34cb169eaa0e2cf16d0a7c4f197a diff --git a/udev_libc_wrapper.c b/udev_libc_wrapper.c index 4b39b6f47..1852141c9 100644 --- a/udev_libc_wrapper.c +++ b/udev_libc_wrapper.c @@ -36,11 +36,15 @@ #define __OWN_USERDB_PARSER__ #endif +#ifdef __GLIBC__ +#define __OWN_STRLCPYCAT__ +#endif + #ifdef USE_STATIC #define __OWN_USERDB_PARSER__ #endif -#ifndef strlcpy +#ifdef __OWN_STRLCPYCAT__ size_t strlcpy(char *dst, const char *src, size_t size) { size_t bytes = 0; @@ -49,17 +53,18 @@ size_t strlcpy(char *dst, const char *src, size_t size) char ch; while ((ch = *p++)) { - if (bytes < size) + if (bytes+1 < size) *q++ = ch; bytes++; } - *q = '\0'; + /* If size == 0 there is no space for a final null... */ + if (size) + *q = '\0'; + return bytes; } -#endif -#ifndef strlcat size_t strlcat(char *dst, const char *src, size_t size) { size_t bytes = 0; @@ -71,9 +76,11 @@ size_t strlcat(char *dst, const char *src, size_t size) q++; bytes++; } + if (bytes == size) + return (bytes + strlen(src)); while ((ch = *p++)) { - if (bytes < size) + if (bytes+1 < size) *q++ = ch; bytes++; } @@ -81,7 +88,7 @@ size_t strlcat(char *dst, const char *src, size_t size) *q = '\0'; return bytes; } -#endif +#endif /* __OWN_STRLCPYCAT__ */ #ifndef __OWN_USERDB_PARSER__ #include @@ -140,7 +147,7 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile) dbg("can't open '%s' as db file", dbfile); return 0; } - dbg("reading '%s' as db file", dbfile); + dbg("search '%s' in '%s'", uname, dbfile); /* loop through the whole file */ cur = 0;