Ejemplo n.º 1
0
int		open_fd(t_ftp *ftp, char *arg)
{
  char		*newpath;
  int		fd;
  struct stat	buf;

  newpath = NULL;
  fd = -1;
  if ((newpath = realpath(arg, NULL)) != NULL)
    {
      if (stat(arg, &buf) == -1)
	return (bad_file(arg));
      ftp->filesize = buf.st_size;
      if (buf.st_size == 0 || (buf.st_mode & S_IFDIR))
	return (-1);
    }
  else
    return (-1);
  if (strncmp(ftp->homepwd, newpath, strlen(ftp->homepwd)) != 0)
    return (-1);
  if ((fd = open(arg, O_RDONLY)) == -1)
    {
      printf("No such file or directory\n");
      return (-1);
    }
  return (fd);
}
Ejemplo n.º 2
0
TEST(LogFileOutput, invalid_file) {
  ResourceMark rm;
  stringStream ss;

  // Attempt to log to a directory (existing log not a regular file)
  create_directory("tmplogdir");
  LogFileOutput bad_file("file=tmplogdir");
  EXPECT_FALSE(bad_file.initialize("", &ss))
    << "file was initialized when there was an existing directory with the same name";
  EXPECT_TRUE(string_contains_substring(ss.as_string(), "tmplogdir is not a regular file"))
    << "missing expected error message, received msg: %s" << ss.as_string();
  remove("tmplogdir");
}
Ejemplo n.º 3
0
t_p		*size_m(t_p *f, char **argv)
{
	int		fd;
	char	*line;
	int		ret;

	fd = open(argv[1], O_RDONLY);
	if (fd == -1)
		bad_file();
	while ((ret = get_next_line(fd, &line)) > 0)
	{
		if (line[0] != ' ' && ft_isdigit(line[0]) == 0)
			bad_file();
		free(line);
		f->size++;
	}
	if (ret < 0)
		bad_file();
	if (f->size <= 1)
		too_small();
	close(fd);
	return (f);
}
Ejemplo n.º 4
0
int		main(int argc, char **argv)
{
	int			fd;
	static t_p	*f;

	fd = 0;
	if (!argv[1])
	{
		ft_putstr_fd("No file\n", 2);
		return (-1);
	}
	if (argc != 2)
		return (-1);
	f = malloc(sizeof(t_p));
	fd = open(argv[1], O_RDONLY);
	if (fd == -1)
		bad_file();
	f = size_m(f, argv);
	f = stock(f, fd);
	f = window(f);
	f = convint(f);
	fdf(f);
	return (0);
}