*
* Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
*
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*/
#include <stdio.h>
{
struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
char path[UTIL_PATH_SIZE];
+ size_t l;
+ char *s;
DIR *dir;
struct dirent *dent;
- util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
- util_strlcat(path, "/", sizeof(path));
- util_strlcat(path, basedir, sizeof(path));
- if (subdir1 != NULL) {
- util_strlcat(path, "/", sizeof(path));
- util_strlcat(path, subdir1, sizeof(path));
- }
- if (subdir2 != NULL) {
- util_strlcat(path, "/", sizeof(path));
- util_strlcat(path, subdir2, sizeof(path));
- }
+ s = path;
+ l = util_strpcpyl(&s, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL);
+ if (subdir1 != NULL)
+ l = util_strpcpyl(&s, l, "/", subdir1, NULL);
+ if (subdir2 != NULL)
+ l = util_strpcpyl(&s, l, "/", subdir2, NULL);
dir = opendir(path);
if (dir == NULL)
return -1;
if (dent->d_name[0] == '.')
continue;
- util_strlcpy(syspath, path, sizeof(syspath));
- util_strlcat(syspath, "/", sizeof(syspath));
- util_strlcat(syspath, dent->d_name, sizeof(syspath));
+ util_strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL);
if (lstat(syspath, &statbuf) != 0)
continue;
if (S_ISREG(statbuf.st_mode))
continue;
if (S_ISLNK(statbuf.st_mode))
util_resolve_sys_link(udev, syspath, sizeof(syspath));
- util_strlcpy(filename, syspath, sizeof(filename));
- util_strlcat(filename, "/uevent", sizeof(filename));
+
+ util_strscpyl(filename, sizeof(filename), syspath, "/uevent", NULL);
if (stat(filename, &statbuf) != 0)
continue;
if (!match_sysattr(udev_enumerate, syspath))
DIR *dir;
struct dirent *dent;
- util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
- util_strlcat(path, "/", sizeof(path));
- util_strlcat(path, basedir, sizeof(path));
+ util_strscpyl(path, sizeof(path), udev_get_sys_path(udev), "/", basedir, NULL);
dir = opendir(path);
if (dir == NULL)
return -1;
if (udev_enumerate == NULL)
return -EINVAL;
- util_strlcpy(base, udev_get_sys_path(udev), sizeof(base));
- util_strlcat(base, "/subsystem", sizeof(base));
+ util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL);
if (stat(base, &statbuf) == 0) {
/* we have /subsystem/, forget all the old stuff */
dbg(udev, "searching '/subsystem/*/devices/*' dir\n");
dbg(udev, "searching '/class/*' dir\n");
scan_dir(udev_enumerate, "class", NULL, NULL);
/* if block isn't a class, scan /block/ */
- util_strlcpy(base, udev_get_sys_path(udev), sizeof(base));
- util_strlcat(base, "/class/block", sizeof(base));
+ util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/class/block", NULL);
if (stat(base, &statbuf) != 0) {
if (match_subsystem(udev_enumerate, "block")) {
dbg(udev, "searching '/block/*' dir\n");
if (udev_enumerate == NULL)
return -EINVAL;
- util_strlcpy(base, udev_get_sys_path(udev), sizeof(base));
- util_strlcat(base, "/subsystem", sizeof(base));
+ util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem", NULL);
if (stat(base, &statbuf) == 0)
subsysdir = "subsystem";
else