summaryrefslogtreecommitdiff
path: root/src/libudev/libudev-util.c
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2013-01-09 19:06:46 +0100
committerKay Sievers <kay@vrfy.org>2013-01-09 19:06:46 +0100
commitd5a89d7dc17a5ba5cf4fc71f82963c5c94a31c3d (patch)
tree6b1c9b2355d2f40fd083eb91411748310a3308dd /src/libudev/libudev-util.c
parent0908dd2fd5536cf15d75780980ac2eca37ff800f (diff)
udev: move string copy functions to shared/
Diffstat (limited to 'src/libudev/libudev-util.c')
-rw-r--r--src/libudev/libudev-util.c99
1 files changed, 8 insertions, 91 deletions
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c
index b55bf75bfc..2eb7907063 100644
--- a/src/libudev/libudev-util.c
+++ b/src/libudev/libudev-util.c
@@ -51,7 +51,7 @@ int util_delete_path(struct udev *udev, const char *path)
if (path[0] == '/')
while(path[1] == '/')
path++;
- util_strscpy(p, sizeof(p), path);
+ strscpy(p, sizeof(p), path);
pos = strrchr(p, '/');
if (pos == p || pos == NULL)
return 0;
@@ -151,7 +151,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string,
if (string[0] != '[')
return -1;
- util_strscpy(temp, sizeof(temp), string);
+ strscpy(temp, sizeof(temp), string);
subsys = &temp[1];
@@ -183,7 +183,7 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string,
val = udev_device_get_sysattr_value(dev, attr);
if (val != NULL)
- util_strscpy(result, maxsize, val);
+ strscpy(result, maxsize, val);
else
result[0] = '\0';
udev_dbg(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
@@ -192,9 +192,9 @@ int util_resolve_subsys_kernel(struct udev *udev, const char *string,
char *s;
s = result;
- l = util_strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL);
+ l = strpcpyl(&s, maxsize, udev_device_get_syspath(dev), NULL);
if (attr != NULL)
- util_strpcpyl(&s, l, "/", attr, NULL);
+ strpcpyl(&s, l, "/", attr, NULL);
udev_dbg(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
}
udev_device_unref(dev);
@@ -207,7 +207,7 @@ ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const
ssize_t len;
const char *pos;
- util_strscpyl(path, sizeof(path), syspath, "/", slink, NULL);
+ strscpyl(path, sizeof(path), syspath, "/", slink, NULL);
len = readlink(path, target, sizeof(target));
if (len <= 0 || len == (ssize_t)sizeof(target))
return -1;
@@ -216,7 +216,7 @@ ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const
if (pos == NULL)
return -1;
pos = &pos[1];
- return util_strscpy(value, size, pos);
+ return strscpy(value, size, pos);
}
int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size)
@@ -243,7 +243,7 @@ int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size)
}
if (base == NULL)
return -EINVAL;
- util_strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL);
+ strscpyl(base, size - (base - syspath), "/", &link_target[back * 3], NULL);
return 0;
}
@@ -307,89 +307,6 @@ void util_remove_trailing_chars(char *path, char c)
path[--len] = '\0';
}
-/*
- * Concatenates strings. In any case, terminates in _all_ cases with '\0'
- * and moves the @dest pointer forward to the added '\0'. Returns the
- * remaining size, and 0 if the string was truncated.
- */
-size_t util_strpcpy(char **dest, size_t size, const char *src)
-{
- size_t len;
-
- len = strlen(src);
- if (len >= size) {
- if (size > 1)
- *dest = mempcpy(*dest, src, size-1);
- size = 0;
- } else {
- if (len > 0) {
- *dest = mempcpy(*dest, src, len);
- size -= len;
- }
- }
- *dest[0] = '\0';
- return size;
-}
-
-size_t util_strpcpyf(char **dest, size_t size, const char *src, ...)
-{
- va_list va;
- int i;
-
- va_start(va, src);
- i = vsnprintf(*dest, size, src, va);
- if (i < (int)size) {
- *dest += i;
- size -= i;
- } else {
- *dest += size;
- size = 0;
- }
- va_end(va);
- *dest[0] = '\0';
- return size;
-}
-
-/* concatenates list of strings, moves dest forward */
-size_t util_strpcpyl(char **dest, size_t size, const char *src, ...)
-{
- va_list va;
-
- va_start(va, src);
- do {
- size = util_strpcpy(dest, size, src);
- src = va_arg(va, char *);
- } while (src != NULL);
- va_end(va);
- return size;
-}
-
-/* copies string */
-size_t util_strscpy(char *dest, size_t size, const char *src)
-{
- char *s;
-
- s = dest;
- return util_strpcpy(&s, size, src);
-}
-
-/* concatenates list of strings */
-size_t util_strscpyl(char *dest, size_t size, const char *src, ...)
-{
- va_list va;
- char *s;
-
- va_start(va, src);
- s = dest;
- do {
- size = util_strpcpy(&s, size, src);
- src = va_arg(va, char *);
- } while (src != NULL);
- va_end(va);
-
- return size;
-}
-
/* count of characters used to encode one unicode char */
static int utf8_encoded_expected_len(const char *str)
{