memset(failed_lines, 0, sizeof(failed_lines));
}
+/*
+ * Set or unset environment variable.
+ */
+static void
+set_environment(const char *key, const char *value)
+{
+
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if (!SetEnvironmentVariable(key, value)) {
+ fprintf(stderr, "SetEnvironmentVariable failed with %d\n",
+ (int)GetLastError());
+ }
+#else
+ if (value == NULL) {
+ if (unsetenv(key) == -1)
+ fprintf(stderr, "unsetenv: %s\n", strerror(errno));
+ } else {
+ if (setenv(key, value, 1) == -1)
+ fprintf(stderr, "setenv: %s\n", strerror(errno));
+ }
+#endif
+}
+
+/*
+ * Enforce C locale for (sub)processes.
+ */
+static void
+set_c_locale()
+{
+ static const char *lcs[] = {
+ "LC_ADDRESS",
+ "LC_ALL",
+ "LC_COLLATE",
+ "LC_CTYPE",
+ "LC_IDENTIFICATION",
+ "LC_MEASUREMENT",
+ "LC_MESSAGES",
+ "LC_MONETARY",
+ "LC_NAME",
+ "LC_NUMERIC",
+ "LC_PAPER",
+ "LC_TELEPHONE",
+ "LC_TIME",
+ NULL
+ };
+ size_t i;
+
+ setlocale(LC_ALL, "C");
+ set_environment("LANG", "C");
+ for (i = 0; lcs[i] != NULL; i++)
+ set_environment(lcs[i], NULL);
+}
+
/*
* Actually run a single test, with appropriate setup and cleanup.
*/
exit(1);
}
/* Explicitly reset the locale before each test. */
- setlocale(LC_ALL, "C");
+ set_c_locale();
/* Record the umask before we run the test. */
umask(oldumask = umask(0));
/*
/* Restore umask */
umask(oldumask);
/* Reset locale. */
- setlocale(LC_ALL, "C");
+ set_c_locale();
/* Reset directory. */
if (!assertChdir(tmpdir)) {
fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n",