-/* Copyright (C) 2000 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ 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.
The GNU C 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
- Library General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <mcheck.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
-
+#include <libc-diag.h>
/* We expect four arguments:
- source directory name
DIR *dir2;
int result = 0;
struct dirent64 *d;
- struct dirent64 direntbuf;
+ union
+ {
+ struct dirent64 d;
+ char room [offsetof (struct dirent64, d_name[0]) + NAME_MAX + 1];
+ }
+ direntbuf;
char *objdir_copy1;
char *objdir_copy2;
char *buf;
while ((d = readdir64 (dir1)) != NULL)
{
-#ifdef _DIRENT_HAVE_D_TYPE
if (d->d_type != DT_UNKNOWN && d->d_type != DT_REG)
continue;
-#endif
if (d->d_ino == st2.st_ino)
{
while ((d = readdir64 (dir2)) != NULL)
{
-#ifdef _DIRENT_HAVE_D_TYPE
if (d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
continue;
-#endif
if (d->d_ino == st2.st_ino)
{
exit (1);
}
+ /* The test below covers the deprecated readdir64_r function. */
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wdeprecated-declarations");
+
/* Try to find the new directory. */
rewinddir (dir1);
- while (readdir64_r (dir1, &direntbuf, &d) == 0 && d != NULL)
+ while (readdir64_r (dir1, &direntbuf.d, &d) == 0 && d != NULL)
{
-#ifdef _DIRENT_HAVE_D_TYPE
if (d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
continue;
-#endif
if (d->d_ino == st1.st_ino)
{
}
}
+ DIAG_POP_NEEDS_COMMENT;
+
if (d == NULL)
{
printf ("haven't found new directory \"%s\"\n", buf);
result = 1;
}
+ /* The test below covers the deprecated readdir64_r function. */
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wdeprecated-declarations");
+
/* We now should have a directory and a file in the new directory. */
rewinddir (dir2);
- while (readdir64_r (dir2, &direntbuf, &d) == 0 && d != NULL)
+ while (readdir64_r (dir2, &direntbuf.d, &d) == 0 && d != NULL)
{
if (strcmp (d->d_name, ".") == 0
|| strcmp (d->d_name, "..") == 0
|| strcmp (d->d_name, "another-dir") == 0)
{
-#ifdef _DIRENT_HAVE_D_TYPE
if (d->d_type != DT_UNKNOWN && d->d_type != DT_DIR)
{
printf ("d_type for \"%s\" is wrong\n", d->d_name);
result = 1;
}
-#endif
if (stat64 (d->d_name, &st3) < 0)
{
printf ("cannot stat \"%s\" is wrong\n", d->d_name);
}
else if (strcmp (d->d_name, "and-a-file") == 0)
{
-#ifdef _DIRENT_HAVE_D_TYPE
if (d->d_type != DT_UNKNOWN && d->d_type != DT_REG)
{
printf ("d_type for \"%s\" is wrong\n", d->d_name);
result = 1;
}
-#endif
if (stat64 (d->d_name, &st3) < 0)
{
printf ("cannot stat \"%s\" is wrong\n", d->d_name);
}
}
+ DIAG_POP_NEEDS_COMMENT;
+
if (stat64 ("does-not-exist", &st1) >= 0)
{
puts ("stat for unexisting file did not fail");
result = 1;
}
+ /* One more test before we leave: mkdir() is supposed to fail with
+ EEXIST if the named file is a symlink. */
+ if (symlink ("a-symlink", "a-symlink") != 0)
+ {
+ printf ("cannot create symlink \"a-symlink\": %m\n");
+ result = 1;
+ }
+ else
+ {
+ if (mkdir ("a-symlink", 0666) == 0)
+ {
+ puts ("can make directory \"a-symlink\"");
+ result = 1;
+ }
+ else if (errno != EEXIST)
+ {
+ puts ("mkdir(\"a-symlink\") does not fail with EEXIST\n");
+ result = 1;
+ }
+ if (unlink ("a-symlink") < 0)
+ {
+ printf ("cannot unlink \"a-symlink\": %m\n");
+ result = 1;
+ }
+ }
+
if (chdir (srcdir) < 0)
{
printf ("cannot change back to source directory: %m\n");