chiark / gitweb /
add strerror() to error logs
[elogind.git] / udev_libc_wrapper.c
index 23cb7b43168bc9ff7c3619bcf1440627f67f8b42..a7a8c5342d481e53fe38842afe91d60eba90db0c 100644 (file)
@@ -58,7 +58,10 @@ size_t strlcpy(char *dst, const char *src, size_t size)
                bytes++;
        }
 
-       *q = '\0';
+       /* If size == 0 there is no space for a final null... */
+       if (size)
+               *q = '\0';
+
        return bytes;
 }
 
@@ -141,7 +144,7 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile)
        char *tail;
 
        if (file_map(dbfile, &buf, &bufsize) != 0) {
-               dbg("can't open '%s' as db file", dbfile);
+               dbg("can't open '%s' as db file: %s", dbfile, strerror(errno));
                return 0;
        }
        dbg("search '%s' in '%s'", uname, dbfile);
@@ -156,7 +159,8 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile)
                if (count >= sizeof(line))
                        continue;
 
-               strlcpy(line, bufline, count);
+               memcpy(line, bufline, count-1);
+               line[count-1] = '\0';
                pos = line;
 
                /* get name */