aboutsummaryrefslogtreecommitdiff
path: root/tools/plink/winmisc.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-01-24 16:46:55 +0100
committermarha <marha@users.sourceforge.net>2012-01-24 16:46:55 +0100
commit6039fd0faf73c9d6c5b2abf9d824734218ec5eee (patch)
tree88f66f9d7c4763f206de6043ef45c63b94472690 /tools/plink/winmisc.c
parentb683b8f5675e280a6dd4ab82d6b9394182798b55 (diff)
downloadvcxsrv-6039fd0faf73c9d6c5b2abf9d824734218ec5eee.tar.gz
vcxsrv-6039fd0faf73c9d6c5b2abf9d824734218ec5eee.tar.bz2
vcxsrv-6039fd0faf73c9d6c5b2abf9d824734218ec5eee.zip
Update to putty 9388
Diffstat (limited to 'tools/plink/winmisc.c')
-rw-r--r--tools/plink/winmisc.c95
1 files changed, 87 insertions, 8 deletions
diff --git a/tools/plink/winmisc.c b/tools/plink/winmisc.c
index e70e77efa..e8a35ee1d 100644
--- a/tools/plink/winmisc.c
+++ b/tools/plink/winmisc.c
@@ -14,27 +14,58 @@ char *platform_get_x_display(void) {
return dupstr(getenv("DISPLAY"));
}
-Filename filename_from_str(const char *str)
+Filename *filename_from_str(const char *str)
{
- Filename ret;
- strncpy(ret.path, str, sizeof(ret.path));
- ret.path[sizeof(ret.path)-1] = '\0';
+ Filename *ret = snew(Filename);
+ ret->path = dupstr(str);
return ret;
}
+Filename *filename_copy(const Filename *fn)
+{
+ return filename_from_str(fn->path);
+}
+
const char *filename_to_str(const Filename *fn)
{
return fn->path;
}
-int filename_equal(Filename f1, Filename f2)
+int filename_equal(const Filename *f1, const Filename *f2)
+{
+ return !strcmp(f1->path, f2->path);
+}
+
+int filename_is_null(const Filename *fn)
{
- return !strcmp(f1.path, f2.path);
+ return !*fn->path;
}
-int filename_is_null(Filename fn)
+void filename_free(Filename *fn)
+{
+ sfree(fn->path);
+ sfree(fn);
+}
+
+int filename_serialise(const Filename *f, void *vdata)
+{
+ char *data = (char *)vdata;
+ int len = strlen(f->path) + 1; /* include trailing NUL */
+ if (data) {
+ strcpy(data, f->path);
+ }
+ return len;
+}
+Filename *filename_deserialise(void *vdata, int maxsize, int *used)
{
- return !*fn.path;
+ char *data = (char *)vdata;
+ char *end;
+ end = memchr(data, '\0', maxsize);
+ if (!end)
+ return NULL;
+ end++;
+ *used = end - data;
+ return filename_from_str(data);
}
char *get_username(void)
@@ -379,3 +410,51 @@ void *minefield_c_realloc(void *p, size_t size)
}
#endif /* MINEFIELD */
+
+FontSpec *fontspec_new(const char *name,
+ int bold, int height, int charset)
+{
+ FontSpec *f = snew(FontSpec);
+ f->name = dupstr(name);
+ f->isbold = bold;
+ f->height = height;
+ f->charset = charset;
+ return f;
+}
+FontSpec *fontspec_copy(const FontSpec *f)
+{
+ return fontspec_new(f->name, f->isbold, f->height, f->charset);
+}
+void fontspec_free(FontSpec *f)
+{
+ sfree(f->name);
+ sfree(f);
+}
+int fontspec_serialise(FontSpec *f, void *vdata)
+{
+ char *data = (char *)vdata;
+ int len = strlen(f->name) + 1; /* include trailing NUL */
+ if (data) {
+ strcpy(data, f->name);
+ PUT_32BIT_MSB_FIRST(data + len, f->isbold);
+ PUT_32BIT_MSB_FIRST(data + len + 4, f->height);
+ PUT_32BIT_MSB_FIRST(data + len + 8, f->charset);
+ }
+ return len + 12; /* also include three 4-byte ints */
+}
+FontSpec *fontspec_deserialise(void *vdata, int maxsize, int *used)
+{
+ char *data = (char *)vdata;
+ char *end;
+ if (maxsize < 13)
+ return NULL;
+ end = memchr(data, '\0', maxsize-12);
+ if (!end)
+ return NULL;
+ end++;
+ *used = end - data + 12;
+ return fontspec_new(data,
+ GET_32BIT_MSB_FIRST(end),
+ GET_32BIT_MSB_FIRST(end + 4),
+ GET_32BIT_MSB_FIRST(end + 8));
+}