source: trunk/src/libctests/glibc/posix/bug-glob1.c@ 2036

Last change on this file since 2036 was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
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>
9
10
11static void prepare (int argc, char *argv[]);
12#define PREPARE prepare
13static int do_test (void);
14#define TEST_FUNCTION do_test ()
15
16#include "../test-skeleton.c"
17
18
19static char *fname;
20
21static void
22prepare (int argc, char *argv[])
23{
24 if (argc < 2)
25 error (EXIT_FAILURE, 0, "missing argument");
26
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)
38 {
39 if (errno == EEXIST)
40 goto again;
41
42 error (EXIT_FAILURE, errno, "cannot create symlink");
43 }
44 add_temp_file (fname);
45}
46
47
48static int
49do_test (void)
50{
51 glob_t gl;
52 int retval = 0;
53 int e;
54
55 e = glob (fname, 0, NULL, &gl);
56 if (e == 0)
57 {
58 printf ("glob(\"%s\") succeeded\n", fname);
59 retval = 1;
60 }
61 globfree (&gl);
62
63 size_t fnamelen = strlen (fname);
64 char buf[fnamelen + 2];
65
66 strcpy (buf, fname);
67 buf[fnamelen - 1] = '?';
68 e = glob (buf, 0, NULL, &gl);
69 if (e == 0)
70 {
71 printf ("glob(\"%s\") succeeded\n", buf);
72 retval = 1;
73 }
74 globfree (&gl);
75
76 strcpy (buf, fname);
77 buf[fnamelen] = '*';
78 buf[fnamelen + 1] = '\0';
79 e = glob (buf, 0, NULL, &gl);
80 if (e == 0)
81 {
82 printf ("glob(\"%s\") succeeded\n", buf);
83 retval = 1;
84 }
85 globfree (&gl);
86
87 return retval;
88}
Note: See TracBrowser for help on using the repository browser.