Updated to fedora-glibc-20041001T1134
[glibc.git] / posix / bug-glob1.c
blob4f7e981c75bab59558a86377a706ad90a45046b5
1 /* Test case for globbing dangling symlink. By Ulrich Drepper. */
2 #include <errno.h>
3 #include <error.h>
4 #include <glob.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
11 static void prepare (int argc, char *argv[]);
12 #define PREPARE prepare
13 static int do_test (void);
14 #define TEST_FUNCTION do_test ()
16 #include "../test-skeleton.c"
19 static char *fname;
21 static void
22 prepare (int argc, char *argv[])
24 if (argc < 2)
25 error (EXIT_FAILURE, 0, "missing argument");
27 size_t len = strlen (argv[1]);
28 static const char ext[] = "globXXXXXX";
29 fname = malloc (len + 1 + sizeof (ext));
30 if (fname == NULL)
31 error (EXIT_FAILURE, errno, "cannot create temp file");
32 strcpy (stpcpy (stpcpy (fname, argv[1]), "/"), ext);
33 fname = mktemp (fname);
34 if (fname == NULL || *fname == '\0')
35 error (EXIT_FAILURE, errno, "cannot create temp file name");
36 if (symlink ("bug-glob1-does-not-exist", fname) != 0)
37 error (EXIT_FAILURE, errno, "cannot create symlink");
38 add_temp_file (fname);
42 static int
43 do_test (void)
45 glob_t gl;
46 int retval = 0;
47 int e;
49 e = glob (fname, 0, NULL, &gl);
50 if (e == 0)
52 printf ("glob(\"%s\") succeeded\n", fname);
53 retval = 1;
55 globfree (&gl);
57 size_t fnamelen = strlen (fname);
58 char buf[fnamelen + 2];
60 strcpy (buf, fname);
61 buf[fnamelen - 1] = '?';
62 e = glob (buf, 0, NULL, &gl);
63 if (e == 0)
65 printf ("glob(\"%s\") succeeded\n", buf);
66 retval = 1;
68 globfree (&gl);
70 strcpy (buf, fname);
71 buf[fnamelen] = '*';
72 buf[fnamelen + 1] = '\0';
73 e = glob (buf, 0, NULL, &gl);
74 if (e == 0)
76 printf ("glob(\"%s\") succeeded\n", buf);
77 retval = 1;
79 globfree (&gl);
81 return retval;