chiark / gitweb /
[PATCH] udev_rules.c: don't change sysfs_device while walking up the device chain
[elogind.git] / udev_libc_wrapper.c
index 0dafe4d077bb344bdd7dc95adf260f6d822742ca..d69f2ac48e11dfb0dcc01daa6125089697307b93 100644 (file)
 #include <fcntl.h>
 #include <sys/types.h>
 
-#include "../udev_libc_wrapper.h"
-#include "../udev.h"
-#include "../udev_utils.h"
-#include "../logging.h"
+#include "udev_libc_wrapper.h"
+#include "udev.h"
+#include "udev_utils.h"
+#include "logging.h"
 
 #ifdef __KLIBC__
 #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,16 @@ 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)
+               *q = '\0';
        return bytes;
 }
-#endif
 
-#ifndef strlcat
 size_t strlcat(char *dst, const char *src, size_t size)
 {
        size_t bytes = 0;
@@ -71,17 +74,20 @@ 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++;
        }
 
-       *q = '\0';
+       if (size)
+               *q = '\0';
        return bytes;
 }
-#endif
+#endif /* __OWN_STRLCPYCAT__ */
 
 #ifndef __OWN_USERDB_PARSER__
 #include <sys/types.h>
@@ -140,7 +146,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;