bool_t saveenv(char * file)
{
	struct environ_t * environ = &(runtime_get()->__environ);
	struct environ_t * p;
	struct xml * root, * env;
	char * str;
	int fd;

	root = xml_new("environment");
	if(!root)
		return FALSE;

	for(p = environ->next; p != environ; p = p->next)
	{
		env = xml_add_child(root, "env", 0);
		xml_set_txt(env, p->content);
	}

	str = xml_toxml(root);
	if(!str)
	{
		xml_free(root);
		return FALSE;
	}

	fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
	if(fd < 0)
	{
		free(str);
		xml_free(root);
		return FALSE;
	}

	write(fd, str, strlen(str));
	close(fd);

	free(str);
	xml_free(root);

	return TRUE;
}
Exemple #2
0
/*
 * save environment variable
 */
bool_t saveenv(char * file)
{
	struct xml * root, * env;
	char * str;
	char ** ep;
	int fd;

	root = xml_new("environment");
	if(!root)
		return FALSE;

	for(ep = environ; *ep; ep++)
	{
		env = xml_add_child(root, "env", 0);
		xml_set_txt(env, *ep);
	}

	str = xml_toxml(root);
	if(!str)
	{
		xml_free(root);
		return FALSE;
	}

	fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
	if(fd < 0)
	{
		free(str);
		xml_free(root);
		return FALSE;
	}

	write(fd, str, strlen(str));
	close(fd);

	free(str);
	xml_free(root);

	return TRUE;
}
Exemple #3
0
bool_t console_stdio_save(char * file)
{
	struct xml * root;
	struct xml * in, * out, * err;
	char * str;
	s32_t fd;

	root = xml_new("console");
	if(!root)
		return FALSE;

	in = xml_add_child(root, "stdin", 0);
	if(!in)
	{
		xml_free(root);
		return FALSE;
	}

	if(console_stdin && console_stdin->name)
		xml_set_attr(in, "name", console_stdin->name);

	out = xml_add_child(root, "stdout", 1);
	if(!out)
	{
		xml_free(root);
		return FALSE;
	}

	if(console_stdout && console_stdout->name)
		xml_set_attr(out, "name", console_stdout->name);

	err = xml_add_child(root, "stderr", 1);
	if(!err)
	{
		xml_free(root);
		return FALSE;
	}

	if(console_stderr && console_stderr->name)
		xml_set_attr(err, "name", console_stderr->name);

	str = xml_toxml(root);
	if(!str)
	{
		xml_free(root);
		return FALSE;
	}

	fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
	if(fd < 0)
	{
		free(str);
		xml_free(root);
		return FALSE;
	}

	write(fd, str, strlen((const char *)str));
	close(fd);

	free(str);
	xml_free(root);

	return TRUE;
}