char *
_textdomain_u(const char *domain, char *result)
{
	char	*p;
	size_t	domain_len;
	Gettext_t	*gt = global_gt;

#ifdef GETTEXT_DEBUG
	gprintf(0, "*************** _textdomain_u(\"%s\", 0x%p)\n",
	    (domain ? domain : ""), (void *)result);
#endif

	/* Query is performed for NULL domain pointer */
	if (domain == NULL) {
		(void) strcpy(result, CURRENT_DOMAIN(gt));
		return (result);
	}

	/* check for error. */
	/*
	 * domain is limited to TEXTDOMAINMAX bytes
	 * excluding a null termination.
	 */
	domain_len = strlen(domain);
	if (domain_len > TEXTDOMAINMAX) {
		/* too long */
		return (NULL);
	}

	/*
	 * Calling textdomain() with a null domain string sets
	 * the domain to the default domain.
	 * If non-null string is passwd, current domain is changed
	 * to the new domain.
	 */

	/* actually this if clause should be protected from signals */
	if (*domain == '\0') {
		if (CURRENT_DOMAIN(gt) != default_domain) {
			free(CURRENT_DOMAIN(gt));
			CURRENT_DOMAIN(gt) = (char *)default_domain;
		}
	} else {
		p = malloc(domain_len + 1);
		if (p == NULL)
			return (NULL);
		(void) strcpy(p, domain);
		if (CURRENT_DOMAIN(gt) != default_domain)
			free(CURRENT_DOMAIN(gt));
		CURRENT_DOMAIN(gt) = p;
	}

	(void) strcpy(result, CURRENT_DOMAIN(gt));
	return (result);
} /* _textdomain_u */
Exemple #2
0
/*
 * textdomain() sets or queries the name of the current domain of
 * the active LC_MESSAGES locale category.
 */
char *
textdomain(const char *domain)
{
	char	*res;
	char	tmp_domain[TEXTDOMAINMAX + 1];

	callout_lock_enter();
	INIT_GT(NULL);
	res = _textdomain_u(domain, tmp_domain);
	if (res == NULL) {
		callout_lock_exit();
		return (NULL);
	}
	callout_lock_exit();
	return (CURRENT_DOMAIN(global_gt));
}