chiark / gitweb /
libudev: get rid of udev_sysfs.c
[elogind.git] / udev / udev_utils.c
index 1649b8cbf0349e4dcf6bd7a27cf465e877eefcdb..2cbb4d98ebbaa701816d391c13f844f03a9faf6d 100644 (file)
@@ -1,22 +1,20 @@
 /*
- * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004-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 version 2 of the License.
- * 
- *     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, write to the Free Software Foundation, Inc.,
- *     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * 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/>.
  */
 
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <stddef.h>
@@ -89,14 +87,17 @@ struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_l
 {
        struct name_entry *name_loop;
        struct name_entry *name_new;
+       size_t keylen = strlen(key);
 
        list_for_each_entry(name_loop, name_list, node) {
-               if (strncmp(name_loop->name, key, strlen(key)) == 0) {
-                       dbg(udev, "key already present '%s', replace it\n", name_loop->name);
-                       snprintf(name_loop->name, sizeof(name_loop->name), "%s=%s", key, value);
-                       name_loop->name[sizeof(name_loop->name)-1] = '\0';
-                       return name_loop;
-               }
+               if (strncmp(name_loop->name, key, keylen) != 0)
+                       continue;
+               if (name_loop->name[keylen] != '=')
+                       continue;
+               dbg(udev, "key already present '%s', replace it\n", name_loop->name);
+               snprintf(name_loop->name, sizeof(name_loop->name), "%s=%s", key, value);
+               name_loop->name[sizeof(name_loop->name)-1] = '\0';
+               return name_loop;
        }
 
        name_new = malloc(sizeof(struct name_entry));