Introduced wrapper macros snew(), snewn() and sresize() for the
[u/mdw/putty] / unix / uxstore.c
index 10e33c0..15fcdcb 100644 (file)
@@ -75,12 +75,12 @@ void provide_xrm_string(char *string)
     q++;
     while (p > string && p[-1] != '.' && p[-1] != '*')
        p--;
-    xrms = smalloc(sizeof(struct xrm_string));
-    key = smalloc(q-p);
+    xrms = snew(struct xrm_string);
+    key = snewn(q-p, char);
     memcpy(key, p, q-p);
     key[q-p-1] = '\0';
     xrms->key = key;
-    while (*q && isspace(*q))
+    while (*q && isspace((unsigned char)*q))
        q++;
     xrms->value = dupstr(q);
 
@@ -134,6 +134,24 @@ int read_setting_i(void *handle, const char *key, int defvalue)
        return atoi(val);
 }
 
+int read_setting_fontspec(void *handle, const char *name, FontSpec *result)
+{
+    return !!read_setting_s(handle, name, result->name, sizeof(result->name));
+}
+int read_setting_filename(void *handle, const char *name, Filename *result)
+{
+    return !!read_setting_s(handle, name, result->path, sizeof(result->path));
+}
+
+void write_setting_fontspec(void *handle, const char *name, FontSpec result)
+{
+    write_setting_s(handle, name, result.name);
+}
+void write_setting_filename(void *handle, const char *name, Filename result)
+{
+    write_setting_s(handle, name, result.path);
+}
+
 void close_settings_r(void *handle)
 {
 }
@@ -181,14 +199,14 @@ static void make_filename(char *filename, int index)
  */
 static char *fgetline(FILE *fp)
 {
-    char *ret = smalloc(512);
+    char *ret = snewn(512, char);
     int size = 512, len = 0;
     while (fgets(ret + len, size - len, fp)) {
        len += strlen(ret + len);
        if (ret[len-1] == '\n')
            break;                     /* got a newline, we're done */
        size = len + 512;
-       ret = srealloc(ret, size);
+       ret = sresize(ret, size, char);
     }
     if (len == 0) {                   /* first fgets returned NULL */
        sfree(ret);