Exemple #1
0
mib_object_t *
MibRegister( ul32 *Id, u16 IdLen, mib_callback_t Rqs, u16 Type, u16 Support, void *Param )
{
    mib_object_t *object;

    object = (mib_object_t *)x_malloc(sizeof(mib_object_t));
    if (object == 0) {
        x_dbg("XSNMP, MibRegister: object is 0\n", TRUE);
        return 0;
    }
    if( !IdLen )
        x_dbg("XSNMP, MibRegister: Idlen == 0\n", TRUE);
    object->Id = (ul32 *)x_malloc(IdLen * sizeof(l32));
    if (object->Id == 0) {
        x_dbg("XSNMP, MibRegister: object->ID is 0\n", TRUE);
        return 0;
    }
    x_memcpy(object->Id, Id, IdLen * sizeof(l32));
    object->IdLen	= IdLen;
    object->Rqs		= Rqs;
    object->Type	= Type;
    object->Support	= Support;
    object->Param	= Param;

    if (!MibObjectInsert(object)) {
        x_free(object->Id);
        x_free(object);
        x_dbg("XSNMP, MibRegister: MibObjectInsert fail\n", TRUE);
        return 0;
    }

    return object;
}
void apply_voronoi (hf_wrapper_struct *hfw) {

//	gint t1;
	if (!hfw->hf_struct->tmp_buf)
		hf_backup(hfw->hf_struct);
	if (!hfw->hf_struct->result_buf)
		hfw->hf_struct->result_buf = 
			(hf_type *) x_malloc(sizeof(hf_type) * hfw->hf_struct->max_x  * hfw->hf_struct->max_y, "hf_type (result_buf in apply_voronoi)");
	if (!hfw->hf_struct->tmp2_buf)
		hfw->hf_struct->tmp2_buf = 
			(hf_type *) x_malloc(sizeof(hf_type) * hfw->hf_struct->max_x  * hfw->hf_struct->max_y, "hf_type (tmp2_buf in apply_voronoi)");
//	t1 = clock();
	// Convention:
	// 1. tmp_buf: original HF
	// 2. tmp2_buf: distance HF
	// 3. result_buf: crackled HF (base level + black lines == cracks)
	// 4. hf_buf: output = crackled HF + distance HF (for lifting edges)

	set_watch_cursor(hfw);	
	hf_voronoi(hfw->hf_struct, hfw->hf_options->img->voronoi);
	
	voronoi_adjust_edges (hfw->hf_struct->result_buf, hfw->hf_struct->hf_buf, hfw->hf_struct->tmp2_buf, hfw->hf_options->img->voronoi->edges_level,  hfw->hf_struct->max_x, hfw->hf_struct->max_y);
	
	unset_watch_cursor(hfw);
// printf("TEMPS DE CRAQU�LEMENT: %d\n",clock() - t1);
}
Exemple #3
0
static int
verify_object(struct conf *conf, struct manifest *mf, struct object *obj,
              struct hashtable *stated_files, struct hashtable *hashed_files)
{
	for (uint32_t i = 0; i < obj->n_file_info_indexes; i++) {
		struct file_info *fi = &mf->file_infos[obj->file_info_indexes[i]];
		char *path = mf->files[fi->index];
		struct file_stats *st = hashtable_search(stated_files, path);
		if (!st) {
			struct stat file_stat;
			if (x_stat(path, &file_stat) != 0) {
				return 0;
			}
			st = x_malloc(sizeof(*st));
			st->size = file_stat.st_size;
			st->mtime = file_stat.st_mtime;
			st->ctime = file_stat.st_ctime;
			hashtable_insert(stated_files, x_strdup(path), st);
		}

		if (fi->size != st->size) {
			return 0;
		}

		if (conf->sloppiness & SLOPPY_FILE_STAT_MATCHES) {
			if (fi->mtime == st->mtime && fi->ctime == st->ctime) {
				cc_log("mtime/ctime hit for %s", path);
				continue;
			} else {
				cc_log("mtime/ctime miss for %s", path);
			}
		}

		struct file_hash *actual = hashtable_search(hashed_files, path);
		if (!actual) {
			struct mdfour hash;
			hash_start(&hash);
			int result = hash_source_code_file(conf, &hash, path);
			if (result & HASH_SOURCE_CODE_ERROR) {
				cc_log("Failed hashing %s", path);
				return 0;
			}
			if (result & HASH_SOURCE_CODE_FOUND_TIME) {
				return 0;
			}
			actual = x_malloc(sizeof(*actual));
			hash_result_as_bytes(&hash, actual->hash);
			actual->size = hash.totalN;
			hashtable_insert(hashed_files, x_strdup(path), actual);
		}
		if (memcmp(fi->hash, actual->hash, mf->hash_size) != 0
		    || fi->size != actual->size) {
			return 0;
		}
	}

	return 1;
}
Exemple #4
0
struct args *
args_init(int init_argc, char **init_args)
{
	struct args *args = (struct args *)x_malloc(sizeof(struct args));
	args->argc = 0;
	args->argv = (char **)x_malloc(sizeof(char *));
	args->argv[0] = NULL;
	for (int i = 0; i < init_argc; i++) {
		args_add(args, init_args[i]);
	}
	return args;
}
Exemple #5
0
static struct hashtable *
create_file_info_index_map(struct file_info *infos, uint32_t len)
{
	struct hashtable *h =
		create_hashtable(1000, hash_from_file_info, file_infos_equal);
	for (uint32_t i = 0; i < len; i++) {
		struct file_info *fi = x_malloc(sizeof(*fi));
		*fi = infos[i];
		uint32_t *index = x_malloc(sizeof(*index));
		*index = i;
		hashtable_insert(h, fi, index);
	}
	return h;
}
Exemple #6
0
bignum_t * bignum_reverse (bignum_t * num) {
	bignum_t * rev = x_malloc (sizeof (bignum_t));

	bignum_init (rev);

	rev->allocated = num->used;
	rev->used = num->used;
	rev->digits = x_malloc (rev->allocated);

	for (size_t i = 0; i < num->used; i++)
		rev->digits[i] = num->digits[num->used - 1 - i];

	return rev;
}
Exemple #7
0
static void conv_write_comms() {
  int i, j;
  int n, p, t;

  /*MPI Communicators*/
  for (i=0; i<numcomm; i++) {
    if ( commtab[i].numbyte ) {
      char *name = x_malloc(16 * sizeof(char));
      unsigned int *array;
      int num = 0;

      for (j=0; j<(commtab[i].numbyte*8); j++) {
        if ( (1 << (j % 8)) & commtab[i].bits[j/8] ) num++;
      }
      if (num) commtab[i].array = array = x_malloc(num * sizeof(unsigned int));
      num = 0;
      for (j=0; j<(commtab[i].numbyte*8); j++) {
        if ( (1 << (j % 8)) & commtab[i].bits[j/8] )
          array[num++] = get_comm_loc(j);
      }
      commtab[i].numarray = num;

      if ( commtab[i].mode & ELG_GROUP_FLAG )
        sprintf(name, "group %d", i);
            else
        sprintf(name, "comm %d", i);
      if (num) wbytes += VTF3_WriteDefcpugrp(fcb, ++grpid, num, array, name);
    }
  }

  /*OpenMP Thread Groups*/
  if ( isthreaded ) {
    for (n=0; n<machine[0].num_member; n++) {
      Group *node = machine[0].member + n;
      for (p=0; p<node->num_member; p++) {
        Group *proc = node->member + p;
        char *name = x_malloc(16 * sizeof(char));
        unsigned int *array = x_malloc(proc->num_member * sizeof(unsigned int));
        for (t=0; t<proc->num_member; t++) {
          array[t] = proc->member[t].id;
        }
        sprintf(name, "tgroup %d", /*maxcomm + 1 +*/ proc->id);
        wbytes += VTF3_WriteDefcpugrp(fcb, ++grpid, proc->num_member,
                                      array, name);
      }
    }
  }
}
int	copy_tab_minus_one(char ***dest, char **src, int index)
{
  int	cnt;
  int	tmp;
  int	cnt_max;

  cnt = tmp = 0;
  while (src[cnt] != '\0')
    cnt++;
  cnt_max = cnt;
  if ((*dest = x_malloc(sizeof(**dest) * (cnt))) == NULL)
    return (0);
  cnt = 0;
  while (cnt <= cnt_max)
    {
      if (((*dest)[tmp++] = my_strdup(src[cnt++])) == NULL)
	return (0);
      if (cnt == index)
	cnt++;
      if (cnt >= cnt_max)
	{
	  (*dest)[tmp] = '\0';
	  return (0);
	}
    }
  (*dest)[tmp] = '\0';
  return (1);
}
Exemple #9
0
error *errorReply(error *in_error, int in_reply_code, const char *in_text, ...)
{
	error *toRet = x_malloc(sizeof(error), errorFree);
	
	if (toRet)
	{
		memset(toRet, 0, sizeof(error));
		toRet->m_code = in_reply_code;
		
		if (in_error)
		{
			toRet->m_next = in_error->m_next;
			in_error->m_next = NULL;
		}
		
		va_list v;
		va_start(v, in_text);
		vasprintf(&toRet->m_string, in_text, v);
		va_end(v);
	}
	else
		return &errorDefault;
	
	return toRet;
}
Exemple #10
0
static bool
init_log(void)
{
	extern struct conf *conf;

	if (debug_log_buffer || logfile || use_syslog) {
		return true;
	}
	assert(conf);
	if (conf->debug) {
		debug_log_buffer_capacity = DEBUG_LOG_BUFFER_MARGIN;
		debug_log_buffer = x_malloc(debug_log_buffer_capacity);
		debug_log_size = 0;
	}
	if (str_eq(conf->log_file, "")) {
		return conf->debug;
	}
#ifdef HAVE_SYSLOG
	if (str_eq(conf->log_file, "syslog")) {
		use_syslog = true;
		openlog("ccache", LOG_PID, LOG_USER);
		return true;
	}
#endif
	logfile = fopen(conf->log_file, "a");
	if (logfile) {
#ifndef _WIN32
		set_cloexec_flag(fileno(logfile));
#endif
		return true;
	} else {
		return false;
	}
}
Exemple #11
0
static bool
_internal_get_from_bb_bin_alloc (xmmsv_t *bb,
                                 unsigned char **buf,
                                 unsigned int *len)
{
	unsigned char *b;
	int32_t l;

	if (!_internal_get_from_bb_int32_positive (bb, &l)) {
		return false;
	}

	b = x_malloc (l);
	if (!b) {
		return false;
	}

	if (!_internal_get_from_bb_data (bb, b, l)) {
		free (b);
		return false;
	}

	*buf = b;
	*len = l;

	return true;
}
Exemple #12
0
void save_render_options_inc (render_struct *rs) {
//	Private method, added 2007-01-01
//	Save some render options in render_options.inc, in the current directory
//	those that are not camera related
//	and that cannot be specified on the command line
	FILE *fin;
	gchar *msg_buf, str_format[100], *ext;
	if (!(fin=fopen("render_options.inc","wb"))) {
		msg_buf = (gchar *) x_malloc(sizeof(gchar) + strlen("render_options.inc") + strlen(_("Not able to open '%s' file for writing"))+5, "const gchar (msg_buf - open file for writing)");
		sprintf(msg_buf,_("Not able to open '%s' file for writing"),"render_options.inc");
		my_msg(msg_buf,WARNING);
	}
	else {
//		loc = setlocale(LC_NUMERIC,""); // Povray uses "." as decimal separator instead of ","
//		setlocale(LC_NUMERIC,"C");
		if (*rs->if_creation || *rs->if_modified) {
			// The PNG file to render is written in a temporary directory
			fprintf(fin,"#declare hf_to_render = %c%s%c;\n",'\"',HF_OUTPUT_FOR_RENDERING,'\"');
			fprintf(fin,"#declare temporary_directory = %c%s%c;\n",'\"',TMP_DIR,'\"');
		}
		else
			// If the current height field has not been changed, we render the source file
			fprintf(fin,"#declare hf_to_render = %c%s%c;\n",'\"',*rs->filename,'\"');
		fprintf(fin,"#declare current_directory = %c%s%c;\n",'\"',*rs->dirname,'\"');
		ext = strstr(*rs->filename,".png");
		if (ext) {
			sprintf(str_format, "#declare fname_radix = %%c%%%d.%ds%%c;\n", ext-*rs->filename,ext-*rs->filename);
//			printf("STR_FORMAT: %s\n",str_format);
			fprintf(fin,str_format,'\"',*rs->filename,'\"');
		}
//		setlocale(LC_NUMERIC,loc);
		fclose(fin);
	}
}
Exemple #13
0
/**
 * set attribute of type to malloc'ed value copy of val.
 */
static int
stun_set_attr_d(stun_packet_t *pkt, int atype, int len, char *val)
{
  int i;

  i = stun_attr_id(pkt, atype);
  //TRACE("))))))))))))))))) 2 i=%d, attrnum(%d)\n",i,(int)pkt->attrnum);

  if (i < 0)
    {
      pkt->attrs = x_realloc(pkt->attrs,
          sizeof(stun_attr_t) * (pkt->attrnum + 2));
      i = pkt->attrnum;
    }

  //TRACE("))))))))))))))))) 3\n");

  pkt->attrs[i].type = (uint16_t) atype;
  pkt->attrs[i].len = (uint16_t) len;
  if (pkt->attrs[pkt->attrnum].len)
    {
      //      TRACE("))))))))))))))))) 4\n");

      pkt->attrs[i].data = x_malloc(pkt->attrs[i].len);
      x_memcpy(pkt->attrs[pkt->attrnum].data, val, len);
    }
  else
    pkt->attrs[i].data = NULL;
  // end with NULL
  pkt->attrs[++pkt->attrnum].type = 0;

  // TRACE("))))))))))))))))) 5\n");

  return 0;
}
Exemple #14
0
/**
 * returns x-mapped address buffer
 */
static char *
stun_x_mapped(struct sockaddr_in *saddr)
{
  uint16_t port;
  uint32_t ip;
  char *xmapped;

  ENTER;

  xmapped = (char *) x_memset(x_malloc(8), 0, 8);

  xmapped[0] = 0;
  xmapped[1] = 1; // ipv4

  TRACE("MAPPING %s:%d\n", inet_ntoa(saddr->sin_addr), ntohs(saddr->sin_port));

  ip = ntohl(saddr->sin_addr.s_addr);
  port = ntohs(saddr->sin_port);
  port ^= 0x2112;
  ip ^= STUN_M_COOKIE;

  port = htons(port);
  ip = htonl(ip);

  x_memcpy(xmapped + 2, &port, 2);
  x_memcpy(xmapped + 4, &ip, 4);

  EXIT;
  return xmapped;
}
Exemple #15
0
swirl_struct *swirl_pen_new() {
	swirl_struct *s;
	s = (swirl_struct *) x_malloc(sizeof(swirl_struct), "swirl_struct");
	s->size = 81;
	s->angle = 0;
	return s;
}
Exemple #16
0
bignum_t * bignum_get_str (const char * value) {
	bignum_t * num = x_malloc (sizeof (bignum_t));

	bignum_init (num);

	while (isblank (*value))
		value++;

	if (*value == '-')
		num->sign = true;

	const char * tail_ptr = NULL;

	if (!*value)
		tail_ptr = value;
	else
		tail_ptr = value + strlen (value) - 1;

	while (tail_ptr > value && isspace (*tail_ptr))
		tail_ptr--;

	while (tail_ptr >= value && isdigit (*tail_ptr)) {
		ensure_allocation (num);
		num->digits[num->used++] = *tail_ptr - '0';

		tail_ptr--;
	}

	if (num->allocated == 0) {
		free (num);
		return bignum_get (0);
	}

	return num;
}
Exemple #17
0
//Creates a new coherence engine
mpCoherence *mpCCreate(int in_data, int in_tasks, int in_cache)
{
	errorAssert(in_data > 0, error_flags, "Need positive number of data sets");
	errorAssert(in_tasks > 0, error_flags, "Need positive number of tasks");
	errorAssert(in_cache > 0, error_flags, "Need positive number of caches");
	
	mpCoherence *o = x_malloc(sizeof(mpCoherence), mpCFree);
	memset(o, 0, sizeof(mpCoherence));
	
	x_pthread_mutex_init(&o->m_mutex, NULL);
	
	o->r_tasks = malloc(sizeof(mpCoTask) * in_tasks);
	memset(o->r_tasks, 0, sizeof(mpCoTask) * in_tasks);
	errorAssert(o->r_tasks != NULL, error_memory,
				"Failed allocating %i bytes for tasks",
				sizeof(mpCoTask) * in_tasks);
	
	o->m_nMaxTasks = in_tasks;
	o->m_nData = in_data;
	o->m_cacheSize = in_cache;
	
#ifdef SEQUENTIAL
	o->r_stack = mpStackCreate(in_tasks * 2);
#endif
	
#ifdef COHERENCE_TQ
	o->r_q = mpQueueCreate(2048);
#else
	o->r_q = mpQueueCreate(2);		//Nice temp value
#endif
	
	return o;
}
Exemple #18
0
static void		get_path(t_env *val)
{
	int		i;
	int		j;
	char	*str;

	i = 5;
	j = 0;
	while (val->env[j] != '\0')
	{
		if (val->env[j][0] == 'P' && val->env[j][1] == 'A'
			&& val->env[j][2] == 'T' && val->env[j][3] == 'H')
			break ;
		else
			j++;
	}
	str = (char *)x_malloc(sizeof(char) * ft_strlen(val->env[j]) - 4);
	while (val->env[j][i] != '\0')
	{
		str[i - 5] = val->env[j][i];
		i++;
	}
	val->path = ft_strsplit(str, ':');
	free(str);
	str = NULL;
}
Exemple #19
0
char *get_string_conf(char *conf_str, char *buf)
{
    char *ptr1, *ptr2, *opt_conf;

    if((strncmp(buf, conf_str, strlen(conf_str))) == 0)
    {
        ptr1 = strchr(buf, '{');

        if(ptr1 == NULL)
            return NULL;

        ptr1++;

        ptr2 = strchr(buf, '}');

        if(ptr2 == NULL)
            return NULL;

        if((ptr2 - ptr1) > (MAX_CONFIGURATION_LINE_LEN - strlen(conf_str)))
            return NULL;

        opt_conf = (char *) x_malloc(ptr2 - ptr1 + 1);

        strlcpy(opt_conf, ptr1, ptr2 - ptr1 + 1);

#ifdef DEBUG
    fprintf(stdout, "Got string option: %s %s\n", conf_str, opt_conf);
#endif
    }

    return opt_conf;
}
Exemple #20
0
int				main(int argc, char *argv[], char *envp[])
{
	t_tree		*tree;
	t_env		*env;
	char		buf[SIZE];
	int			ret;

	env = (t_env *)x_malloc(sizeof(t_env));
	env->env = get_env(envp);
	get_path(env);
	while (argv || argc)
	{
		ft_bzero(buf, SIZE);
		print_prompt();
		ft_printf(" $>");
		if ((ret = read(0, buf, SIZE)) < 2)
			continue ;
		buf[ret - 1] = '\0';
		env->fst_cmd = ft_strdup(buf);
		if (!(tree = init_tree(env->fst_cmd)))
			continue ;
		ft_cmd_path(tree, env);
		ft_process(tree, env);
		free_tree(tree);
		free(env->fst_cmd);
	}
	return (0);
}
Exemple #21
0
static bool
_internal_get_from_bb_string_alloc (xmmsv_t *bb, char **buf,
                                    unsigned int *len)
{
	char *str;
	int32_t l;

	if (!_internal_get_from_bb_int32_positive (bb, &l)) {
		return false;
	}

	str = x_malloc (l + 1);
	if (!str) {
		return false;
	}

	if (!_internal_get_from_bb_data (bb, str, l)) {
		free (str);
		return false;
	}

	str[l] = '\0';

	*buf = str;
	*len = l;

	return true;
}
Exemple #22
0
void		init_term(t_area *ar, char **argv, int argc)
{
  extern char	**environ;

  ar->term = cpy_from_env(environ, "TERM=");
  if (ar->term == NULL)
    {
      my_put_error(ERR_TERM);
      exit(EXIT_FAILURE);
    }
  x_tgetent(tgetent(ar->bp, ar->term));
  ar->area = ar->t;
  ar->clstr = xtgetstr("cl", &(ar->area));
  ar->cmstr = xtgetstr("cm", &(ar->area));
  ar->sostr = xtgetstr("so", &(ar->area));
  ar->sestr = xtgetstr("se", &(ar->area));
  ar->usstr = xtgetstr("us", &(ar->area));
  ar->uestr = xtgetstr("ue", &(ar->area));
  ar->li = tgetnum("li");
  ar->co = tgetnum("co");
  tputs(ar->clstr, 1, my_outc);
  argc = make_argc(ar, argc);
  ar->ac = argc - 1;
  ar->res = malloc(argc * sizeof(*(ar->res)));
  x_malloc(ar->res, argc);
  init_size(ar, argv);
  my_arg_cpy(ar, argv, argc);
}
Exemple #23
0
log_handler_t *log_create_handler(int verbose_level, int motion, const char *path, char **errstr) {
  handler_t *handler;
  char buffer[256];

  // allocate handler
  handler=(handler_t *)x_malloc(sizeof(handler_t));

  // set level
  handler->level=verbose_level;

  // motion
  handler->motion=motion;

  // open stream
  if(path==NULL)
    handler->stream=stdout;
  else {
    errno=0;
    handler->stream=fopen(path, "a");
    if(handler->stream==NULL) {
      x_asprintf(errstr, "Error opening log file '%s': %s", path, strerror_r(errno, buffer, 256));
      return NULL;
    }
  }

  return (log_handler_t *)handler;
}
Exemple #24
0
bool
MibObjectInsert( mib_object_t *Object )
{
    i32 mindex, cmp, i;

    if(MibRoot->Count >= MibRoot->Size) {
        i32 n;
        mib_object_t **p;

        n = MibRoot->Size + 100;
        if( MibRoot->Table )
            p = (mib_object_t **)x_realloc(MibRoot->Table, n*sizeof(mib_object_t *));
        else
            p = (mib_object_t **)x_malloc(sizeof(mib_object_t *));
        if (p == 0)
            return FALSE;
        MibRoot->Table = p;
        MibRoot->Size = n;
    }

    MibRoot->Table[MibRoot->Count] = Object;
    MibRoot->Count++;

    mindex = MibObjectFind(Object->Id, Object->IdLen, &cmp);
    if (cmp == 0 && mindex != MibRoot->Count-1) {
        MibRoot->Count--;
        return FALSE;
    }

    for(i = MibRoot->Count-1; i > mindex; i--)
        MibRoot->Table[i] = MibRoot->Table[i-1];
    MibRoot->Table[mindex] = Object;

    return TRUE;
}
Exemple #25
0
char	*epur_line(char *line)
{
  int	i;
  int	n;
  char	*ret;

  i = 0;
  n = 0;
  if (line == NULL)
    return (NULL);
  ret = x_malloc(strlen(line));
  while (line[i] == ' ' || line[i] == '\t')
    i++;
  while (line[i + n] != '\0')
    {
      while (line[i + n] != '\0' && (line[i + n] == ' ' || line[i + n] == '\t')
	     && (line[i + n + 1] == ' ' || line[i + n + 1] == '\t'))
	i++;
      ret[n] = line[i + n];
      if (line[i + n] != '\0')
	n++;
    }
  ret[n] = '\0';
  free (line);
  return (ret);
}
Exemple #26
0
static int
x_vcam_on_append(x_object *so, x_object *parent)
{
  int ofd;
  virtual_camera_t *mctl = (virtual_camera_t *) so;
  ENTER;

  mctl->w = 320;
  mctl->h = 240;

  /* init capture */
  mctl->vfd = v4l2_capture_init(&mctl->_framebuf, &mctl->w, &mctl->h);
  mctl->framebuf = x_malloc(mctl->w * mctl->h * 3 / 2 + 1);

  TRACE("Opend camera at %dx%d\n", mctl->w, mctl->h);

  mctl->cam_qwartz.data = (void *) so;

  /** @todo This should be moved in x_object API */
  ev_periodic_init(&mctl->cam_qwartz, __vcam_periodic_cb, 0., 0.06667, 0);

  x_object_add_watcher(so, &mctl->cam_qwartz, EVT_PERIODIC);

#ifdef DEBUG
  ofd = open("yuv.out.dump", O_RDWR | O_TRUNC | O_CREAT,
      S_IRWXU | S_IRWXG | S_IRWXO);
  close(ofd);
#endif

  EXIT;
  return 0;
}
Exemple #27
0
mib_local_t *
MibInsert( snmp_object_t *Obj, mib_local_t **local, u16 IdLen, u16 IdSize )
{
    mib_local_t * Junk;
    mib_local_t	* Local = *local;

    if(Obj->IdLen != (u32)(IdLen + IdSize) || Obj->Id[IdLen] < 1) {
        return NULL;
    }
    if((Junk = (mib_local_t *)x_malloc(sizeof(mib_local_t))) == NULL) {
        return NULL;
    }
    Junk->Index = Obj->Id[IdLen];

    if(Local == NULL || Local->Index > Junk->Index) {
        Junk->Next = Local;
        *local = Junk;
        return Junk;
    }
    while(Local->Next != NULL && Local->Next->Index <= Junk->Index)
        Local = Local->Next;
    if(Local->Index == Junk->Index) {
        x_free(Junk);
        return Local;
    }
    Junk->Next = Local->Next;
    Local->Next = Junk;

    return Junk;
}
char		*get_next_line(const int fd, t_mysh *all)
{
  int		rd;
  char		*output;
  static int	i = 0;
  static char	*buffer = NULL;

  /*  if (fd == 0)
      return (empty_buffer(buffer));*/
  rd = 1;
  if (buffer == NULL || buffer[i] == '\0')
    if ((buffer = my_read(fd, &i, &rd, buffer)) == NULL)
      return (NULL);
  output = x_malloc(sizeof(output) * (BUF_SIZE + 1));
  all->gnl_j = 0;
  while (buffer[i] != '\n' && rd > 0)
    if (buffer[i] == '\0')
      {
	if ((buffer = my_read(fd, &i, &rd, buffer)) == NULL)
	  return (output);
	output = my_realloc(all->gnl_j, output);
      }
    else
      output[all->gnl_j++] = buffer[i++];
  output[all->gnl_j] = '\0';
  i++;
  return (output);
}
Exemple #29
0
void gl_save_water_inc (gl_preview_struct *gl_preview) {
//	Public method
//	Save the current water plane parameters in "geomorph_water.inc" in the current directory
//	Eventually move in a scene management file

	FILE *fin;
	gchar *loc, *tmp, *msg_buf;
	if (!(fin=fopen("water.inc","wb"))) {
		msg_buf = (gchar *) x_malloc(sizeof(gchar) + strlen("water.inc") + strlen(_("Not able to open '%s' file for writing"))+5 , "const gchar (msg_buf - open file for writing)");
		sprintf(msg_buf,_("Not able to open '%s' file for writing"),"water.inc");
		my_msg(msg_buf,WARNING);
	}
	else {
		tmp = setlocale(LC_NUMERIC,NULL); // Povray uses "." as decimal separator instead of ","
		loc = (gchar *) malloc(strlen(tmp)+1);
		strcpy(loc,tmp);
		setlocale(LC_NUMERIC,"C");
		if (gl_preview->use_water && *gl_preview->use_water)
			fprintf(fin,"#declare preview_water_level = %5.2f;\n",*gl_preview->water_level);
		else
			fprintf(fin," ");
		setlocale(LC_NUMERIC,loc);
		free(loc);
		fclose(fin);
	}
}
Exemple #30
0
view_struct *view_struct_new_with_rgb (gint width, gint height, void (*calc_buf) (gpointer, unsigned char*, gint, gint), gpointer external_data, gboolean if_rgb)  {
//	Builds a preview structure, for a 8 bits image
	view_struct *vs;
	vs = (view_struct *) x_malloc(sizeof(view_struct), "view_struct");
//	printf("View_struct_new: %d\n",vs);
	vs->width = width;
	vs->height = height;
	vs->calc_buf = calc_buf;
	vs->external_data = external_data;
	vs->if_rgb = if_rgb;

	if (if_rgb)
		vs->buf8 = (unsigned char *) x_calloc(3*width*height,sizeof(unsigned char), "unsigned char (vs->buf8 in view_area.c)");
	else
		vs->buf8 = (unsigned char *) x_calloc(width*height,sizeof(unsigned char), "unsigned char (vs->buf8 in view_area.c)");

	vs->area = gtk_drawing_area_new();
	gtk_widget_set_size_request( GTK_WIDGET(vs->area), vs->width, vs->height);
	gtk_signal_connect(GTK_OBJECT(vs->area), "configure_event",
		(GtkSignalFunc) area_configure_event, (gpointer) vs);
	gtk_signal_connect(GTK_OBJECT(vs->area),"expose_event",
		(GtkSignalFunc) area_expose_event, (gpointer) vs);
	gtk_widget_show(vs->area);

	vs->viewport = NULL;
	return vs;
}