summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Jansen <jansene@google.com>2023-11-20 13:53:39 -0800
committerErwin Jansen <jansene@google.com>2023-11-21 18:23:15 -0800
commit261366ca9e9e10d8fc65b333160b61c55ad34c14 (patch)
tree7e243d706cb15ba5dce0d538b10b91ffa3638dd1
parentd536cd883af1469b1ebf3a38f7492f70c8d4bd3f (diff)
downloadglib-261366ca9e9e10d8fc65b333160b61c55ad34c14.tar.gz
FIX: Windows build
This contains a series of fixes + changes to make sure we can build glib as a dll using bazel. First, glib is mixing headers + c files, something bazel doesn't really like. So we rename all .c files that are actually treated as headers. Next we introduce a rule to create windows dll's, which we have taken from the google public repo. We also bring in the tests. Change-Id: I37b9946abb2e94e15d0ae45ca836b165a778e7ce
-rw-r--r--BUILD264
-rw-r--r--common_headers.bzl61
-rw-r--r--glib.code-workspace13
-rw-r--r--glib/gconvert.c260
-rw-r--r--glib/gnulib/vasnprintf.c4
-rw-r--r--glib/gstdio-private.c2
-rw-r--r--glib/gstdio-private.h168
-rw-r--r--glib/gstdio.c2
-rw-r--r--glib/gwin32-private.h (renamed from glib/gwin32-private.c)2
-rw-r--r--glib/gwin32.c2
-rw-r--r--glib/tests/fileutils.c2
-rw-r--r--glib/tests/win32.c2
-rw-r--r--glib/win_iconv.h (renamed from glib/win_iconv.c)0
-rw-r--r--gmodule/gmodule-win32.h (renamed from gmodule/gmodule-win32.c)0
-rw-r--r--gmodule/gmodule.c86
-rw-r--r--meson.build2
16 files changed, 627 insertions, 243 deletions
diff --git a/BUILD b/BUILD
index f97bdd7cc..e23b477ac 100644
--- a/BUILD
+++ b/BUILD
@@ -1,3 +1,4 @@
+load(":common_headers.bzl", "common_os_headers", "common_os_includes", "generate_test_rules")
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
objc_library(
@@ -14,15 +15,11 @@ objc_library(
'-DGLIB_CHARSETALIAS_DIR=""',
"-I $(execpath os/darwin)",
"-I $(execpath os/darwin/glib)",
- "-I $(execpath glib)",
- "-I $(execpath .)",
],
data = [
# These paths are here so we can use them in copts with $(execpath ...)
"os/darwin",
"os/darwin/glib",
- "glib",
- ".",
],
includes = [
".",
@@ -35,7 +32,7 @@ py_binary(
)
run_binary(
- name = "gen_visibility_macros",
+ name = "gen_visibility_gmodule",
outs = ["gmodule/gmodule-visibility.h"],
args = [
"2.77.2",
@@ -47,8 +44,43 @@ run_binary(
)
cc_library(
+ name = "gmodule-static",
+ srcs = [
+ "gmodule/gmodule.c",
+ "gmodule/gmodule-deprecated.c",
+ ] + glob([
+ "glib/*.h",
+ "glib/deprecated/*.h",
+ ]) + common_os_headers() + select({
+ "@platforms//os:windows": ["gmodule/gmodule-win32.h"],
+ "//conditions:default": [],
+ }),
+ hdrs = [
+ "glib.h",
+ "gmodule/gmodule.h",
+ "gmodule/gmodule-visibility.h",
+ ] + common_os_headers() + select({
+ "@platforms//os:windows": [],
+ "//conditions:default": ["gmodule/gmodule-dl.c"],
+ }),
+ copts = [
+ "-Wno-#pragma-messages",
+ "-Wno-implicit-function-declaration",
+ ],
+ includes = ["glib"] + common_os_includes(),
+ local_defines = [
+ "_GNU_SOURCE",
+ "G_DISABLE_CAST_CHECKS",
+ "GMODULE_COMPILATION",
+ ],
+ deps = [":glib-static"],
+)
+
+# This is a windows only library that providing common gnu based printing
+cc_library(
name = "gnulib",
srcs = [
+ "glib.h",
"glib/gnulib/asnprintf.c",
"glib/gnulib/isnan.c",
"glib/gnulib/printf.c",
@@ -56,17 +88,21 @@ cc_library(
"glib/gnulib/printf-frexp.c",
"glib/gnulib/printf-frexpl.c",
"glib/gnulib/printf-parse.c",
- # "glib/gnulib/vasnprintf.c",
+ "glib/gnulib/vasnprintf.c",
"glib/gnulib/xsize.c",
- ] + glob([
- "glib/gnulib/*.h",
- "glib/*.h",
- "glib/deprecated/*.h",
- ]),
+ ] + glob(
+ [
+ "glib/gnulib/*.h",
+ "glib/*.h",
+ "glib/deprecated/*.h",
+ ],
+ exclude = [
+ "glib/gnulib/printf-frexp.h",
+ ],
+ ),
hdrs = [
- "glib.h",
- "glib/gnulib/g-gnulib.h",
"glib/gnulib/printf-frexp.c",
+ "glib/gnulib/printf-frexp.h",
"os/windows/config.h",
"os/windows/glib/glibconfig.h",
"os/windows/glib/gnulib/gnulib_math.h",
@@ -76,14 +112,34 @@ cc_library(
"os/windows/glib",
"os/windows/glib/gnulib",
],
+ local_defines = [
+ "_GNU_SOURCE",
+ "G_DISABLE_CAST_CHECKS",
+ "GCC_LINT=1",
+ "GLIB_COMPILATION",
+ "HAVE_ISNAN_IN_LIBC",
+ "HAVE_ISNAND_IN_LIBC",
+ "HAVE_ISNANF_IN_LIBC",
+ "HAVE_ISNANL_IN_LIBC",
+ ],
)
-# Note we merge gmodule inside this.
+# Windows only dirent implementation
cc_library(
- # Named "glib2" so it doesn't shadow the "glib" directory in this package.
- name = "glib-2.0",
+ name = "dirent",
+ srcs = ["glib/dirent/dirent.c"],
+ hdrs = [
+ "glib/dirent/dirent.h",
+ ],
+ defines = [
+ "UNICODE",
+ "_UNICODE",
+ ],
+)
+
+cc_library(
+ name = "glib-static",
srcs = [
- "gmodule/gmodule.c",
"glib/garcbox.c",
"glib/garray.c",
"glib/gasyncqueue.c",
@@ -177,20 +233,12 @@ cc_library(
"glib/glib-unixprivate.h",
"glib/gspawn.c",
"glib/gthread-posix.c",
- "os/darwin/config.h",
- "os/darwin/glib/glibconfig.h",
- "os/darwin/gmodule/gmoduleconf.h",
],
"@platforms//os:windows": [
- "glib/dirent/dirent.h",
- "glib/dirent/wdirent.c",
"glib/giowin32.c",
"glib/gspawn-win32.c",
"glib/gthread-win32.c",
"glib/gwin32.c",
- "os/windows/config.h",
- "os/windows/glib/glibconfig.h",
- "os/windows/gmodule/gmoduleconf.h",
],
"@platforms//os:linux": [
"glib/giounix.c",
@@ -199,9 +247,6 @@ cc_library(
"glib/glib-unixprivate.h",
"glib/gspawn.c",
"glib/gthread-posix.c",
- "os/linux/config.h",
- "os/linux/glib/glibconfig.h",
- "os/linux/gmodule/gmoduleconf.h",
],
"//conditions:default": [],
}) + glob(
@@ -213,22 +258,13 @@ cc_library(
],
exclude = [
"glib/glib-unixprivate.h",
+ "glib/glib-visibility.h",
],
- ),
+ ) + common_os_headers(),
hdrs = [
"glib.h",
- "gmodule/gmodule-dl.c", # TODO: this technically leaks out.
- "gmodule/gmodule-visibility.h",
- ] + select({
- "@platforms//os:windows": [
- "glib/dirent/dirent.c",
- "glib/gstdio-private.c",
- "glib/gwin32-private.c",
- "glib/win_iconv.c",
- "gmodule/gmodule-win32.c",
- ],
- "//conditions:default": [],
- }),
+ "glib/glib-visibility.h",
+ ],
copts = [
"-Winvalid-pch",
"-Wextra",
@@ -288,27 +324,17 @@ cc_library(
"glib",
".",
],
- includes = select({
- "@platforms//os:macos": [
- "os/darwin",
- "os/darwin/glib",
- "os/darwin/gmodule",
- ],
- "@platforms//os:linux": [
- "os/linux",
- "os/linux/glib",
- "os/linux/gmodule",
- ],
- "@platforms//os:windows": [
- "os/windows",
- "os/windows/glib",
- "os/windows/gmodule",
- ],
- "//conditions:default": [],
- }) + [
+ includes = [
".",
"glib",
"gmodule",
+ ] + common_os_includes(),
+ linkopts = [
+ "-DEFAULTLIB:ws2_32.lib",
+ "-DEFAULTLIB:User32.lib",
+ "-DEFAULTLIB:Shell32.lib",
+ "-DEFAULTLIB:Ole32.lib",
+ "-DEFAULTLIB:Advapi32.lib",
],
local_defines = [
"GLIB_COMPILATION",
@@ -318,7 +344,123 @@ cc_library(
],
deps = select({
"@platforms//os:macos": [":glib-darwin"],
- "@platforms//os:windows": [":gnulib"],
+ "@platforms//os:windows": [
+ ":dirent",
+ ":gnulib",
+ ],
"//conditions:default": [],
- }) + ["@pcre2"],
+ }) + [
+ # ":gmodule",
+ "@pcre2",
+ ],
+)
+
+cc_shared_library(
+ name = "glib-2.0",
+ deps = [":glib-static"],
)
+
+cc_shared_library(
+ name = "gmodule-2.0",
+ deps = [":gmodule-static"],
+)
+
+glib_tests = [
+ "array-test",
+ "asyncqueue",
+ "atomic",
+ "base64",
+ "bitlock",
+ "bookmarkfile",
+ "bytes",
+ "cache",
+ "charset",
+ "checksum",
+ "collate",
+ "completion",
+ "cond",
+ "convert",
+ "dataset",
+ "dir",
+ "error",
+ "fileutils",
+ "guuid",
+ "gvariant",
+ "hash",
+ "hmac",
+ "hook",
+ "hostutils",
+ "io-channel-basic",
+ "io-channel",
+ "keyfile",
+ "list",
+ "logging",
+ "macros",
+ "mainloop",
+ "mappedfile",
+ "mapping",
+ "markup",
+ "markup-parse",
+ "markup-collect",
+ "markup-escape",
+ "markup-subparser",
+ "max-version",
+ "memchunk",
+ "mem-overflow",
+ "mutex",
+ "node",
+ "once",
+ "onceinit",
+ "option-context",
+ "option-argv0",
+ "overflow",
+ "overflow-fallback",
+ "pathbuf",
+ "pattern",
+ "private",
+ "protocol",
+ "queue",
+ "rand",
+ "rcbox",
+ "rec-mutex",
+ "refcount",
+ "refcount-macro",
+ "refstring",
+ "regex",
+ "relation",
+ "rwlock",
+ "scannerapi",
+ "search-utils",
+ "sequence",
+ "shell",
+ "slice",
+ "slist",
+ "sort",
+ "strfuncs",
+ "string",
+ "strvbuilder",
+ "testing",
+ "test-printf",
+ "thread",
+ "thread-deprecated",
+ "thread-pool",
+ "thread-pool-slow",
+ "timeout",
+ "timer",
+ "tree",
+ "types",
+ "utf8-performance",
+ "utf8-pointer",
+ "utf8-validate",
+ "utf8-misc",
+ "utils",
+ "utils-isolated",
+ "unicode",
+ "unicode-encoding",
+ "unicode-normalize",
+ "uri",
+ "1bit-mutex",
+ "642026",
+]
+
+generate_test_rules(glib_tests)
diff --git a/common_headers.bzl b/common_headers.bzl
new file mode 100644
index 000000000..9c335c573
--- /dev/null
+++ b/common_headers.bzl
@@ -0,0 +1,61 @@
+"""
+Common headers and includes that are used accross many
+glib like libraries
+"""
+# build_commons.bzl
+
+load("@rules_cc//cc:defs.bzl", "cc_test")
+
+def generate_test_rules(test_names):
+ # Iterate over the test_names array and generate cc_test rules
+ test_rules = []
+ for test_name in test_names:
+ test_rules.append(
+ cc_test(
+ name = "glib_test_" + test_name,
+ srcs = ["glib/tests/" + test_name + ".c"],
+ deps = [":glib-2.0"],
+ ),
+ )
+ return test_rules
+
+def common_os_headers():
+ return select({
+ "@platforms//os:macos": [
+ "os/darwin/config.h",
+ "os/darwin/gmodule/gmoduleconf.h",
+ "os/darwin/glib/glibconfig.h",
+ ],
+ "@platforms//os:linux": [
+ "os/linux/config.h",
+ "os/linux/gmodule/gmoduleconf.h",
+ "os/linux/glib/glibconfig.h",
+ ],
+ "@platforms//os:windows": [
+ "os/windows/config.h",
+ "os/windows/gmodule/gmoduleconf.h",
+ "os/windows/glib/glibconfig.h",
+ "os/windows/glib/gnulib/gnulib_math.h",
+ ],
+ "//conditions:default": [],
+ })
+
+def common_os_includes():
+ return select({
+ "@platforms//os:macos": [
+ "os/darwin",
+ "os/darwin/glib",
+ "os/darwin/gmodule",
+ ],
+ "@platforms//os:linux": [
+ "os/linux",
+ "os/linux/glib",
+ "os/linux/gmodule",
+ ],
+ "@platforms//os:windows": [
+ "os/windows",
+ "os/windows/glib",
+ "os/windows/gmodule",
+ ],
+ "//conditions:default": [],
+ })
diff --git a/glib.code-workspace b/glib.code-workspace
new file mode 100644
index 000000000..402d5b12c
--- /dev/null
+++ b/glib.code-workspace
@@ -0,0 +1,13 @@
+{
+ "folders": [
+ {
+ "path": "."
+ },
+ {
+ "path": "../dtc"
+ }
+ ],
+ "settings": {
+ "workbench.colorTheme": "Solarized Light"
+ }
+} \ No newline at end of file
diff --git a/glib/gconvert.c b/glib/gconvert.c
index 66886adc3..0bf5c69b4 100644
--- a/glib/gconvert.c
+++ b/glib/gconvert.c
@@ -36,7 +36,7 @@
#include <stdlib.h>
#ifdef G_OS_WIN32
-#include "win_iconv.c"
+#include "win_iconv.h"
#endif
#ifdef G_PLATFORM_WIN32
@@ -130,7 +130,7 @@
* This section is a practical summary of the detailed
* things to do to make sure your applications process file
* name encodings correctly.
- *
+ *
* 1. If you get a file name from the file system from a function
* such as readdir() or gtk_file_chooser_get_filename(), you do
* not need to do any conversion to pass that file name to
@@ -208,14 +208,14 @@ try_to_aliases (const char **to_aliases,
* g_iconv_open: (skip)
* @to_codeset: destination codeset
* @from_codeset: source codeset
- *
+ *
* Same as the standard UNIX routine iconv_open(), but
* may be implemented via libiconv on UNIX flavors that lack
* a native implementation.
- *
+ *
* GLib provides g_convert() and g_locale_to_utf8() which are likely
* more convenient than the raw iconv wrappers.
- *
+ *
* Returns: a "conversion descriptor", or (GIConv)-1 if
* opening the converter failed.
**/
@@ -225,7 +225,7 @@ g_iconv_open (const gchar *to_codeset,
{
#ifndef ANDROID_STUB
iconv_t cd;
-
+
if (!try_conversion (to_codeset, from_codeset, &cd))
{
const char **to_aliases = _g_charset_get_aliases (to_codeset);
@@ -264,14 +264,14 @@ g_iconv_open (const gchar *to_codeset,
* @inbytes_left: (inout): inout parameter, bytes remaining to convert in @inbuf
* @outbuf: converted output bytes
* @outbytes_left: (inout): inout parameter, bytes available to fill in @outbuf
- *
+ *
* Same as the standard UNIX routine iconv(), but
* may be implemented via libiconv on UNIX flavors that lack
* a native implementation.
*
* GLib provides g_convert() and g_locale_to_utf8() which are likely
* more convenient than the raw iconv wrappers.
- *
+ *
* Note that the behaviour of iconv() for characters which are valid in the
* input character set, but which have no representation in the output character
* set, is implementation defined. This function may return success (with a
@@ -281,7 +281,7 @@ g_iconv_open (const gchar *to_codeset,
*
* Returns: count of non-reversible conversions, or -1 on error
**/
-gsize
+gsize
g_iconv (GIConv converter,
gchar **inbuf,
gsize *inbytes_left,
@@ -309,7 +309,7 @@ g_iconv (GIConv converter,
*
* GLib provides g_convert() and g_locale_to_utf8() which are likely
* more convenient than the raw iconv wrappers.
- *
+ *
* Returns: -1 on error, 0 on success
**/
gint
@@ -348,7 +348,7 @@ open_converter (const gchar *to_codeset,
from_codeset, to_codeset);
}
}
-
+
return cd;
}
@@ -357,8 +357,8 @@ close_converter (GIConv cd)
{
if (cd == (GIConv) -1)
return 0;
-
- return g_iconv_close (cd);
+
+ return g_iconv_close (cd);
}
/**
@@ -372,7 +372,7 @@ close_converter (GIConv cd)
* @converter: conversion descriptor from g_iconv_open()
* @bytes_read: (out) (optional): location to store the number of bytes in
* the input string that were successfully converted, or %NULL.
- * Even if the conversion was successful, this may be
+ * Even if the conversion was successful, this may be
* less than @len if there were partial characters
* at the end of the input. If the error
* %G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
@@ -383,9 +383,9 @@ close_converter (GIConv cd)
* @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
- * Converts a string from one character set to another.
- *
- * Note that you should use g_iconv() for streaming conversions.
+ * Converts a string from one character set to another.
+ *
+ * Note that you should use g_iconv() for streaming conversions.
* Despite the fact that @bytes_read can return information about partial
* characters, the g_convert_... functions are not generally suitable
* for streaming. If the underlying converter maintains internal state,
@@ -412,8 +412,8 @@ gchar*
g_convert_with_iconv (const gchar *str,
gssize len,
GIConv converter,
- gsize *bytes_read,
- gsize *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
gchar *dest;
@@ -426,16 +426,16 @@ g_convert_with_iconv (const gchar *str,
gboolean have_error = FALSE;
gboolean done = FALSE;
gboolean reset = FALSE;
-
+
g_return_val_if_fail (converter != (GIConv) -1, NULL);
-
+
if (len < 0)
len = strlen (str);
p = str;
inbytes_remaining = len;
outbuf_size = len + NUL_TERMINATOR_LENGTH;
-
+
outbytes_remaining = outbuf_size - NUL_TERMINATOR_LENGTH;
outp = dest = g_malloc (outbuf_size);
@@ -457,10 +457,10 @@ g_convert_with_iconv (const gchar *str,
case E2BIG:
{
gsize used = outp - dest;
-
+
outbuf_size *= 2;
dest = g_realloc (dest, outbuf_size);
-
+
outp = dest + used;
outbytes_remaining = outbuf_size - used - NUL_TERMINATOR_LENGTH;
}
@@ -489,7 +489,7 @@ g_convert_with_iconv (const gchar *str,
_("Unrepresentable character in conversion input"));
have_error = TRUE;
}
- else
+ else
{
if (!reset)
{
@@ -503,12 +503,12 @@ g_convert_with_iconv (const gchar *str,
}
memset (outp, 0, NUL_TERMINATOR_LENGTH);
-
+
if (bytes_read)
*bytes_read = p - str;
else
{
- if ((p - str) != len)
+ if ((p - str) != len)
{
if (!have_error)
{
@@ -543,7 +543,7 @@ g_convert_with_iconv (const gchar *str,
* @from_codeset: character set of @str.
* @bytes_read: (out) (optional): location to store the number of bytes in
* the input string that were successfully converted, or %NULL.
- * Even if the conversion was successful, this may be
+ * Even if the conversion was successful, this may be
* less than @len if there were partial characters
* at the end of the input. If the error
* %G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
@@ -556,7 +556,7 @@ g_convert_with_iconv (const gchar *str,
*
* Converts a string from one character set to another.
*
- * Note that you should use g_iconv() for streaming conversions.
+ * Note that you should use g_iconv() for streaming conversions.
* Despite the fact that @bytes_read can return information about partial
* characters, the g_convert_... functions are not generally suitable
* for streaming. If the underlying converter maintains internal state,
@@ -576,11 +576,11 @@ g_convert_with_iconv (const gchar *str,
**/
gchar*
g_convert (const gchar *str,
- gssize len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
- gsize *bytes_read,
- gsize *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
gchar *res;
@@ -589,17 +589,17 @@ g_convert (const gchar *str,
g_return_val_if_fail (str != NULL, NULL);
g_return_val_if_fail (to_codeset != NULL, NULL);
g_return_val_if_fail (from_codeset != NULL, NULL);
-
+
cd = open_converter (to_codeset, from_codeset, error);
if (cd == (GIConv) -1)
{
if (bytes_read)
*bytes_read = 0;
-
+
if (bytes_written)
*bytes_written = 0;
-
+
return NULL;
}
@@ -624,12 +624,12 @@ g_convert (const gchar *str,
* @from_codeset: character set of @str.
* @fallback: UTF-8 string to use in place of characters not
* present in the target encoding. (The string must be
- * representable in the target encoding).
- * If %NULL, characters not in the target encoding will
+ * representable in the target encoding).
+ * If %NULL, characters not in the target encoding will
* be represented as Unicode escapes \uxxxx or \Uxxxxyyyy.
* @bytes_read: (out) (optional): location to store the number of bytes in
* the input string that were successfully converted, or %NULL.
- * Even if the conversion was successful, this may be
+ * Even if the conversion was successful, this may be
* less than @len if there were partial characters
* at the end of the input.
* @bytes_written: (out) (optional): the number of bytes stored in
@@ -642,10 +642,10 @@ g_convert (const gchar *str,
* in the output. Note that it is not guaranteed that the specification
* for the fallback sequences in @fallback will be honored. Some
* systems may do an approximate conversion from @from_codeset
- * to @to_codeset in their iconv() functions,
+ * to @to_codeset in their iconv() functions,
* in which case GLib will simply return that approximate conversion.
*
- * Note that you should use g_iconv() for streaming conversions.
+ * Note that you should use g_iconv() for streaming conversions.
* Despite the fact that @bytes_read can return information about partial
* characters, the g_convert_... functions are not generally suitable
* for streaming. If the underlying converter maintains internal state,
@@ -662,7 +662,7 @@ g_convert (const gchar *str,
**/
gchar*
g_convert_with_fallback (const gchar *str,
- gssize len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
const gchar *fallback,
@@ -675,10 +675,10 @@ g_convert_with_fallback (const gchar *str,
gchar *outp;
const gchar *insert_str = NULL;
const gchar *p;
- gsize inbytes_remaining;
+ gsize inbytes_remaining;
const gchar *save_p = NULL;
gsize save_inbytes = 0;
- gsize outbytes_remaining;
+ gsize outbytes_remaining;
gsize err;
GIConv cd;
gsize outbuf_size;
@@ -686,18 +686,18 @@ g_convert_with_fallback (const gchar *str,
gboolean done = FALSE;
GError *local_error = NULL;
-
+
g_return_val_if_fail (str != NULL, NULL);
g_return_val_if_fail (to_codeset != NULL, NULL);
g_return_val_if_fail (from_codeset != NULL, NULL);
-
+
if (len < 0)
len = strlen (str);
-
+
/* Try an exact conversion; we only proceed if this fails
* due to an illegal sequence in the input string.
*/
- dest = g_convert (str, len, to_codeset, from_codeset,
+ dest = g_convert (str, len, to_codeset, from_codeset,
bytes_read, bytes_written, &local_error);
if (!local_error)
return dest;
@@ -713,7 +713,7 @@ g_convert_with_fallback (const gchar *str,
g_error_free (local_error);
local_error = NULL;
-
+
/* No go; to proceed, we need a converter from "UTF-8" to
* to_codeset, and the string as UTF-8.
*/
@@ -722,14 +722,14 @@ g_convert_with_fallback (const gchar *str,
{
if (bytes_read)
*bytes_read = 0;
-
+
if (bytes_written)
*bytes_written = 0;
-
+
return NULL;
}
- utf8 = g_convert (str, len, "UTF-8", from_codeset,
+ utf8 = g_convert (str, len, "UTF-8", from_codeset,
bytes_read, &inbytes_remaining, error);
if (!utf8)
{
@@ -772,10 +772,10 @@ g_convert_with_fallback (const gchar *str,
outbuf_size *= 2;
dest = g_realloc (dest, outbuf_size);
-
+
outp = dest + used;
outbytes_remaining = outbuf_size - used - NUL_TERMINATOR_LENGTH;
-
+
break;
}
case EILSEQ:
@@ -792,14 +792,14 @@ g_convert_with_fallback (const gchar *str,
else if (p)
{
if (!fallback)
- {
+ {
gunichar ch = g_utf8_get_char (p);
insert_str = g_strdup_printf (ch < 0x10000 ? "\\u%04x" : "\\U%08x",
ch);
}
else
insert_str = fallback;
-
+
save_p = g_utf8_next_char (p);
save_inbytes = inbytes_remaining - (save_p - p);
p = insert_str;
@@ -845,7 +845,7 @@ g_convert_with_fallback (const gchar *str,
/* Cleanup
*/
memset (outp, 0, NUL_TERMINATOR_LENGTH);
-
+
close_converter (cd);
if (bytes_written)
@@ -867,7 +867,7 @@ g_convert_with_fallback (const gchar *str,
/*
* g_locale_to_utf8
*
- *
+ *
*/
/*
@@ -997,7 +997,7 @@ convert_checked (const gchar *string,
* for the @len parameter is unsafe)
* @bytes_read: (out) (optional): location to store the number of bytes in the
* input string that were successfully converted, or %NULL.
- * Even if the conversion was successful, this may be
+ * Even if the conversion was successful, this may be
* less than @len if there were partial characters
* at the end of the input. If the error
* %G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
@@ -1007,7 +1007,7 @@ convert_checked (const gchar *string,
* buffer (not including the terminating nul).
* @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
- *
+ *
* Converts a string which is in the encoding used for strings by
* the C runtime (usually the same as that used by the operating
* system) in the [current locale][setlocale] into a UTF-8 string.
@@ -1019,13 +1019,13 @@ convert_checked (const gchar *string,
* the %G_CONVERT_ERROR_ILLEGAL_SEQUENCE error for backward compatibility with
* earlier versions of this library. Use g_convert() to produce output that
* may contain embedded nul characters.
- *
+ *
* Returns: (type utf8): The converted string, or %NULL on an error.
**/
gchar *
g_locale_to_utf8 (const gchar *opsysstring,
- gssize len,
- gsize *bytes_read,
+ gssize len,
+ gsize *bytes_read,
gsize *bytes_written,
GError **error)
{
@@ -1087,12 +1087,12 @@ _g_ctype_locale_to_utf8 (const gchar *opsysstring,
/**
* g_locale_from_utf8:
- * @utf8string: a UTF-8 encoded string
+ * @utf8string: a UTF-8 encoded string
* @len: the length of the string, or -1 if the string is
* nul-terminated.
* @bytes_read: (out) (optional): location to store the number of bytes in the
* input string that were successfully converted, or %NULL.
- * Even if the conversion was successful, this may be
+ * Even if the conversion was successful, this may be
* less than @len if there were partial characters
* at the end of the input. If the error
* %G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
@@ -1102,7 +1102,7 @@ _g_ctype_locale_to_utf8 (const gchar *opsysstring,
* buffer (not including the terminating nul).
* @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
- *
+ *
* Converts a string from UTF-8 to the encoding used for strings by
* the C runtime (usually the same as that used by the operating
* system) in the [current locale][setlocale]. On Windows this means
@@ -1119,8 +1119,8 @@ _g_ctype_locale_to_utf8 (const gchar *opsysstring,
**/
gchar *
g_locale_from_utf8 (const gchar *utf8string,
- gssize len,
- gsize *bytes_read,
+ gssize len,
+ gsize *bytes_read,
gsize *bytes_written,
GError **error)
{
@@ -1180,11 +1180,11 @@ filename_charset_cache_free (gpointer data)
* The returned @charsets belong to GLib and must not be freed.
*
* Note that on Unix, regardless of the locale character set or
- * `G_FILENAME_ENCODING` value, the actual file names present
+ * `G_FILENAME_ENCODING` value, the actual file names present
* on a system might be in any random encoding or just gibberish.
*
* Returns: %TRUE if the filename encoding is UTF-8.
- *
+ *
* Since: 2.6
*/
gboolean
@@ -1208,9 +1208,9 @@ g_get_filename_charsets (const gchar ***filename_charsets)
g_free (cache->charset);
g_strfreev (cache->filename_charsets);
cache->charset = g_strdup (charset);
-
+
p = g_getenv ("G_FILENAME_ENCODING");
- if (p != NULL && p[0] != '\0')
+ if (p != NULL && p[0] != '\0')
{
cache->filename_charsets = g_strsplit (p, ",", 0);
cache->is_utf8 = (strcmp (cache->filename_charsets[0], "UTF-8") == 0);
@@ -1231,7 +1231,7 @@ g_get_filename_charsets (const gchar ***filename_charsets)
cache->is_utf8 = g_get_charset (&new_charset);
cache->filename_charsets[0] = g_strdup (new_charset);
}
- else
+ else
{
cache->filename_charsets = g_new0 (gchar *, 3);
cache->is_utf8 = TRUE;
@@ -1250,7 +1250,7 @@ g_get_filename_charsets (const gchar ***filename_charsets)
#else /* G_PLATFORM_WIN32 */
gboolean
-g_get_filename_charsets (const gchar ***filename_charsets)
+g_get_filename_charsets (const gchar ***filename_charsets)
{
static const gchar *charsets[] = {
"UTF-8",
@@ -1283,12 +1283,12 @@ get_filename_charset (const gchar **filename_charset)
{
const gchar **charsets;
gboolean is_utf8;
-
+
is_utf8 = g_get_filename_charsets (&charsets);
if (filename_charset)
*filename_charset = charsets[0];
-
+
return is_utf8;
}
@@ -1301,7 +1301,7 @@ get_filename_charset (const gchar **filename_charset)
* for the @len parameter is unsafe)
* @bytes_read: (out) (optional): location to store the number of bytes in the
* input string that were successfully converted, or %NULL.
- * Even if the conversion was successful, this may be
+ * Even if the conversion was successful, this may be
* less than @len if there were partial characters
* at the end of the input. If the error
* %G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
@@ -1311,10 +1311,10 @@ get_filename_charset (const gchar **filename_charset)
* buffer (not including the terminating nul).
* @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
- *
+ *
* Converts a string which is in the encoding used by GLib for
* filenames into a UTF-8 string. Note that on Windows GLib uses UTF-8
- * for filenames; on other platforms, this function indirectly depends on
+ * for filenames; on other platforms, this function indirectly depends on
* the [current locale][setlocale].
*
* The input string shall not contain nul characters even if the @len
@@ -1324,13 +1324,13 @@ get_filename_charset (const gchar **filename_charset)
* nul character, the error %G_CONVERT_ERROR_EMBEDDED_NUL is set and the
* function returns %NULL. Use g_convert() to produce output that
* may contain embedded nul characters.
- *
+ *
* Returns: (type utf8): The converted string, or %NULL on an error.
**/
gchar*
-g_filename_to_utf8 (const gchar *opsysstring,
- gssize len,
- gsize *bytes_read,
+g_filename_to_utf8 (const gchar *opsysstring,
+ gssize len,
+ gsize *bytes_read,
gsize *bytes_written,
GError **error)
{
@@ -1354,7 +1354,7 @@ g_filename_to_utf8 (const gchar *opsysstring,
* nul-terminated.
* @bytes_read: (out) (optional): location to store the number of bytes in
* the input string that were successfully converted, or %NULL.
- * Even if the conversion was successful, this may be
+ * Even if the conversion was successful, this may be
* less than @len if there were partial characters
* at the end of the input. If the error
* %G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
@@ -1364,10 +1364,10 @@ g_filename_to_utf8 (const gchar *opsysstring,
* the output buffer (not including the terminating nul).
* @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
- *
+ *
* Converts a string from UTF-8 to the encoding GLib uses for
* filenames. Note that on Windows GLib uses UTF-8 for filenames;
- * on other platforms, this function indirectly depends on the
+ * on other platforms, this function indirectly depends on the
* [current locale][setlocale].
*
* The input string shall not contain nul characters even if the @len
@@ -1381,8 +1381,8 @@ g_filename_to_utf8 (const gchar *opsysstring,
**/
gchar*
g_filename_from_utf8 (const gchar *utf8string,
- gssize len,
- gsize *bytes_read,
+ gssize len,
+ gsize *bytes_read,
gsize *bytes_written,
GError **error)
{
@@ -1404,7 +1404,7 @@ static gboolean
has_case_prefix (const gchar *haystack, const gchar *needle)
{
const gchar *h, *n;
-
+
/* Eat one character at a time. */
h = haystack;
n = needle;
@@ -1415,7 +1415,7 @@ has_case_prefix (const gchar *haystack, const gchar *needle)
n++;
h++;
}
-
+
return *n == '\0';
}
@@ -1429,7 +1429,7 @@ typedef enum {
static const guchar acceptable[96] = {
/* A table of the ASCII chars from space (32) to DEL (127) */
- /* ! " # $ % & ' ( ) * + , - . / */
+ /* ! " # $ % & ' ( ) * + , - . / */
0x00,0x3F,0x20,0x20,0x28,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x2A,0x28,0x3F,0x3F,0x1C,
/* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x20,
@@ -1448,7 +1448,7 @@ static const gchar hex[] = "0123456789ABCDEF";
/* Note: This escape function works on file: URIs, but if you want to
* escape something else, please read RFC-2396 */
static gchar *
-g_escape_uri_string (const gchar *string,
+g_escape_uri_string (const gchar *string,
UnsafeCharacterSet mask)
{
#define ACCEPTABLE(a) ((a)>=32 && (a)<128 && (acceptable[(a)-32] & use_mask))
@@ -1459,29 +1459,29 @@ g_escape_uri_string (const gchar *string,
int c;
gint unacceptable;
UnsafeCharacterSet use_mask;
-
+
g_return_val_if_fail (mask == UNSAFE_ALL
|| mask == UNSAFE_ALLOW_PLUS
|| mask == UNSAFE_PATH
|| mask == UNSAFE_HOST
|| mask == UNSAFE_SLASHES, NULL);
-
+
unacceptable = 0;
use_mask = mask;
for (p = string; *p != '\0'; p++)
{
c = (guchar) *p;
- if (!ACCEPTABLE (c))
+ if (!ACCEPTABLE (c))
unacceptable++;
}
-
+
result = g_malloc (p - string + unacceptable * 2 + 1);
-
+
use_mask = mask;
for (q = result, p = string; *p != '\0'; p++)
{
c = (guchar) *p;
-
+
if (!ACCEPTABLE (c))
{
*q++ = '%'; /* means hex coming */
@@ -1491,9 +1491,9 @@ g_escape_uri_string (const gchar *string,
else
*q++ = *p;
}
-
+
*q = '\0';
-
+
return result;
}
@@ -1512,10 +1512,10 @@ g_escape_file_uri (const gchar *hostname,
/* Turn backslashes into forward slashes. That's what Netscape
* does, and they are actually more or less equivalent in Windows.
*/
-
+
pathname = g_strdup (pathname);
p = (char *) pathname;
-
+
while ((backslash = strchr (p, '\\')) != NULL)
{
*backslash = '/';
@@ -1542,7 +1542,7 @@ g_escape_file_uri (const gchar *hostname,
g_free (escaped_hostname);
g_free (escaped_path);
-
+
return res;
}
@@ -1553,13 +1553,13 @@ unescape_character (const char *scanner)
int second_digit;
first_digit = g_ascii_xdigit_value (scanner[0]);
- if (first_digit < 0)
+ if (first_digit < 0)
return -1;
-
+
second_digit = g_ascii_xdigit_value (scanner[1]);
- if (second_digit < 0)
+ if (second_digit < 0)
return -1;
-
+
return (first_digit << 4) | second_digit;
}
@@ -1572,7 +1572,7 @@ g_unescape_uri_string (const char *escaped,
const gchar *in, *in_end;
gchar *out, *result;
int c;
-
+
if (escaped == NULL)
return NULL;
@@ -1580,7 +1580,7 @@ g_unescape_uri_string (const char *escaped,
len = strlen (escaped);
result = g_malloc (len + 1);
-
+
out = result;
for (in = escaped, in_end = escaped + len; in < in_end; in++)
{
@@ -1611,7 +1611,7 @@ g_unescape_uri_string (const char *escaped,
*out++ = c;
}
-
+
g_assert (out - result <= len);
*out = '\0';
@@ -1663,7 +1663,7 @@ hostname_validate (const char *hostname)
while (is_asciialphanum (c) || c == '-');
if (last_char == '-')
return FALSE;
-
+
/* if that was the last label, check that it was a toplabel */
if (c == '\0' || (c == '.' && *p == '\0'))
return is_asciialpha (first_char);
@@ -1680,7 +1680,7 @@ hostname_validate (const char *hostname)
* stored in this location.
* @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
- *
+ *
* Converts an escaped ASCII-encoded URI to a local filename in the
* encoding used for filenames.
*
@@ -1688,7 +1688,7 @@ hostname_validate (const char *hostname)
* but are not part of the resulting filename.
* We take inspiration from https://url.spec.whatwg.org/#file-state,
* but we don't support the entire standard.
- *
+ *
* Returns: (type filename): a newly-allocated string holding
* the resulting filename, or %NULL on an error.
**/
@@ -1723,7 +1723,7 @@ g_filename_from_uri (const gchar *uri,
temp_uri = g_strdup (uri);
past_scheme = temp_uri + strlen ("file:");
-
+
past_path = strchr (past_scheme, '?');
if (past_path != NULL)
*past_path = '\0';
@@ -1762,7 +1762,7 @@ g_filename_from_uri (const gchar *uri,
uri);
return NULL;
}
-
+
if (hostname)
*hostname = unescaped_hostname;
else
@@ -1830,10 +1830,10 @@ g_filename_from_uri (const gchar *uri,
* @hostname: (nullable): A UTF-8 encoded hostname, or %NULL for none.
* @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
- *
+ *
* Converts an absolute filename to an escaped ASCII-encoded URI, with the path
* component following Section 3.3. of RFC 2396.
- *
+ *
* Returns: a newly-allocated string holding the resulting
* URI, or %NULL on an error.
**/
@@ -1862,7 +1862,7 @@ g_filename_to_uri (const gchar *filename,
_("Invalid hostname"));
return NULL;
}
-
+
#ifdef G_OS_WIN32
/* Don't use localhost unnecessarily */
if (hostname && g_ascii_strcasecmp (hostname, "localhost") == 0)
@@ -1876,7 +1876,7 @@ g_filename_to_uri (const gchar *filename,
/**
* g_uri_list_extract_uris:
- * @uri_list: an URI list
+ * @uri_list: an URI list
*
* Splits an URI list conforming to the text/uri-list
* mime type defined in RFC 2483 into individual URIs,
@@ -1946,7 +1946,7 @@ g_uri_list_extract_uris (const gchar *uri_list)
* for instance there might be problems converting it to UTF-8, and some files
* can be translated in the display.
*
- * If GLib cannot make sense of the encoding of @filename, as a last resort it
+ * If GLib cannot make sense of the encoding of @filename, as a last resort it
* replaces unknown characters with U+FFFD, the Unicode replacement character.
* You can search the result for the UTF-8 encoding of this character (which is
* "\357\277\275" in octal notation) to find out if @filename was in an invalid
@@ -1970,7 +1970,7 @@ g_filename_display_basename (const gchar *filename)
char *display_name;
g_return_val_if_fail (filename != NULL, NULL);
-
+
basename = g_path_get_basename (filename);
display_name = g_filename_display_name (basename);
g_free (basename);
@@ -1981,14 +1981,14 @@ g_filename_display_basename (const gchar *filename)
* g_filename_display_name:
* @filename: (type filename): a pathname hopefully in the
* GLib file name encoding
- *
- * Converts a filename into a valid UTF-8 string. The conversion is
- * not necessarily reversible, so you should keep the original around
+ *
+ * Converts a filename into a valid UTF-8 string. The conversion is
+ * not necessarily reversible, so you should keep the original around
* and use the return value of this function only for display purposes.
- * Unlike g_filename_to_utf8(), the result is guaranteed to be non-%NULL
+ * Unlike g_filename_to_utf8(), the result is guaranteed to be non-%NULL
* even if the filename actually isn't in the GLib file name encoding.
*
- * If GLib cannot make sense of the encoding of @filename, as a last resort it
+ * If GLib cannot make sense of the encoding of @filename, as a last resort it
* replaces unknown characters with U+FFFD, the Unicode replacement character.
* You can search the result for the UTF-8 encoding of this character (which is
* "\357\277\275" in octal notation) to find out if @filename was in an invalid
@@ -2010,7 +2010,7 @@ g_filename_display_name (const gchar *filename)
const gchar **charsets;
gchar *display_name = NULL;
gboolean is_utf8;
-
+
is_utf8 = g_get_filename_charsets (&charsets);
if (is_utf8)
@@ -2018,7 +2018,7 @@ g_filename_display_name (const gchar *filename)
if (g_utf8_validate (filename, -1, NULL))
display_name = g_strdup (filename);
}
-
+
if (!display_name)
{
/* Try to convert from the filename charsets to UTF-8.
@@ -2026,18 +2026,18 @@ g_filename_display_name (const gchar *filename)
*/
for (i = is_utf8 ? 1 : 0; charsets[i]; i++)
{
- display_name = g_convert (filename, -1, "UTF-8", charsets[i],
+ display_name = g_convert (filename, -1, "UTF-8", charsets[i],
NULL, NULL, NULL);
if (display_name)
break;
}
}
-
+
/* if all conversions failed, we replace invalid UTF-8
* by a question mark
*/
- if (!display_name)
+ if (!display_name)
display_name = g_utf8_make_valid (filename, -1);
return display_name;
diff --git a/glib/gnulib/vasnprintf.c b/glib/gnulib/vasnprintf.c
index a5b68db8c..fdc636ae8 100644
--- a/glib/gnulib/vasnprintf.c
+++ b/glib/gnulib/vasnprintf.c
@@ -142,7 +142,7 @@
# define DCHAR_CPY wmemcpy
# define DCHAR_SET wmemset
# else
-# define VASNPRINTF vasnprintf
+# define VASNPRINTF _g_gnulib_vasnprintf
# define FCHAR_T char
# define DCHAR_T char
# define TCHAR_T char
@@ -1785,7 +1785,7 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
#endif
DCHAR_T *
-VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
+_g_gnulib_vasnprintf (DCHAR_T *resultbuf, size_t *lengthp,
const FCHAR_T *format, va_list args)
{
DIRECTIVES d;
diff --git a/glib/gstdio-private.c b/glib/gstdio-private.c
index d00cfa3bd..b44f1aa89 100644
--- a/glib/gstdio-private.c
+++ b/glib/gstdio-private.c
@@ -1,4 +1,4 @@
-/* gstdio-private.c - private glib functions for gstdio.c
+/* gstdio-private.h - private glib functions for gstdio.c
*
* Copyright 2004 Tor Lillqvist
* Copyright 2018 Руслан Ижбулатов
diff --git a/glib/gstdio-private.h b/glib/gstdio-private.h
new file mode 100644
index 000000000..b44f1aa89
--- /dev/null
+++ b/glib/gstdio-private.h
@@ -0,0 +1,168 @@
+/* gstdio-private.h - private glib functions for gstdio.c
+ *
+ * Copyright 2004 Tor Lillqvist
+ * Copyright 2018 Руслан Ижбулатов
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * 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/>.
+ */
+
+/* Strips "\\\\?\\" extended prefix or
+ * "\\??\\" NT Object Manager prefix from
+ * @str in-place, using memmove.
+ * @str_size must point to the size of @str
+ * in gunichar2s, including NUL-terminator
+ * (if @str is NUL-terminated; it doesn't have to be).
+ * On return @str_size will correctly reflect changes
+ * in @str size (if any).
+ * Returns TRUE if @str was modified.
+ */
+static gboolean
+_g_win32_strip_extended_ntobjm_prefix (gunichar2 *str,
+ gsize *str_size)
+{
+ const wchar_t *extended_prefix = L"\\\\?\\";
+ const gsize extended_prefix_len = wcslen (extended_prefix);
+ const gsize extended_prefix_len_bytes = sizeof (gunichar2) * extended_prefix_len;
+ const gsize extended_prefix_with_drive_len_bytes = sizeof (gunichar2) * (extended_prefix_len + 2);
+ const wchar_t *ntobjm_prefix = L"\\??\\";
+ const gsize ntobjm_prefix_len = wcslen (ntobjm_prefix);
+ const gsize ntobjm_prefix_len_bytes = sizeof (gunichar2) * ntobjm_prefix_len;
+ const gsize ntobjm_prefix_with_drive_len_bytes = sizeof (gunichar2) * (ntobjm_prefix_len + 2);
+ gboolean do_move = FALSE;
+ gsize move_shift = 0;
+
+ if ((*str_size) * sizeof (gunichar2) > extended_prefix_with_drive_len_bytes &&
+ memcmp (str,
+ extended_prefix,
+ extended_prefix_len_bytes) == 0 &&
+ iswascii (str[extended_prefix_len]) &&
+ iswalpha (str[extended_prefix_len]) &&
+ str[extended_prefix_len + 1] == L':')
+ {
+ do_move = TRUE;
+ move_shift = extended_prefix_len;
+ }
+ else if ((*str_size) * sizeof (gunichar2) > ntobjm_prefix_with_drive_len_bytes &&
+ memcmp (str,
+ ntobjm_prefix,
+ ntobjm_prefix_len_bytes) == 0 &&
+ iswascii (str[ntobjm_prefix_len]) &&
+ iswalpha (str[ntobjm_prefix_len]) &&
+ str[ntobjm_prefix_len + 1] == L':')
+ {
+ do_move = TRUE;
+ move_shift = ntobjm_prefix_len;
+ }
+
+ if (do_move)
+ {
+ *str_size -= move_shift;
+ memmove (str,
+ str + move_shift,
+ (*str_size) * sizeof (gunichar2));
+ }
+
+ return do_move;
+}
+
+static int
+_g_win32_copy_and_maybe_terminate (const guchar *data,
+ gsize in_to_copy,
+ gunichar2 *buf,
+ gsize buf_size,
+ gunichar2 **alloc_buf,
+ gboolean terminate)
+{
+ gsize to_copy = in_to_copy;
+ /* Number of bytes we can use to add extra zeroes for NUL-termination.
+ * 0 means that we can destroy up to 2 bytes of data,
+ * 1 means that we can destroy up to 1 byte of data,
+ * 2 means that we do not perform destructive NUL-termination
+ */
+ gsize extra_bytes = terminate ? 2 : 0;
+ char *buf_in_chars;
+
+ if (to_copy == 0)
+ return 0;
+
+ /* 2 bytes is sizeof (wchar_t), for an extra NUL-terminator. */
+ if (buf)
+ {
+ if (to_copy >= buf_size)
+ {
+ extra_bytes = 0;
+ to_copy = buf_size;
+ }
+ else if (to_copy > buf_size - 2)
+ {
+ extra_bytes = 1;
+ }
+
+ memcpy (buf, data, to_copy);
+ }
+ else
+ {
+ /* Note that SubstituteNameLength is USHORT, so to_copy + 2, being
+ * gsize, never overflows.
+ */
+ *alloc_buf = g_malloc (to_copy + extra_bytes);
+ memcpy (*alloc_buf, data, to_copy);
+ }
+
+ if (!terminate)
+ return to_copy;
+
+ if (buf)
+ buf_in_chars = (char *) buf;
+ else
+ buf_in_chars = (char *) *alloc_buf;
+
+ if (to_copy >= 2 && buf_in_chars[to_copy - 2] == 0 &&
+ buf_in_chars[to_copy - 1] == 0)
+ {
+ /* Fully NUL-terminated, do nothing */
+ }
+ else if ((to_copy == 1 || buf_in_chars[to_copy - 2] != 0) &&
+ buf_in_chars[to_copy - 1] == 0)
+ {
+ /* Have one zero, try to add another one */
+ if (extra_bytes > 0)
+ {
+ /* Append trailing zero */
+ buf_in_chars[to_copy] = 0;
+ /* Be precise about the number of bytes we return */
+ to_copy += 1;
+ }
+ else if (to_copy >= 2)
+ {
+ /* No space for appending, destroy one byte */
+ buf_in_chars[to_copy - 2] = 0;
+ }
+ /* else there's no space at all (to_copy == 1), do nothing */
+ }
+ else if (extra_bytes > 0 || to_copy >= 2)
+ {
+ buf_in_chars[to_copy - 2 + extra_bytes] = 0;
+ buf_in_chars[to_copy - 1 + extra_bytes] = 0;
+ to_copy += extra_bytes;
+ }
+ else /* extra_bytes == 0 && to_copy == 1 */
+ {
+ buf_in_chars[0] = 0;
+ }
+
+ return to_copy;
+}
diff --git a/glib/gstdio.c b/glib/gstdio.c
index 3a2d07985..cf48967d8 100644
--- a/glib/gstdio.c
+++ b/glib/gstdio.c
@@ -140,7 +140,7 @@ w32_error_to_errno (DWORD error_code)
}
}
-#include "gstdio-private.c"
+#include "gstdio-private.h"
/* Windows implementation of fopen() does not accept modes such as
* "wb+". The 'b' needs to be appended to "w+", i.e. "w+b". Note
diff --git a/glib/gwin32-private.c b/glib/gwin32-private.h
index c863e2806..db19d645d 100644
--- a/glib/gwin32-private.c
+++ b/glib/gwin32-private.h
@@ -1,4 +1,4 @@
-/* gwin32-private.c - private glib functions for gwin32.c
+/* gwin32-private.h - private glib functions for gwin32.c
*
* Copyright 2019 Руслан Ижбулатов
*
diff --git a/glib/gwin32.c b/glib/gwin32.c
index 6dbf81af0..97f24c431 100644
--- a/glib/gwin32.c
+++ b/glib/gwin32.c
@@ -1068,7 +1068,7 @@ static DWORD *exceptions_to_catch = NULL;
static HANDLE debugger_wakeup_event = 0;
static DWORD debugger_spawn_flags = 0;
-#include "gwin32-private.c"
+#include "gwin32-private.h"
static char *
copy_chars (char *buffer,
diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c
index ab5b574cc..b1efeacf9 100644
--- a/glib/tests/fileutils.c
+++ b/glib/tests/fileutils.c
@@ -2114,7 +2114,7 @@ test_fopen_modes (void)
}
#ifdef G_OS_WIN32
-#include "../gstdio-private.c"
+#include "../gstdio-private.h"
static int
g_wcscmp0 (const gunichar2 *str1,
diff --git a/glib/tests/win32.c b/glib/tests/win32.c
index 748692d65..2a10e19dd 100644
--- a/glib/tests/win32.c
+++ b/glib/tests/win32.c
@@ -30,7 +30,7 @@
static char *argv0 = NULL;
-#include "../gwin32-private.c"
+#include "../gwin32-private.h"
static void
test_subst_pid_and_event (void)
diff --git a/glib/win_iconv.c b/glib/win_iconv.h
index 8635c37e3..8635c37e3 100644
--- a/glib/win_iconv.c
+++ b/glib/win_iconv.h
diff --git a/gmodule/gmodule-win32.c b/gmodule/gmodule-win32.h
index bea841271..bea841271 100644
--- a/gmodule/gmodule-win32.c
+++ b/gmodule/gmodule-win32.h
diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c
index aafaaf0ad..720b6f334 100644
--- a/gmodule/gmodule.c
+++ b/gmodule/gmodule.c
@@ -21,10 +21,10 @@
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
-/*
+/*
* MT safe
*/
@@ -85,7 +85,7 @@
* it must ensure that it is never unloaded, by calling g_module_make_resident().
*
* Example: Calling a function defined in a GModule
- * |[<!-- language="C" -->
+ * |[<!-- language="C" -->
* // the function signature for 'say_hello'
* typedef void (* SayHelloFunc) (const char *message);
*
@@ -265,7 +265,7 @@ g_module_find_by_handle (gpointer handle)
{
GModule *module;
GModule *retval = NULL;
-
+
if (main_module && main_module->handle == handle)
retval = main_module;
else
@@ -284,7 +284,7 @@ g_module_find_by_name (const gchar *name)
{
GModule *module;
GModule *retval = NULL;
-
+
for (module = modules; module; module = module->next)
if (strcmp (name, module->file_name) == 0)
{
@@ -314,7 +314,7 @@ g_module_set_error (const gchar *error)
#if (G_MODULE_IMPL == G_MODULE_IMPL_DL)
#include "gmodule-dl.c"
#elif (G_MODULE_IMPL == G_MODULE_IMPL_WIN32)
-#include "gmodule-win32.c"
+#include "gmodule-win32.h"
#elif (G_MODULE_IMPL == G_MODULE_IMPL_AR)
#include "gmodule-ar.c"
#else
@@ -375,7 +375,7 @@ gboolean
g_module_supported (void)
{
SUPPORT_OR_RETURN (FALSE);
-
+
return TRUE;
}
@@ -391,7 +391,7 @@ parse_libtool_archive (const gchar* libtool_name)
gchar *name;
GTokenType token;
GScanner *scanner;
-
+
int fd = g_open (libtool_name, O_RDONLY | O_CLOEXEC, 0);
if (fd < 0)
{
@@ -404,21 +404,21 @@ parse_libtool_archive (const gchar* libtool_name)
scanner = g_scanner_new (NULL);
g_scanner_input_file (scanner, fd);
scanner->config->symbol_2_token = TRUE;
- g_scanner_scope_add_symbol (scanner, 0, "dlname",
+ g_scanner_scope_add_symbol (scanner, 0, "dlname",
GUINT_TO_POINTER (TOKEN_DLNAME));
- g_scanner_scope_add_symbol (scanner, 0, "installed",
+ g_scanner_scope_add_symbol (scanner, 0, "installed",
GUINT_TO_POINTER (TOKEN_INSTALLED));
- g_scanner_scope_add_symbol (scanner, 0, "libdir",
+ g_scanner_scope_add_symbol (scanner, 0, "libdir",
GUINT_TO_POINTER (TOKEN_LIBDIR));
while (!g_scanner_eof (scanner))
{
token = g_scanner_get_next_token (scanner);
- if (token == TOKEN_DLNAME || token == TOKEN_INSTALLED ||
+ if (token == TOKEN_DLNAME || token == TOKEN_INSTALLED ||
token == TOKEN_LIBDIR)
{
if (g_scanner_get_next_token (scanner) != '=' ||
- g_scanner_get_next_token (scanner) !=
- (token == TOKEN_INSTALLED ?
+ g_scanner_get_next_token (scanner) !=
+ (token == TOKEN_INSTALLED ?
G_TOKEN_IDENTIFIER : G_TOKEN_STRING))
{
gchar *display_libtool_name = g_filename_display_name (libtool_name);
@@ -440,7 +440,7 @@ parse_libtool_archive (const gchar* libtool_name)
lt_dlname = g_strdup (scanner->value.v_string);
}
else if (token == TOKEN_INSTALLED)
- lt_installed =
+ lt_installed =
strcmp (scanner->value.v_identifier, "yes") == 0;
else /* token == TOKEN_LIBDIR */
{
@@ -448,7 +448,7 @@ parse_libtool_archive (const gchar* libtool_name)
lt_libdir = g_strdup (scanner->value.v_string);
}
}
- }
+ }
}
if (!lt_installed)
@@ -472,7 +472,7 @@ parse_libtool_archive (const gchar* libtool_name)
}
name = g_strconcat (lt_libdir, G_DIR_SEPARATOR_S, lt_dlname, NULL);
-
+
g_free (lt_dlname);
g_free (lt_libdir);
@@ -541,11 +541,11 @@ g_module_open_full (const gchar *file_name,
GModule *module;
gpointer handle = NULL;
gchar *name = NULL;
-
+
SUPPORT_OR_RETURN (NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
+
g_rec_mutex_lock (&g_module_global_lock);
if (G_UNLIKELY (!module_debug_initialized))
@@ -555,7 +555,7 @@ g_module_open_full (const gchar *file_name,
flags &= ~G_MODULE_BIND_LAZY;
if (!file_name)
- {
+ {
if (!main_module)
{
handle = _g_module_self ();
@@ -580,13 +580,13 @@ g_module_open_full (const gchar *file_name,
g_rec_mutex_unlock (&g_module_global_lock);
return main_module;
}
-
+
/* we first search the module list by name */
module = g_module_find_by_name (file_name);
if (module)
{
module->ref_count++;
-
+
g_rec_mutex_unlock (&g_module_global_lock);
return module;
}
@@ -701,7 +701,7 @@ g_module_open_full (const gchar *file_name,
gchar *saved_error;
GModuleCheckInit check_init;
const gchar *check_failed = NULL;
-
+
/* search the module list by handle, since file names are not unique */
module = g_module_find_by_handle (handle);
if (module)
@@ -709,14 +709,14 @@ g_module_open_full (const gchar *file_name,
_g_module_close (module->handle);
module->ref_count++;
g_module_set_error (NULL);
-
+
g_rec_mutex_unlock (&g_module_global_lock);
return module;
}
-
+
saved_error = g_strdup (g_module_error ());
g_module_set_error (NULL);
-
+
module = g_new (GModule, 1);
module->file_name = g_strdup (file_name);
module->handle = handle;
@@ -725,15 +725,15 @@ g_module_open_full (const gchar *file_name,
module->unload = NULL;
module->next = modules;
modules = module;
-
+
/* check initialization */
if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init) && check_init != NULL)
check_failed = check_init (module);
-
+
/* we don't call unload() if the initialization check failed. */
if (!check_failed)
g_module_symbol (module, "g_module_unload", (gpointer) &module->unload);
-
+
if (check_failed)
{
gchar *temp_error;
@@ -791,14 +791,14 @@ gboolean
g_module_close (GModule *module)
{
SUPPORT_OR_RETURN (FALSE);
-
+
g_return_val_if_fail (module != NULL, FALSE);
g_return_val_if_fail (module->ref_count > 0, FALSE);
-
+
g_rec_mutex_lock (&g_module_global_lock);
module->ref_count--;
-
+
if (!module->ref_count && !module->is_resident && module->unload)
{
GModuleUnload unload;
@@ -812,9 +812,9 @@ g_module_close (GModule *module)
{
GModule *last;
GModule *node;
-
+
last = NULL;
-
+
node = modules;
while (node)
{
@@ -830,12 +830,12 @@ g_module_close (GModule *module)
node = last->next;
}
module->next = NULL;
-
+
_g_module_close (module->handle);
g_free (module->file_name);
g_free (module);
}
-
+
g_rec_mutex_unlock (&g_module_global_lock);
return g_module_error() == NULL;
}
@@ -889,11 +889,11 @@ g_module_symbol (GModule *module,
if (symbol)
*symbol = NULL;
SUPPORT_OR_RETURN (FALSE);
-
+
g_return_val_if_fail (module != NULL, FALSE);
g_return_val_if_fail (symbol_name != NULL, FALSE);
g_return_val_if_fail (symbol != NULL, FALSE);
-
+
g_rec_mutex_lock (&g_module_global_lock);
#ifdef G_MODULE_NEED_USCORE
@@ -907,7 +907,7 @@ g_module_symbol (GModule *module,
#else /* !G_MODULE_NEED_USCORE */
*symbol = _g_module_symbol (module->handle, symbol_name);
#endif /* !G_MODULE_NEED_USCORE */
-
+
module_error = g_module_error ();
if (module_error)
{
@@ -918,7 +918,7 @@ g_module_symbol (GModule *module,
g_free (error);
*symbol = NULL;
}
-
+
g_rec_mutex_unlock (&g_module_global_lock);
return !module_error;
}
@@ -937,10 +937,10 @@ const gchar *
g_module_name (GModule *module)
{
g_return_val_if_fail (module != NULL, NULL);
-
+
if (module == main_module)
return "main";
-
+
return module->file_name;
}
@@ -976,7 +976,7 @@ g_module_build_path (const gchar *directory,
const gchar *module_name)
{
g_return_val_if_fail (module_name != NULL, NULL);
-
+
return _g_module_build_path (directory, module_name);
}
diff --git a/meson.build b/meson.build
index 810c92561..be834b689 100644
--- a/meson.build
+++ b/meson.build
@@ -2074,7 +2074,7 @@ glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack)
# available in the actual runtime environment. On Windows, we always use
# the built-in implementation
if host_system == 'windows'
- # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need
+ # We have a #include "win_iconv.h" in gconvert.c on Windows, so we don't need
# any external library for it
libiconv = []
else