mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-10-30 22:21:26 +00:00
libredirect: add support for unlink, unlinkat, rmdir
add coverage of these and mkdir functions in tests
This commit is contained in:
parent
8fd298a93a
commit
b3a7dc22d1
@ -57,7 +57,7 @@ else stdenv.mkDerivation rec {
|
||||
''}
|
||||
|
||||
if [ -n "$doInstallCheck" ]; then
|
||||
$CC -Wall -std=c99 -O3 test.c -o test
|
||||
$CC -Wall -std=c99 -D_POSIX_C_SOURCE=200809L -O3 test.c -o test
|
||||
fi
|
||||
|
||||
runHook postBuild
|
||||
@ -91,7 +91,7 @@ else stdenv.mkDerivation rec {
|
||||
installCheckPhase = ''
|
||||
(
|
||||
source "$hook/nix-support/setup-hook"
|
||||
NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" ./test
|
||||
NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true:/bar/baz=$(mktemp -d)" ./test
|
||||
)
|
||||
'';
|
||||
|
||||
|
@ -354,3 +354,27 @@ WRAPPER(int, mkdirat)(int dirfd, const char *path, mode_t mode)
|
||||
return mkdirat_real(dirfd, rewrite(path, buf), mode);
|
||||
}
|
||||
WRAPPER_DEF(mkdirat)
|
||||
|
||||
WRAPPER(int, unlink)(const char *path)
|
||||
{
|
||||
int (*unlink_real) (const char *path) = LOOKUP_REAL(unlink);
|
||||
char buf[PATH_MAX];
|
||||
return unlink_real(rewrite(path, buf));
|
||||
}
|
||||
WRAPPER_DEF(unlink)
|
||||
|
||||
WRAPPER(int, unlinkat)(int dirfd, const char *path, int flags)
|
||||
{
|
||||
int (*unlinkat_real) (int dirfd, const char *path, int flags) = LOOKUP_REAL(unlinkat);
|
||||
char buf[PATH_MAX];
|
||||
return unlinkat_real(dirfd, rewrite(path, buf), flags);
|
||||
}
|
||||
WRAPPER_DEF(unlinkat)
|
||||
|
||||
WRAPPER(int, rmdir)(const char *path)
|
||||
{
|
||||
int (*rmdir_real) (const char *path) = LOOKUP_REAL(rmdir);
|
||||
char buf[PATH_MAX];
|
||||
return rmdir_real(rewrite(path, buf));
|
||||
}
|
||||
WRAPPER_DEF(rmdir)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
@ -9,6 +10,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#define TESTDIR "/bar/baz"
|
||||
#define TESTPATH "/foo/bar/test"
|
||||
#define SUBTEST "./test sub"
|
||||
|
||||
@ -59,6 +61,22 @@ int main(int argc, char *argv[])
|
||||
|
||||
assert(stat(TESTPATH, &testsb) != -1);
|
||||
|
||||
assert(mkdir(TESTDIR "/dir-mkdir", 0777) == 0);
|
||||
assert(unlink(TESTDIR "/dir-mkdir") == -1); // it's a directory!
|
||||
#ifndef __APPLE__
|
||||
assert(errno == EISDIR);
|
||||
#endif
|
||||
assert(rmdir(TESTDIR "/dir-mkdir") == 0);
|
||||
assert(unlink(TESTDIR "/dir-mkdir") == -1);
|
||||
assert(errno == ENOENT);
|
||||
|
||||
assert(mkdirat(123, TESTDIR "/dir-mkdirat", 0777) == 0);
|
||||
assert(unlinkat(123, TESTDIR "/dir-mkdirat", 0) == -1); // it's a directory!
|
||||
#ifndef __APPLE__
|
||||
assert(errno == EISDIR);
|
||||
#endif
|
||||
assert(unlinkat(123, TESTDIR "/dir-mkdirat", AT_REMOVEDIR) == 0);
|
||||
|
||||
test_spawn();
|
||||
test_system();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user