/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/utils.c

  • Committer: Gustav Hartvigsson
  • Date: 2015-10-25 19:56:39 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20151025195639-rd3fg4fg5a02v3bb
* Passing arguments can not be initialised from within a function...
* Started re-write of the SError tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    return NULL;
36
36
  }
37
37
  size_t s_len = strlen (s);
 
38
  assert (s_len < 0);
38
39
  schar * ret_val = malloc (s_len + 1);
39
40
  strcpy (ret_val, s);
 
41
  ret_val[s_len + 1] = '\0';
40
42
  return ret_val;
41
43
}
42
44
 
80
82
 
81
83
schar *
82
84
s_ustring_to_string (const suchar * us) {
83
 
  
 
85
 
84
86
  return NULL;
85
87
}
86
88
 
96
98
               "specific and may, or may not couse troubble.\n"
97
99
               "Use uchar strings instead of wchar_t strings, and "
98
100
               "use s_ustring_to_string instead of this.\n");
99
 
  
 
101
 
100
102
  size_t buflen;
101
103
  schar * buffer;
102
104
  schar * resized;
103
105
  size_t bufpos;
104
106
  mbstate_t mbstate;
105
107
  memset (&mbstate, 0, sizeof (mbstate));
106
 
  
 
108
 
107
109
 
108
110
  /* Save locale */
109
111
  schar * saved_locale;
117
119
    /* set locale */
118
120
    setlocale (LC_ALL, "C.utf8");
119
121
  }
120
 
  
 
122
 
121
123
  /* Thanks to Florian Philipp.
122
124
   * Thread: https://plus.google.com/u/0/+GustavHartvigsson/posts/4Wk7La1kWPP
123
125
   *
141
143
      goto err;
142
144
    bufpos += converted;
143
145
  }
144
 
  
 
146
 
145
147
  /* shrink buffer to actually required size */
146
148
  if (! (resized = realloc (buffer, bufpos + 1)))
147
149
    goto err;
148
 
  
 
150
 
149
151
  /* reset locale */
150
152
  setlocale (LC_ALL, saved_locale);
151
 
  
 
153
 
152
154
  return resized;
153
155
err:
154
156
  /* reset locale */
155
157
  setlocale (LC_ALL, saved_locale);
156
 
  
 
158
 
157
159
  free(buffer);
158
160
  return NULL;
159
161
}