Exemplo n.º 1
0
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;
}
Exemplo n.º 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;
}