chiark / gitweb /
memfd: skip utf-8 escaping if we use a name that was passed in
[elogind.git] / src / shared / memfd.c
index 6e2319d6eed5f9262598780af4cad81d64703c57..c21642f49ae9b568a6ec9b2822b9cb5ff0ee7130 100644 (file)
 #include "bus-label.h"
 #include "missing.h"
 #include "memfd.h"
+#include "utf8.h"
 
 int memfd_new(const char *name) {
 
         _cleanup_free_ char *g = NULL;
         int fd;
 
-        assert(name);
-
         if (name) {
-                /* The kernel side is pretty picky about the character
-                 * set here, let's do the usual bus escaping to deal
-                 * with that. */
-
-                g = bus_label_escape(name);
+                g = utf8_escape_invalid(name);
                 if (!g)
                         return -ENOMEM;
 
                 name = g;
-
         } else {
                 char pr[17] = {};
 
@@ -60,13 +54,7 @@ int memfd_new(const char *name) {
                 if (isempty(pr))
                         name = "sd";
                 else {
-                        _cleanup_free_ char *e = NULL;
-
-                        e = bus_label_escape(pr);
-                        if (!e)
-                                return -ENOMEM;
-
-                        g = strappend("sd-", e);
+                        g = strappend("sd-", pr);
                         if (!g)
                                 return -ENOMEM;
 
@@ -161,7 +149,6 @@ int memfd_new_and_map(const char *name, size_t sz, void **p) {
         _cleanup_close_ int fd = -1;
         int r;
 
-        assert(name);
         assert(sz > 0);
         assert(p);
 
@@ -221,7 +208,7 @@ int memfd_get_name(int fd, char **name) {
         if (!n)
                 return -ENOMEM;
 
-        e = bus_label_unescape(n);
+        e = utf8_escape_invalid(n);
         if (!e)
                 return -ENOMEM;