Fix wrong PPC_FEATURE_* values.
[glibc.git] / posix / bug-glob1.c
blob05c2da7584f863acb6ecac23d57404f120751871
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 + sizeof (ext));
30 if (fname == NULL)
31 error (EXIT_FAILURE, errno, "cannot create temp file");
32 again:
33 strcpy (stpcpy (fname, argv[1]), ext);
34 fname = mktemp (fname);
35 if (fname == NULL || *fname == '\0')
36 error (EXIT_FAILURE, errno, "cannot create temp file name");
37 if (symlink ("bug-glob1-does-not-exist", fname) != 0)
39 if (errno == EEXIST)
40 goto again;
42 error (EXIT_FAILURE, errno, "cannot create symlink");
44 add_temp_file (fname);
48 static int
49 do_test (void)
51 glob_t gl;
52 int retval = 0;
53 int e;
55 e = glob (fname, 0, NULL, &gl);
56 if (e == 0)
58 printf ("glob(\"%s\") succeeded\n", fname);
59 retval = 1;
61 globfree (&gl);
63 size_t fnamelen = strlen (fname);
64 char buf[fnamelen + 2];
66 strcpy (buf, fname);
67 buf[fnamelen - 1] = '?';
68 e = glob (buf, 0, NULL, &gl);
69 if (e == 0)
71 printf ("glob(\"%s\") succeeded\n", buf);
72 retval = 1;
74 globfree (&gl);
76 strcpy (buf, fname);
77 buf[fnamelen] = '*';
78 buf[fnamelen + 1] = '\0';
79 e = glob (buf, 0, NULL, &gl);
80 if (e == 0)
82 printf ("glob(\"%s\") succeeded\n", buf);
83 retval = 1;
85 globfree (&gl);
87 return retval;