chiark / gitweb /
util: don't AND cx with cx
[elogind.git] / src / util.c
index 5029896ef0635d507fcb9bc8e6e10dab537c81d3..9b43c21d08456698770805c8bf1701f60b2730f2 100644 (file)
@@ -1209,6 +1209,26 @@ char **strv_path_canonicalize(char **l) {
         return l;
 }
 
+char **strv_path_remove_empty(char **l) {
+        char **f, **t;
+
+        if (!l)
+                return NULL;
+
+        for (f = t = l; *f; f++) {
+
+                if (dir_is_empty(*f) > 0) {
+                        free(*f);
+                        continue;
+                }
+
+                *(t++) = *f;
+        }
+
+        *t = NULL;
+        return l;
+}
+
 int reset_all_signal_handlers(void) {
         int sig;
 
@@ -3991,7 +4011,7 @@ int detect_vm(const char **id) {
                 : "0" (eax)
         );
 
-        hypervisor = !!(ecx & ecx & 0x80000000U);
+        hypervisor = !!(ecx & 0x80000000U);
 
         if (hypervisor) {
 
@@ -4586,15 +4606,15 @@ static int base_cmp(const void *a, const void *b) {
         return strcmp(file_name_from_path(s1), file_name_from_path(s2));
 }
 
-char **conf_files_list(const char *suffix, const char *dir, ...) {
+int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
         Hashmap *fh;
         char **files = NULL;
         va_list ap;
-        int e = 0;
+        int r = 0;
 
         fh = hashmap_new(string_hash_func, string_compare_func);
         if (!fh) {
-                e = ENOMEM;
+                r = -ENOMEM;
                 goto finish;
         }
 
@@ -4602,7 +4622,7 @@ char **conf_files_list(const char *suffix, const char *dir, ...) {
         while (dir) {
                 if (files_add(fh, dir, suffix) < 0) {
                         log_error("Failed to search for files.");
-                        e = EINVAL;
+                        r = -EINVAL;
                         goto finish;
                 }
                 dir = va_arg(ap, const char *);
@@ -4612,13 +4632,13 @@ char **conf_files_list(const char *suffix, const char *dir, ...) {
         files = hashmap_get_strv(fh);
         if (files == NULL) {
                 log_error("Failed to compose list of files.");
-                e = ENOMEM;
+                r = -ENOMEM;
                 goto finish;
         }
 
         qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
 finish:
         hashmap_free(fh);
-        errno = e;
-        return files;
+        *strv = files;
+        return r;
 }