/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 src/utils.c

  • Committer: Gustav Hartvigsson
  • Date: 2014-12-22 11:32:35 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20141222113235-r6jrin8cj6p8m13w
* Fixed some of the build warnings.
* added TRUE and FALSE definitons.
* added S_TYPES enum.

* TODO:
  * Convert to CMake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
*/
22
22
 
23
23
#include "utils.h"
 
24
#include <string.h>
 
25
#include <stdlib.h>
 
26
#include <stdio.h>
 
27
#include <stdarg.h>
24
28
 
25
29
char * s_string_new (const char * s) {
26
 
  char * ret_val = strdup (s);
27
 
  free (s);
 
30
  char * ret_val = malloc (strlen (s) + 1);
 
31
  strcpy (ret_val, s);
 
32
  free ((char *) s);
 
33
  return ret_val;
 
34
}
 
35
 
 
36
char * s_string_new_fmt (const char * format, ...) {
 
37
  char * ret_val = malloc (strlen (format) + 1);
 
38
  strcpy (ret_val, format);
 
39
  free ((char *) format);
28
40
  return ret_val;
29
41
}
30
42
 
31
43
char * s_string_new_with_len (const char * s, size_t len) {
32
44
  char * ret_val = malloc (len + 1);
33
45
  strncpy (ret_val, s, len);
34
 
  free (s);
 
46
  free ((char *) s);
35
47
  return ret_val;
36
48
}
37
49
 
38
 
void s_print (const char * string) {
39
 
  fprintf (stdout, string);
 
50
void s_print (const char * format, ...) {
 
51
  va_list args;
 
52
  va_start (args, format);
 
53
  fprintf (stdout, (char *) format, args);
 
54
  va_end (args);
40
55
}