1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Change the semantics of 'FontSpec' so that it's a dynamically

allocated type.

The main reason for this is to stop it from taking up a fixed large
amount of space in every 'struct value' subunion in conf.c, although
that makes little difference so far because Filename is still doing
the same thing (and is therefore next on my list). However, the
removal of its arbitrary length limit is not to be sneezed at.

[originally from svn r9314]
This commit is contained in:
Simon Tatham
2011-10-01 17:38:59 +00:00
parent f69591412c
commit 9c75fe9a3f
19 changed files with 220 additions and 139 deletions

View File

@ -150,3 +150,35 @@ FILE *f_open(struct Filename filename, char const *mode, int is_private)
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);
}