diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -33,6 +33,36 @@ #include #include +/** Converts an integer to a string, thanks to Dom_ (http://www.signalsondisplay.com/) */ +char *int_to_str(int nbr) +{ + int div; + int len; + int i; + char *res; + + res = malloc(4 * sizeof(*res)); // Was xmalloc, hopefully it still works :D + i = 0; + while (i < 3) + res[i++] = '\0'; + res[3] = '\0'; + i = 0; + div = 1; + len = 1; + while (nbr / div >= 10) + { + div *= 10; + len++; + } + while (len) + { + res[i++] = '0' + (nbr / div); + len--; + nbr %= div; + div /= 10; + } + return (res); +} /** Generates a SSH key with ssh-keygen */ int ssh_keygen(){ // distren.id_rsa and distren.id_rsa.pub are now generated in SYSCONFDIR (etc) @@ -253,8 +283,8 @@ return 1; /** Executor function for Blender operations */ void exec_blender(struct blendjob* blendjob, char *input, char *output, int frame) { - char *frame_str; - asprintf(frame,frame_str); // Converts the int frame to a string, so it can be in the cmd array. GNU/*nix compatible only, fix before releasing win32, although dll for windows for asprintf exists! + + char *frame_str = int_to_str(frame); // Converts the int frame to a string, so it can be in the cmd array. GNU/*nix compatible only, fix before releasing win32, although dll for windows for asprintf exists! /* start execio code */ char *command = "blender"; // @TODO: append .exe if win32?