/+junk/c_sdl_joypad_ducktape

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape

« back to all changes in this revision

Viewing changes to src/utils.c

  • Committer: Gustav Hartvigsson
  • Date: 2014-09-02 20:15:48 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140902201548-h1kss1wdocqhs8df
* Fixed Makefile
* Changed all void * to _pointer in DynamicArray.[h,c].
* Fixed GameObject to work with the new base-type.
* Made the Object stuffs...
* added string_new_printf utility function in utils.[h,c]

* Derp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <stdarg.h>
 
5
#include <stdio.h>
 
6
#include "utils.h"
 
7
 
 
8
char * string_new_printf (char * format, ...) {
 
9
  char tmp_str[_STR_MAX_LEN];
 
10
  char * ret_val;
 
11
  va_list args;
 
12
  int str_len;
 
13
  
 
14
  va_start (args, format);
 
15
  str_len = snprintf (tmp_str, _STR_MAX_LEN, format, args);
 
16
  va_end (args);
 
17
  
 
18
  if (str_len < 1) {
 
19
    return NULL;
 
20
  }
 
21
  
 
22
  ret_val = malloc ((str_len + 1) * sizeof (char));
 
23
  memcpy (ret_val, tmp_str, (str_len + 1) * sizeof (char));
 
24
  
 
25
  return ret_val;
 
26
}