示例#1
0
int		program_load_datas(t_list *programs)
{
  t_list_item	*item;
  t_program	*program;
  int		header_len;

  header_len = MAGIC_LEN + PROG_NAME_LENGTH
    + SIZE_CONTENT_LENGTH + COMMENT_LENGTH + 4;
  item = programs->top;
  while (item != NULL)
    {
      program = (t_program *)item->data;
      if (load_data(program) == RET_FAILURE)
	return (RET_FAILURE);
      if (program->data_len < header_len)
	return (error_int(RET_FAILURE, ERR_INVALID_HEADER));
      else if (program->data_len == header_len)
	return (error_int(RET_FAILURE, ERR_CONTENT_EMPTY));
      if (check_magic(program->data) == RET_FAILURE)
	return (RET_FAILURE);
      program->code = program->data + header_len;
      program->code_len = program->data_len - header_len;
      item = item->next;
    }
  return (RET_SUCCESS);
}
示例#2
0
int		find_full_path(t_info *info)
{
  char		*path;
  int		i;
  char		*line;
  char		*tp;

  i = 0;
  path = my_getenv(info, "PATH");
  if (path == NULL)
    return (error_int("Variable PATH doesn't exist", 1));
  tp = strtok(path, ":");
  check_line(tp, info);
  while ((tp = strtok(NULL, ":")))
    {
      if (check_line(tp, info) == RETURN_SUCCESS)
	{
	  free(path);
	  return (RETURN_SUCCESS);
	}
      memset(tp, '\0', strlen(tp));
    }
  free(tp);
  free(path);
  return (RETURN_ERROR);
}
示例#3
0
文件: api_pattern.C 项目: juddy/edcde
Tt_category
tt_pattern_category(Tt_pattern p)
{
	_Tt_audit audit;
        Tt_status status = audit.entry("P", TT_PATTERN_CATEGORY, p);
	Tt_category result;

        if (status != TT_OK) {
		audit.exit((Tt_category)error_int(status));
                return (Tt_category)error_int(status);
        }

        result = _tt_pattern_category(p);
        audit.exit(result);

	return result;
}
示例#4
0
static int	check_file(t_program *prgm, int i, const char **argv)
{
  int		fd;

  if (argv[i][0] != '-')
    {
      if (i - 1 > 0)
	if (argv[i - 1][0] == '-')
	  return (RET_SUCCESS);
      if ((fd = open(argv[i], O_RDONLY)) == RET_ERROR)
	return (error_int(RET_FAILURE, ERR_FILE_UNEXIST));
      close (fd);
      if ((prgm->file = my_strdup(argv[i])) == NULL)
	return (error_int(RET_FAILURE, ERR_GENERAL));
    }
  return (RET_SUCCESS);
}
示例#5
0
static int      check_n(t_program *prgm, int i, int argc, const char **argv)
{
  if (my_match(argv[i], "-n"))
    {
      if (prgm->player_id != -1)
	return (error_int(RET_FAILURE, ERR_N_REPEAT));
      if (i + 1 < argc)
	{
	  if (!my_str_isnum(argv[i + 1])
	      || (prgm->player_id = my_getnbr(argv[i + 1])) < 0)
	    return (error_int(RET_ERROR, ERR_N_INVALID_VAL));
	}
      else
	return (error_int(RET_FAILURE, ERR_N_NO_VAL));
    }
  return (RET_SUCCESS);
}
示例#6
0
static int	check_magic(char *data)
{
  static char	cor_magic[4] = COREWAR_EXEC_MAGIC;

  if (my_mem_isequal(data, cor_magic, 4) == false)
    return (error_int(RET_FAILURE, ERR_BAD_MAGIC));
  return (RET_SUCCESS);
}
示例#7
0
static int	load_data(t_program *program)
{
  int		fd;

  if ((fd = open(program->file, O_RDONLY)) == RET_ERROR)
    return (error_int(RET_FAILURE, ERR_OPEN_RD));
  if ((program->data_len = get_data_size(fd)) == RET_ERROR)
    return (RET_FAILURE);
  if (lseek(fd, SEEK_SET, 0) == RET_ERROR)
    return (error_int(RET_FAILURE, ERR_LSEEK));
  if ((program->data = malloc(program->data_len * sizeof(char))) == NULL)
    return (error_int(RET_FAILURE, ERR_MALLOC));
  if (read(fd, program->data, program->data_len) != program->data_len)
    return (error_int(RET_FAILURE, ERR_READ));
  if (close(fd) == RET_ERROR)
    return (error_int(RET_SUCCESS, WAR_CLOSE));
  return (RET_SUCCESS);
}
示例#8
0
int		params_get_files(t_list *programs, int argc,
				 const char **argv)
{
  t_program	*program;
  int		i;

  if ((program = program_new()) == NULL)
    return (error_int(RET_FAILURE, ERR_GENERAL));
  i = 1;
  while (i < argc)
    {
      if (fill_program(program, i, argc, argv) == RET_FAILURE)
	return (RET_FAILURE);
      if (program->file)
	{
	  if (my_list_enqueue(programs, program) == RET_FAILURE)
	    return (error_int(RET_FAILURE, ERR_GENERAL));
	  if (i + 1 < argc && (program = program_new()) == NULL)
	    return (error_int(RET_FAILURE, ERR_GENERAL));
	}
      i++;
    }
  return (RET_SUCCESS);
}
示例#9
0
static int	get_data_size(int fd)
{
  int		ret;
  char		buf[64];
  int		size;

  size = 0;
  while ((ret = read(fd, buf, 64)) != 0)
    {
      if (ret < 0)
	return (error_int(RET_ERROR, ERR_READ));
      size += ret;
    }
  return (size);
}