]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/xml.c
run: also show a pretty string for main exit status, if any
[thirdparty/systemd.git] / src / shared / xml.c
index 15c629b1884ca172ac16e719ba3bd9eec5aba8a0..3b1fb41fef74b04721be82cd5206bfbe71af0e61 100644 (file)
@@ -1,27 +1,10 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-/***
-  This file is part of systemd.
+#include <errno.h>
+#include <stddef.h>
 
-  Copyright 2013 Lennart Poettering
-
-  systemd 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.
-
-  systemd 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
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include <string.h>
-
-#include "util.h"
+#include "macro.h"
+#include "string-util.h"
 #include "xml.h"
 
 enum {
@@ -104,26 +87,26 @@ int xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
 
                         if (startswith(b, "!--")) {
                                 /* A comment */
-                                e = strstr(b + 3, "-->");
+                                e = strstrafter(b + 3, "-->");
                                 if (!e)
                                         return -EINVAL;
 
-                                inc_lines(line, b, e + 3 - b);
+                                inc_lines(line, b, e - b);
 
-                                c = e + 3;
+                                c = e;
                                 continue;
                         }
 
                         if (*b == '?') {
                                 /* Processing instruction */
 
-                                e = strstr(b + 1, "?>");
+                                e = strstrafter(b + 1, "?>");
                                 if (!e)
                                         return -EINVAL;
 
-                                inc_lines(line, b, e + 2 - b);
+                                inc_lines(line, b, e - b);
 
-                                c = e + 2;
+                                c = e;
                                 continue;
                         }
 
@@ -207,7 +190,7 @@ int xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
                         if (*c == '=') {
                                 c++;
 
-                                if (*c == '\'' || *c == '\"') {
+                                if (IN_SET(*c, '\'', '"')) {
                                         /* Tag with a quoted value */
 
                                         e = strchr(c+1, *c);
@@ -250,5 +233,5 @@ int xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
 
         }
 
-        assert_not_reached("Bad state");
+        assert_not_reached();
 }