halt='Use strcat(a, b) instead of strncat(a, b, strlen(b))' \
$(_sc_search_regexp)
+# Ensure that each .c file containing a "main" function also
+# calls virGettextInitialize
+sc_gettext_init:
+ @require='virGettextInitialize *\(' \
+ in_vc_files='\.c$$' \
+ containing='\<main *(' \
+ halt='the above files do not call virGettextInitialize' \
+ $(_sc_search_regexp)
+
# We don't use this feature of maint.mk.
prev_version_file = /dev/null
exclude_file_name_regexp--sc_avoid_write = \
^(src/($(_src1))|daemon/libvirtd|tools/virsh-console|tests/($(_test1)))\.c$$
-exclude_file_name_regexp--sc_bindtextdomain = ^(tests|examples)/
+exclude_file_name_regexp--sc_bindtextdomain = .*
+
+exclude_file_name_regexp--sc_gettext_init = ^(tests|examples)/
exclude_file_name_regexp--sc_copyright_usage = \
^COPYING(|\.LESSER)$$
#include <getopt.h>
#include <stdlib.h>
#include <grp.h>
-#include <locale.h>
#include "libvirt_internal.h"
#include "virerror.h"
#include "locking/lock_manager.h"
#include "viraccessmanager.h"
#include "virutil.h"
+#include "virgettext.h"
#ifdef WITH_DRIVER_MODULES
# include "driver.h"
{0, 0, 0, 0}
};
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
+ if (virGettextInitialize() < 0 ||
virInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
exit(EXIT_FAILURE);
util/virfile.c util/virfile.h \
util/virfirewall.c util/virfirewall.h \
util/virfirewallpriv.h \
+ util/virgettext.c util/virgettext.h \
util/virgic.c util/virgic.h \
util/virhash.c util/virhash.h \
util/virhashcode.c util/virhashcode.h \
util/virevent.c \
util/vireventpoll.c \
util/virfile.c \
+ util/virgettext.c \
util/virhash.c \
util/virhashcode.c \
util/virjson.c \
virFirewallStartTransaction;
+# util/virgettext.h
+virGettextInitialize;
+
+
# util/virgic.h
virGICVersionTypeFromString;
virGICVersionTypeToString;
#include <sys/stat.h>
#include <getopt.h>
#include <stdlib.h>
-#include <locale.h>
#include "lock_daemon.h"
#include "virhash.h"
#include "viruuid.h"
#include "virstring.h"
+#include "virgettext.h"
#include "locking/lock_daemon_dispatch.h"
#include "locking/lock_protocol.h"
privileged = geteuid() == 0;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
+ if (virGettextInitialize() < 0 ||
virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <locale.h>
-#include "configmake.h"
#include "internal.h"
#include "virconf.h"
#include "viralloc.h"
#include "domain_conf.h"
+#include "virgettext.h"
static int
.cb = authCallback,
};
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
+ if (virGettextInitialize() < 0)
exit(EXIT_FAILURE);
- }
if (getArgs(argc, argv, &uri, &uuid, &action) < 0)
goto cleanup;
#include <sys/stat.h>
#include <getopt.h>
#include <stdlib.h>
-#include <locale.h>
#include "log_daemon.h"
#include "virhash.h"
#include "viruuid.h"
#include "virstring.h"
+#include "virgettext.h"
#include "log_daemon_dispatch.h"
#include "log_protocol.h"
privileged = geteuid() == 0;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
+ if (virGettextInitialize() < 0 ||
virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
#include <signal.h>
#include <getopt.h>
#include <sys/mount.h>
-#include <locale.h>
#include <grp.h>
#include <sys/stat.h>
#include <time.h>
#include "virdbus.h"
#include "rpc/virnetdaemon.h"
#include "virstring.h"
+#include "virgettext.h"
#define VIR_FROM_THIS VIR_FROM_LXC
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++)
ns_fd[i] = -1;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL ||
+ if (virGettextInitialize() < 0 ||
virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
#include <config.h>
-#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include "virjson.h"
#include "virlease.h"
#include "configmake.h"
+#include "virgettext.h"
#define VIR_FROM_THIS VIR_FROM_NETWORK
program_name = argv[0];
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), program_name);
- exit(EXIT_FAILURE);
- }
-
- if (virThreadInitialize() < 0 ||
+ if (virGettextInitialize() < 0 ||
+ virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), program_name);
exit(EXIT_FAILURE);
#include <fcntl.h>
#include <getopt.h>
#include <sys/utsname.h>
-#include <locale.h>
#include "internal.h"
#include "virbuffer.h"
#include "configmake.h"
#include "virrandom.h"
#include "virstring.h"
+#include "virgettext.h"
#include "storage/storage_driver.h"
char *profile = NULL;
char *include_file = NULL;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
- exit(EXIT_FAILURE);
- }
-
- if (virThreadInitialize() < 0 ||
+ if (virGettextInitialize() < 0 ||
+ virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
exit(EXIT_FAILURE);
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <locale.h>
#include "virutil.h"
#include "virfile.h"
#include "c-ctype.h"
-#include "configmake.h"
#include "virstring.h"
+#include "virgettext.h"
/* we don't need to include the full internal.h just for this */
#define STREQ(a, b) (strcmp(a, b) == 0)
const char *partsep;
bool devmap_nopartsep = false;
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
+ if (virGettextInitialize() < 0)
exit(EXIT_FAILURE);
- }
if (argc == 3 && STREQ(argv[2], "-g")) {
cmd = DISK_GEOMETRY;
#include <config.h>
-#include <locale.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include "virfile.h"
#include "viralloc.h"
#include "virerror.h"
-#include "configmake.h"
#include "virrandom.h"
#include "virstring.h"
+#include "virgettext.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
program_name = argv[0];
- if (setlocale(LC_ALL, "") == NULL ||
- bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
- textdomain(PACKAGE) == NULL) {
- fprintf(stderr, _("%s: initialization failed\n"), program_name);
- exit(EXIT_FAILURE);
- }
-
- if (virThreadInitialize() < 0 ||
+ if (virGettextInitialize() < 0 ||
+ virThreadInitialize() < 0 ||
virErrorInitialize() < 0) {
fprintf(stderr, _("%s: initialization failed\n"), program_name);
exit(EXIT_FAILURE);
--- /dev/null
+/*
+ * virgettext.c: gettext helper routines
+ *
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <locale.h>
+#include <stdio.h>
+
+#include "configmake.h"
+#include "internal.h"
+#include "virgettext.h"
+
+
+/**
+ * virGettextInitialize:
+ *
+ * Initialize standard gettext setup
+ * Returns -1 on fatal error
+ */
+int
+virGettextInitialize(void)
+{
+ if (!setlocale(LC_ALL, "")) {
+ perror("setlocale");
+ /* failure to setup locale is not fatal */
+ }
+
+ if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
+ perror("bindtextdomain");
+ return -1;
+ }
+
+ if (!textdomain(PACKAGE)) {
+ perror("textdomain");
+ return -1;
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * virgettext.h: gettext helper routines
+ *
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+#ifndef __VIR_GETTEXT_H__
+# define __VIR_GETTEXT_H__
+
+int virGettextInitialize(void);
+
+#endif /* __VIR_GETTEXT_H__ */
#include <getopt.h>
#include <sys/time.h>
#include <fcntl.h>
-#include <locale.h>
#include <time.h>
#include <limits.h>
#include <sys/stat.h>
#include <libvirt/libvirt-qemu.h>
#include <libvirt/libvirt-lxc.h>
#include "virfile.h"
-#include "configmake.h"
#include "virthread.h"
#include "vircommand.h"
#include "conf/domain_conf.h"
#include "virtypedparam.h"
#include "virstring.h"
+#include "virgettext.h"
#include "virsh-console.h"
#include "virsh-domain.h"
progname++;
ctl->progname = progname;
- if (!setlocale(LC_ALL, "")) {
- perror("setlocale");
- /* failure to setup locale is not fatal */
- }
- if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
- perror("bindtextdomain");
- return EXIT_FAILURE;
- }
- if (!textdomain(PACKAGE)) {
- perror("textdomain");
+ if (virGettextInitialize() < 0)
return EXIT_FAILURE;
- }
if (isatty(STDIN_FILENO)) {
ctl->istty = true;
#include <errno.h>
#include <getopt.h>
-#include <locale.h>
#if WITH_READLINE
# include <readline/readline.h>
# include <readline/history.h>
#endif
-#include "configmake.h"
#include "internal.h"
#include "viralloc.h"
#include "virerror.h"
#include "virfile.h"
#include "virstring.h"
#include "virthread.h"
+#include "virgettext.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
progname++;
ctl->progname = progname;
- if (!setlocale(LC_ALL, "")) {
- perror("setlocale");
- /* failure to setup locale is not fatal */
- }
- if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
- perror("bindtextdomain");
- return EXIT_FAILURE;
- }
- if (!textdomain(PACKAGE)) {
- perror("textdomain");
+ if (virGettextInitialize() < 0)
return EXIT_FAILURE;
- }
if (isatty(STDIN_FILENO)) {
ctl->istty = true;
#include <stdlib.h>
#include <gettext.h>
#include <getopt.h>
-#include <locale.h>
#include "internal.h"
-#include "configmake.h"
+#include "virgettext.h"
#include "virt-host-validate-common.h"
#if WITH_QEMU
bool quiet = false;
bool usedHvname = false;
- if (!setlocale(LC_ALL, "")) {
- perror("setlocale");
- /* failure to setup locale is not fatal */
- }
- if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
- perror("bindtextdomain");
- return EXIT_FAILURE;
- }
- if (!textdomain(PACKAGE)) {
- perror("textdomain");
+ if (virGettextInitialize() < 0)
return EXIT_FAILURE;
- }
while ((c = getopt_long(argc, argv, "hvq", argOptions, NULL)) != -1) {
switch (c) {
#include <errno.h>
#include <fnmatch.h>
#include <getopt.h>
-#include <locale.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include "virstring.h"
#include "viralloc.h"
#include "vircommand.h"
+#include "virgettext.h"
#define VIR_FROM_THIS VIR_FROM_NONE
static const char *conf_file = SYSCONFDIR "/libvirt/virt-login-shell.conf";
virSetErrorLogPriorityFunc(NULL);
progname = argv[0];
- if (!setlocale(LC_ALL, "")) {
- perror("setlocale");
- /* failure to setup locale is not fatal */
- }
- if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
- perror("bindtextdomain");
- return ret;
- }
- if (!textdomain(PACKAGE)) {
- perror("textdomain");
+ if (virGettextInitialize() < 0)
return ret;
- }
while ((arg = getopt_long(argc, argv, "hV", opt, &longindex)) != -1) {
switch (arg) {
#include <sys/time.h>
#include "c-ctype.h"
#include <fcntl.h>
-#include <locale.h>
#include <time.h>
#include <limits.h>
#include <sys/stat.h>
#include <libvirt/libvirt-qemu.h>
#include <libvirt/libvirt-lxc.h>
#include "virfile.h"
-#include "configmake.h"
#include "virthread.h"
#include "vircommand.h"
#include "conf/domain_conf.h"