Fix copy-and-paste error in command-line font selection in r9314.
[sgt/putty] / unix / uxmisc.c
index dc20863..222d559 100644 (file)
@@ -140,11 +140,45 @@ FILE *f_open(struct Filename filename, char const *mode, int is_private)
     if (!is_private) {
        return fopen(filename.path, mode);
     } else {
-       assert(mode[0] == 'w');        /* is_private is meaningless for read */
-       int fd = open(filename.path, O_WRONLY | O_CREAT | O_TRUNC,
+       int fd;
+       assert(mode[0] == 'w');        /* is_private is meaningless for read,
+                                         and tricky for append */
+       fd = open(filename.path, O_WRONLY | O_CREAT | O_TRUNC,
                      0700);
        if (fd < 0)
            return NULL;
        return fdopen(fd, mode);
     }
 }
+
+FontSpec *fontspec_new(const char *name)
+{
+    FontSpec *f = snew(FontSpec);
+    f->name = dupstr(name);
+    return f;
+}
+FontSpec *fontspec_copy(const FontSpec *f)
+{
+    return fontspec_new(f->name);
+}
+void fontspec_free(FontSpec *f)
+{
+    sfree(f->name);
+    sfree(f);
+}
+int fontspec_serialise(FontSpec *f, void *data)
+{
+    int len = strlen(f->name);
+    if (data)
+        strcpy(data, f->name);
+    return len + 1;                    /* include trailing NUL */
+}
+FontSpec *fontspec_deserialise(void *vdata, int maxsize, int *used)
+{
+    char *data = (char *)vdata;
+    char *end = memchr(data, '\0', maxsize);
+    if (!end)
+        return NULL;
+    *used = end - data + 1;
+    return fontspec_new(data);
+}