h8300: Assembly functions
[uclibc-ng.git] / test / misc / bug-glob1.c
blob276983a0da5a026221e2a70f82788831dc89372c
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);
35 /* fname = mktemp (fname); */
36 close(mkstemp(fname));
37 unlink(fname);
39 if (fname == NULL || *fname == '\0')
40 error (EXIT_FAILURE, errno, "cannot create temp file name");
41 if (symlink ("bug-glob1-does-not-exist", fname) != 0)
43 if (errno == EEXIST)
44 goto again;
46 error (EXIT_FAILURE, errno, "cannot create symlink");
48 add_temp_file (fname);
52 static int
53 do_test (void)
55 glob_t gl;
56 int retval = 0;
57 int e;
59 e = glob (fname, 0, NULL, &gl);
60 if (e == 0)
62 printf ("glob(\"%s\") succeeded when it should not have\n", fname);
63 retval = 1;
65 globfree (&gl);
67 size_t fnamelen = strlen (fname);
68 char buf[fnamelen + 2];
70 strcpy (buf, fname);
71 buf[fnamelen - 1] = '?';
72 e = glob (buf, 0, NULL, &gl);
73 if (e == 0)
75 printf ("glob(\"%s\") succeeded when it should not have\n", buf);
76 retval = 1;
78 globfree (&gl);
80 strcpy (buf, fname);
81 buf[fnamelen] = '*';
82 buf[fnamelen + 1] = '\0';
83 e = glob (buf, 0, NULL, &gl);
84 if (e == 0)
86 printf ("glob(\"%s\") succeeded when it should not have\n", buf);
87 retval = 1;
89 globfree (&gl);
91 return retval;