|
Packit Service |
2723c6 |
/* Tests of symlinkat.
|
|
Packit Service |
2723c6 |
Copyright (C) 2009-2018 Free Software Foundation, Inc.
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
2723c6 |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
2723c6 |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
2723c6 |
(at your option) any later version.
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
2723c6 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
2723c6 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
2723c6 |
GNU General Public License for more details.
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
2723c6 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
/* Written by Eric Blake <ebb9@byu.net>, 2009. */
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
#include <config.h>
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
#include <unistd.h>
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
#include "signature.h"
|
|
Packit Service |
2723c6 |
SIGNATURE_CHECK (symlinkat, int, (char const *, int, char const *));
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
#include <fcntl.h>
|
|
Packit Service |
2723c6 |
#include <errno.h>
|
|
Packit Service |
2723c6 |
#include <stdbool.h>
|
|
Packit Service |
2723c6 |
#include <stdio.h>
|
|
Packit Service |
2723c6 |
#include <stdlib.h>
|
|
Packit Service |
2723c6 |
#include <string.h>
|
|
Packit Service |
2723c6 |
#include <sys/stat.h>
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
#include "ignore-value.h"
|
|
Packit Service |
2723c6 |
#include "macros.h"
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
#ifndef HAVE_SYMLINK
|
|
Packit Service |
2723c6 |
# define HAVE_SYMLINK 0
|
|
Packit Service |
2723c6 |
#endif
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
#define BASE "test-symlinkat.t"
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
#include "test-symlink.h"
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
static int dfd = AT_FDCWD;
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
static int
|
|
Packit Service |
2723c6 |
do_symlink (char const *contents, char const *name)
|
|
Packit Service |
2723c6 |
{
|
|
Packit Service |
2723c6 |
return symlinkat (contents, dfd, name);
|
|
Packit Service |
2723c6 |
}
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
int
|
|
Packit Service |
2723c6 |
main (void)
|
|
Packit Service |
2723c6 |
{
|
|
Packit Service |
2723c6 |
int result;
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
/* Remove any leftovers from a previous partial run. */
|
|
Packit Service |
2723c6 |
ignore_value (system ("rm -rf " BASE "*"));
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
/* Test behaviour for invalid file descriptors. */
|
|
Packit Service |
2723c6 |
{
|
|
Packit Service |
2723c6 |
errno = 0;
|
|
Packit Service |
2723c6 |
ASSERT (symlinkat ("foo", -1, "bar") == -1);
|
|
Packit Service |
2723c6 |
ASSERT (errno == EBADF
|
|
Packit Service |
2723c6 |
|| errno == ENOSYS /* seen on mingw */
|
|
Packit Service |
2723c6 |
);
|
|
Packit Service |
2723c6 |
}
|
|
Packit Service |
2723c6 |
{
|
|
Packit Service |
2723c6 |
close (99);
|
|
Packit Service |
2723c6 |
errno = 0;
|
|
Packit Service |
2723c6 |
ASSERT (symlinkat ("foo", 99, "bar") == -1);
|
|
Packit Service |
2723c6 |
ASSERT (errno == EBADF
|
|
Packit Service |
2723c6 |
|| errno == ENOSYS /* seen on mingw */
|
|
Packit Service |
2723c6 |
);
|
|
Packit Service |
2723c6 |
}
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
/* Perform same checks as counterpart functions. */
|
|
Packit Service |
2723c6 |
result = test_symlink (do_symlink, false);
|
|
Packit Service |
2723c6 |
dfd = openat (AT_FDCWD, ".", O_RDONLY);
|
|
Packit Service |
2723c6 |
ASSERT (0 <= dfd);
|
|
Packit Service |
2723c6 |
ASSERT (test_symlink (do_symlink, false) == result);
|
|
Packit Service |
2723c6 |
|
|
Packit Service |
2723c6 |
ASSERT (close (dfd) == 0);
|
|
Packit Service |
2723c6 |
if (result == 77)
|
|
Packit Service |
2723c6 |
fputs ("skipping test: symlinks not supported on this file system\n",
|
|
Packit Service |
2723c6 |
stderr);
|
|
Packit Service |
2723c6 |
return result;
|
|
Packit Service |
2723c6 |
}
|