Ejemplo n.º 1
0
char		*mallocat(char *line, char *buffer, int *j, int lus)
{
  int		i;
  char		*dest;
  static int	iter = 1;

  i = 0;
  if (!(dest = gbgc_malloc(NULL, sizeof(char) * (gnl_len(&iter) + BUFF + 1))))
    return (NULL);
  if (line)
    while (line[i])
      {
	dest[i] = line[i];
	i++;
      }
  while ((*j) < lus && buffer[*j] != '\n')
    {
      dest[i] = buffer[(*j)];
      (*j)++;
      i++;
    }
  dest[i] = 0;
  gbgc_free(NULL, line);
  if (buffer[(*j)] == '\n')
    iter = 1;
  return (dest);
}
Ejemplo n.º 2
0
int     compile_raw_code(t_opc *op, char **args)
{
  int   i;

  if (op == NULL || args == NULL || (op->args = gbgc_malloc(NULL, 1)) == NULL)
    return (0);
  op->size = 1;
  i = -1;
  while (args[++i] != NULL)
    {
      if (my_strlen(args[i]) >= 2)
        {
          args[i][2] = '\0';
          op->args[i] = my_getnbr_base(args[i], "0123456789ABCDEF");
          op->size += 1;
          if ((op->args = gbgc_realloc(op->args, op->size - 1, op->size)) ==
              NULL)
            return (0);
        }
      else
        return (0);
    }
  op->size -= 1;
  return (1);
}
Ejemplo n.º 3
0
void   	*my_ptrdup(void *ptr, size_t size)
{
  char 	*dest;

  if (ptr == NULL || !size || (dest = gbgc_malloc(size)) == NULL ||
      (dest = my_memcpy(dest, ptr, size)) == NULL)
    return (NULL);
  return ((void *)dest);
}
Ejemplo n.º 4
0
t_pip	*create_pipe(char *edge1, char *edge2)
{
  t_pip	*out;

  if (edge1 == NULL || edge2 == NULL ||
      (out = gbgc_malloc(NULL, sizeof(t_pip))) == NULL ||
      (out->edge1 = my_strdup(edge1)) == NULL ||
      (out->edge2 = my_strdup(edge2)) == NULL)
    return (NULL);
  return (out);
}
Ejemplo n.º 5
0
void		*gbgc_calloc(size_t n)
{
  unsigned char	*ptr;
  unsigned int	i;

  if (n <= 0 || (ptr = gbgc_malloc(NULL, n)) == NULL)
    return (NULL);
  i = 0;
  while (i++ < n)
    ptr[i - 1] = 0;
  return (ptr);
}
Ejemplo n.º 6
0
t_prog		*add_elem_to_t_prog(t_prog *progs)
{
  t_prog	*res;
  t_prog	*tmp;

  if ((progs == NULL))
    {
      if ((res = gbgc_malloc(NULL, sizeof(t_prog))) == NULL)
	return (NULL);
      clear_prog_struct(res);
      res->next = NULL;
      return (res);
    }
  tmp = progs;
  while (tmp->next)
    tmp = tmp->next;
  if ((res = gbgc_malloc(NULL, sizeof(t_prog))) == NULL)
    return (NULL);
  res->next = NULL;
  tmp->next = res;
  return (progs);
}
Ejemplo n.º 7
0
t_fle	*openstdin()
{
  t_fle	*stdin;

  if ((stdin = gbgc_malloc(NULL, sizeof(t_fle))) == NULL)
    return (NULL);
  stdin->name = my_strdup("stdin");
  stdin->fmode = O_RDONLY;
  stdin->fd = 0;
  stdin->csr = 0;
  stdin->status = NEOF;
  stdin->state = NOT_FLUSHED;
  return (stdin);
}
Ejemplo n.º 8
0
void		*gbgc_realloc(void *ptr, size_t oldsize, size_t newsize)
{
  unsigned char	*nptr;
  unsigned char	*cpy;
  unsigned int	i;

  if ((cpy = ptr) == NULL || oldsize <= 0 || newsize <= 0 ||
      (nptr = gbgc_malloc(NULL, newsize)) == NULL)
    return (NULL);
  i = 0;
  while (i++ < oldsize)
    nptr[i - 1] = cpy[i - 1];
  gbgc_free(NULL, ptr);
  return (nptr);
}
Ejemplo n.º 9
0
t_opc	*get_forkopcode()
{
  t_opc	*opc;

  if ((opc = gbgc_malloc(NULL, sizeof(t_opc))) == NULL)
    return (NULL);
  opc->keyword = my_strdup(op_tab[11].mnemonique);
  opc->nb_args = op_tab[11].nbr_args;
  opc->type[0] = (char)op_tab[11].type[0];
  opc->hexcode = op_tab[11].code;
  opc->nb_cycles = op_tab[11].nbr_cycles;
  opc->description = my_strdup(op_tab[11].comment);
  opc->is_paramoct = 0;
  return (opc);
}
Ejemplo n.º 10
0
t_fle	*my_fopen(char *name, int mode)
{
  t_fle	*out;

  if (name == NULL || (out = gbgc_malloc(NULL, sizeof(t_fle))) == NULL ||
      is_dir(name))
    return (NULL);
  if ((mode & O_WRONLY) || (mode & O_RDWR))
    my_create_file(name);
  if ((out->name = my_strdup(name)) == NULL || (out->fd = open(name, mode)) < 0)
    return (NULL);
  out->fmode = mode;
  out->csr = 0;
  out->buff[0] = 0;
  out->buff[BUFF_SZ] = 0;
  out->status = NEOF;
  out->state = FLUSHED;
  return (out);
}
Ejemplo n.º 11
0
char		*glob_str_malloc(glob_t *globb)
{
  int		len;
  size_t	i;
  char		*res;

  len = 0;
  i = 0;
  if (globb->gl_pathv == NULL)
    return (NULL);
  while (i < globb->gl_pathc)
    {
      if ((globb->gl_pathv[i]))
	len += (my_strlen(globb->gl_pathv[i]) + 1);
      i++;
    }
  ++len;
  if ((res = gbgc_malloc(NULL, sizeof(char) * (len))) == NULL)
    return (NULL);
  return (res);
}
Ejemplo n.º 12
0
void	get_raminfo(t_ram *ram)
{
  int	info_size;
  int	fd;
  char	*buffer;
  char	**data;
  int	j;

  if (ram == NULL || (info_size = my_fgetsize("/proc/meminfo")) < 0 ||
      (buffer = gbgc_malloc(NULL, info_size + 50)) == NULL)
    return;
  if ((fd = open("/proc/meminfo", O_RDONLY)) < 0 ||
      (j = read(fd, buffer, info_size)) < 0)
    return;
  buffer[j] = '\0';
  close(fd);
  if ((data = my_str_to_wordtab(buffer)) == NULL)
    return;
  gbgc_free(NULL, buffer);
  ram->unit = get_memunit(data[2]);
  get_raminfoloop(ram, data, -1);
}
Ejemplo n.º 13
0
int		fill_lwd(t_my_lwd *lwd, t_my_wd *wd, int nb_w, int pos)
{
  int		nb_words;
  int		lp;
  t_my_lwd	*next;

  lp = 0;
  while (!(is_alphanum(wd->str[lp + pos])))
    {
      if (wd->str[lp + pos] == '\0')
	return (nb_w);
      wd->str[lp + pos] = '\0';
      ++lp;
    }
  if ((next = gbgc_malloc(sizeof(t_my_lwd))) == NULL)
    return (-1);
  next->prev = lwd;
  lwd->next = next;
  next->str = wd->str + lp + pos;
  while (is_alphanum(wd->str[++lp + pos]));
  nb_words = fill_lwd(next, wd, ++nb_w, lp + pos);
  return (nb_words);
}