Changeset - 601295e9ca42
[Not reviewed]
default
0 2 0
ethanzonca - 16 years ago 2009-08-01 00:17:17

Trying out someone's int_to_str() function, we'll see how it goes... but it used xmalloc, which isn't in every build env. I changed it to malloc, we'll see... :D
2 files changed with 33 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -33,6 +33,36 @@
 
#include <sys/stat.h>
 
#include <fcntl.h>
 

	
 
/** 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?
src/server/slavefuncs.h
Show inline comments
 
@@ -21,6 +21,7 @@
 
#define _DISTREN_SLAVEFUNCS_H
 
#include "blendjob.h"
 

	
 
char *int_to_str(int nbr);
 
int ssh_keygen();
 
int register_user(char *username, char *email);
 
int login_user(char *username);
0 comments (0 inline, 0 general)