diff --git a/ChangeLog b/ChangeLog index c67c47162e..9647c8ec3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2000-09-27 Ulrich Drepper + + * posix/tst-dir.c: Test a few error cases of chdir. + 2000-09-26 Ulrich Drepper * math/math_private.h: Don't add long double prototypes if diff --git a/posix/tst-dir.c b/posix/tst-dir.c index 4f55fcc90d..1eff3b5e06 100644 --- a/posix/tst-dir.c +++ b/posix/tst-dir.c @@ -1,4 +1,24 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 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. + + 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. + + 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. */ + #include +#include #include #include #include @@ -338,7 +358,7 @@ main (int argc, char *argv[]) result = 1; } - if (chdir (buf)< 0) + if (chdir (buf) < 0) { printf ("cannot change to new directory: %m\n"); exit (1); @@ -377,6 +397,43 @@ main (int argc, char *argv[]) } close (fd); + /* Some tests about error reporting. */ + errno = 0; + if (chdir ("and-a-file") >= 0) + { + printf ("chdir to \"and-a-file\" succeeded\n"); + exit (1); + } + if (errno != ENOTDIR) + { + printf ("chdir to \"and-a-file\" didn't set correct error\n"); + result = 1; + } + + errno = 0; + if (chdir ("and-a-file/..") >= 0) + { + printf ("chdir to \"and-a-file/..\" succeeded\n"); + exit (1); + } + if (errno != ENOTDIR) + { + printf ("chdir to \"and-a-file/..\" didn't set correct error\n"); + result = 1; + } + + errno = 0; + if (chdir ("another-dir/../and-a-file") >= 0) + { + printf ("chdir to \"another-dir/../and-a-file\" succeeded\n"); + exit (1); + } + if (errno != ENOTDIR) + { + printf ("chdir to \"another-dir/../and-a-file\" didn't set correct error\n"); + result = 1; + } + /* We now should have a directory and a file in the new directory. */ rewinddir (dir2); while (readdir64_r (dir2, &direntbuf, &d) == 0 && d != NULL)