/* Returns 0 in case of error, or length of printed string  */
static int env_print(char *name, int flag)
/* Returns 0 in case of error, or length of printed string  */
static int env_print(char *name, int flag)
{
	char *res = NULL;
	ssize_t len;
	if (name) {
		struct env_entry e, *ep;
		e.key = name;
		e.data = NULL;
		hsearch_r(e, ENV_FIND, &ep, &env_htab, flag);
		if (ep == NULL)
			return 0;
		len = printf("%s=%s\n", ep->key, ep->data);
		return len;
	}
	len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
	if (len > 0) {
		puts(res);
		free(res);
		return len;
	}
	printf("## Error: cannot export environment\n");
	return 0;
}