Ejemplo n.º 1
0
// Resolves the given path relative to the current working directory
inline std::string absolute_path(const std::string& path)
{
#ifdef BOOST_IOSTREAMS_WINDOWS
    return path.size() && (path[0] == '/' || path[0] == '\\') ||
           path.size() > 1 && std::isalpha(path[0]) && path[1] == ':' ?
               path :
               current_directory() + '\\' + path;
#else // #ifdef BOOST_IOSTREAMS_WINDOWS
    return path.size() && (path[0] == '/') ?
        path :
        current_directory() + '/' + path;
#endif // #ifdef BOOST_IOSTREAMS_WINDOWS
}
Ejemplo n.º 2
0
void	second_pipe_traitement(char *buffer, char **env,
			       t_traite *tr, int pipefd[2])
{
  int	tst;
  int	directory;

  if ((tr->pid = fork()) == -1)
    exit(EXIT_FAILURE);
  if (tr->pid == 0)
    {
      buffer = tr->tmp;
      buffer = cut_buff_pipe(buffer);
      tr->buff = epure_str(buffer);
      tr->tab = strtab(tr->buff);
      tr->path = find_path(env, tr->path);
      directory = current_directory(tr->tab);
      if (directory == 2)
	tr->exec = test(tr->path, tr->tab[0]);
      close(pipefd[1]);
      dup2(pipefd[0], 0);
      execve(tr->exec, tr->tab, env);
      exit(0);
    }
  close(pipefd[1]);
  close(pipefd[0]);
  wait(&tr->statut);
  if (WIFSIGNALED(tr->statut))
    my_putstr("Segmentation fault\n");
}
Ejemplo n.º 3
0
void	first_pipe_traitement(char *buffer, char **env,
			      t_traite *tr, int pipefd[2])
{
  int	tst;
  int	directory;
  int	error;

  error = pipe(pipefd);
  if (error == -1)
    exit(EXIT_FAILURE);
  if ((tr->pid = fork()) == -1)
    exit(EXIT_FAILURE);
  if (tr->pid == 0)
    {
      tr->buff = epure_str(buffer);
      tr->tab = strtab(tr->buff);
      tr->path = find_path(env, tr->path);
      directory = current_directory(tr->tab);
      if (directory == 2)
	tr->exec = test(tr->path, tr->tab[0]);
      close(pipefd[0]);
      dup2(pipefd[1], 1);
      execve(tr->exec, tr->tab, env);
      exit(0);
    }
  waitpid(tr->pid, &tst, 0);
}
Ejemplo n.º 4
0
int	file(void)
{
int	handle, bytes, badcount;

	FILE *direction;
	char filename[257], curdir[MAXPATH], *buf, answ;

//This gives a 4 Kbyte limit to file input.  See also below
//	buf = malloc(4096);		//init buf for file input
	memset(buf, 0x00, 4096);	//clear buf to avoid errors

	if (buf == NULL)		//test for malloc() error
	{
		printf("WARNING! - Unable to allocate memory for the input buffer\n");
		return 1;			//return errorlevel
	}

	current_directory(curdir);
	printf("Please enter the path and file name you want to input.\n");
//Make sure the file exists or we get an error and are kicked out.
	printf("I've only reserved 4 Kbytes now.\n");
	printf("The current directory is %s\n", curdir);
	scanf("%s", filename);
	handle = open(filename, O_RDONLY);	//my code, file is read-only

	if (handle == -1)		//if file error
	{
		perror("Error ");
		return 1;			//return errorlevel
	}

	if ((bytes = read(handle, buf, 4096)) == -1)	//4 K file limit
	{
		printf("Read Failed.\n");
		return 1;
//		exit(1);			//this line quits execution
	}

	else					//if no error
	{
		printf("Read: %d bytes read.\n", bytes);
		printf("They were :\n%s\n\n", buf); //just here to check for errors.
	}
	close(handle);			//close file

	return 0;
}
	LEMON_UNITTEST_CASE(FileSystemUnittest,exist_Test)
	{
		String current = current_directory();

		current_directory(current);

		LEMON_CHECK(current_directory() == current);

		String dirName = LEMON_TEXT("{C3F0C7DD-A2A8-42B5-BF87-277345DE9774}");

		if(exists(dirName))
		{
			if(is_directory(dirName)) remove_directories(dirName);

			else remove_file(dirName);
		}

		create_directory(dirName);

		LEMON_CHECK(exists(dirName));

		const static size_t children = 100;

		for(size_t i = 0; i < children ; ++ i)
		{
			StringStream stream;

			stream << LEMON_TEXT("{C3F0C7DD-A2A8-42B5-BF87-277345DE9774}/") << i;

			String currentFile = stream.str();

			create_directory(currentFile);

			LEMON_CHECK(exists(currentFile));
		}

		directory_iteartor_t iter(dirName);

		directory_iteartor_t end;

		size_t i;

		for(i = 0;iter != end; ++ iter,++i)
		{
			if(LEMON_TEXT(".") == *iter) continue;

			if(LEMON_TEXT("..") == *iter) continue;

			String path = dirName + LEMON_TEXT("/") + *iter;

			remove_directory(path);

			LEMON_CHECK(!exists(path));
		}

		LEMON_CHECK(children == (i - 2));

		remove_directory(dirName);

		LEMON_CHECK(!exists(dirName));
	}
Ejemplo n.º 6
0
	 uri::fpath fullpath(const uri::fpath & source)
	{
		if(!source.relative()) return source;

		return uri::fpath(current_directory()) / source;
	}