test_data is an array of (usually) signed char, but
glnx_file_replace_contents_at() takes an array of unsigned bytes.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Formally, `strlen("x")` is not a constant expression, although gcc can
and does optimize it to a constant expression in simple cases.
clang 19.1.6 warns about this usage.
Replace it with the size of a static array (1 more than the strlen of
its contents), which is unambiguously a constant expression.
Resolves: https://gitlab.gnome.org/GNOME/libglnx/-/issues/5
Signed-off-by: Simon McVittie <smcv@collabora.com>
This is a slight generalization of the reproducer contributed by Will
Thompson: as well as exercising the case where the parent is a dangling
symlink (reproducing GNOME/libglnx#1), this also exercises the case where
the parent is a non-directory non-symlink (in this case a regular file).
Reproduces: GNOME/libglnx#1
Co-authored-by: Will Thompson <wjt@endlessos.org>
Signed-off-by: Simon McVittie <smcv@collabora.com>
If we try to create `link/content` where `link` is a dangling symlink,
recursing to create `link` will succeed (mkdirat fails with EEXIST,
which is explicitly ignored), but then mkdirat for `link/content` will
still fail. Fail gracefully instead of crashing out with an assertion
failure.
Resolves: GNOME/libglnx#1
Signed-off-by: Simon McVittie <smcv@collabora.com>
Otherwise it could potentially race with tests in other executables that
also want to create `./test`, or interfere with other test-cases in the
same executable that expect `./test` to be nonexistent or empty.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Meson 1.1.0 officially deprecates string defaults for boolean options,
but boolean defaults worked in many older Meson versions, going back to
at least 0.49.x.
Signed-off-by: Simon McVittie <smcv@collabora.com>
When compiling with GLib older than 2.80.x, we provide a compatibility
backport of g_closefrom() and g_fdwalk_set_cloexec(), but when compiling
with newer GLib, we rely on GLib to provide those.
The intended scope of libglnx (Linux only) is narrower than the scope
of `<glib-unix.h>` (any Unix platform), so we can safely include
`<glib-unix.h>` unconditionally. This provides least-astonishment by
having `#include <libglnx.h>` with newer GLib always provide a superset
of the functionality it provides with older GLib.
This would have avoided needing
https://github.com/flatpak/flatpak/pull/5737.
Fixes: 6ada39c3 "backports: Add a backport of g_closefrom(), g_fdwalk_set_cloexec()"
Signed-off-by: Simon McVittie <smcv@collabora.com>
Recent versions of openSUSE default to using -Werror=return-type for
package builds, which results in all of these function checks
incorrectly detecting the function as not being available.
Co-authored-by: Peng Yi
Resolves: https://gitlab.gnome.org/GNOME/libglnx/-/issues/4
Signed-off-by: Simon McVittie <smcv@debian.org>
These will be new API in GLib 2.79.2.
The only code change in the implementation, other than the _glnx
wrappers, was to use `close()` instead of `g_close (fd, NULL)` in a
context where it must be async-signal safe.
The test-case needed some more adjustments to be backwards-compatible
with GLib from the distant past.
Signed-off-by: Simon McVittie <smcv@collabora.com>
We weren't passing the right path argument here.
This bug would've been quickly noticed if the function were actually
used but I still did at least a global GitHub search which didn't return
any users.
This allows doing:
meson setup _build
meson test -C _build
without an intervening `meson compile` step. Previously, this would have
failed in `tests/testing` because `testing-helper` was never compiled.
For a project this small, there's no real need to distinguish precisely
which tests need the helper: we can have a simpler build by just
assuming that they all do, like Autotools would.
Signed-off-by: Simon McVittie <smcv@collabora.com>
When testing something that is expected to fail or crash, it's useful
to disable core dump reporting.
This is a slightly simplified version of GNOME/glib!3510: because
libglnx isn't portable to non-Linux, we can assume that <sys/prctl.h>,
prctl() and <sys/resource.h> are always available, so we don't need
to check for them in the build system.
Signed-off-by: Simon McVittie <smcv@collabora.com>
This is a very useful utility function that allows you to compare two
strings arrays.
Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
This is essentially the same as glnx_steal_fd, so make glnx_steal_fd an
alias for it.
The unit test is taken from GLib, slightly modified to avoid g_close()
and also test the old name glnx_steal_fd().
Signed-off-by: Simon McVittie <smcv@collabora.com>
g_memdup2() replaces g_memdup(), which is prone to integer overflow on
64-bit systems if copying a very large object with an
attacker-controlled size.
The original version in GLib is extern, but it seems simple enough to
inline a backport.
Related: https://gitlab.gnome.org/GNOME/glib/-/issues/2319
Signed-off-by: Simon McVittie <smcv@collabora.com>