summaryrefslogtreecommitdiff
path: root/udev_libc_wrapper.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2005-03-07 04:29:43 +0100
committerGreg KH <gregkh@suse.de>2005-04-26 23:51:00 -0700
commit63f61c5cf639953aa38e025485919b0aa1c49b59 (patch)
tree2392041b5aef6984384cf044371ec2d9716014d4 /udev_libc_wrapper.c
parent56a8a624eef99f5324b54fad466b144aa4f882c2 (diff)
[PATCH] replace strncpy()/strncat() by strlcpy()/strlcat()
Diffstat (limited to 'udev_libc_wrapper.c')
-rw-r--r--udev_libc_wrapper.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/udev_libc_wrapper.c b/udev_libc_wrapper.c
index df54515206..0dafe4d077 100644
--- a/udev_libc_wrapper.c
+++ b/udev_libc_wrapper.c
@@ -32,16 +32,58 @@
#include "../udev_utils.h"
#include "../logging.h"
-
#ifdef __KLIBC__
#define __OWN_USERDB_PARSER__
#endif
+
#ifdef USE_STATIC
#define __OWN_USERDB_PARSER__
#endif
-#ifndef __OWN_USERDB_PARSER__
+#ifndef strlcpy
+size_t strlcpy(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while ((ch = *p++)) {
+ if (bytes < size)
+ *q++ = ch;
+ bytes++;
+ }
+
+ *q = '\0';
+ return bytes;
+}
+#endif
+
+#ifndef strlcat
+size_t strlcat(char *dst, const char *src, size_t size)
+{
+ size_t bytes = 0;
+ char *q = dst;
+ const char *p = src;
+ char ch;
+
+ while (bytes < size && *q) {
+ q++;
+ bytes++;
+ }
+ while ((ch = *p++)) {
+ if (bytes < size)
+ *q++ = ch;
+ bytes++;
+ }
+
+ *q = '\0';
+ return bytes;
+}
+#endif
+
+#ifndef __OWN_USERDB_PARSER__
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
@@ -107,11 +149,10 @@ static unsigned long get_id_by_name(const char *uname, const char *dbfile)
bufline = &buf[cur];
cur += count+1;
- if (count >= LINE_SIZE)
+ if (count >= sizeof(line))
continue;
- strncpy(line, bufline, count);
- line[count] = '\0';
+ strlcpy(line, bufline, count);
pos = line;
/* get name */
@@ -158,5 +199,4 @@ gid_t lookup_group(const char *group)
id = get_id_by_name(group, GROUP_FILE);
return (gid_t) id;
}
-
#endif /* __OWN_USERDB_PARSER__ */