-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* posix/Makefile: Add rules to build and run bug-glob1. * posix/bug-glob1.c: New file.
- Loading branch information
Ulrich Drepper
committed
Sep 30, 2004
1 parent
c4f4ef8
commit 0da4ee5
Showing
3 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* Test case for globbing dangling symlink. By Ulrich Drepper. */ | ||
#include <errno.h> | ||
#include <error.h> | ||
#include <glob.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
|
||
static void prepare (int argc, char *argv[]); | ||
#define PREPARE prepare | ||
static int do_test (void); | ||
#define TEST_FUNCTION do_test () | ||
|
||
#include "../test-skeleton.c" | ||
|
||
|
||
static char *fname; | ||
|
||
static void | ||
prepare (int argc, char *argv[]) | ||
{ | ||
if (argc < 2) | ||
error (EXIT_FAILURE, 0, "missing argument"); | ||
|
||
size_t len = strlen (argv[1]); | ||
static const char ext[] = "globXXXXXX"; | ||
fname = malloc (len + 1 + sizeof (ext)); | ||
if (fname == NULL) | ||
error (EXIT_FAILURE, errno, "cannot create temp file"); | ||
strcpy (stpcpy (stpcpy (fname, argv[1]), "/"), ext); | ||
fname = mktemp (fname); | ||
if (fname == NULL || *fname == '\0') | ||
error (EXIT_FAILURE, errno, "cannot create temp file name"); | ||
if (symlink ("bug-glob1-does-not-exist", fname) != 0) | ||
error (EXIT_FAILURE, errno, "cannot create symlink"); | ||
add_temp_file (fname); | ||
} | ||
|
||
|
||
static int | ||
do_test (void) | ||
{ | ||
glob_t gl; | ||
int retval = 0; | ||
int e; | ||
|
||
e = glob (fname, 0, NULL, &gl); | ||
if (e == 0) | ||
{ | ||
printf ("glob(\"%s\") succeeded\n", fname); | ||
retval = 1; | ||
} | ||
globfree (&gl); | ||
|
||
size_t fnamelen = strlen (fname); | ||
char buf[fnamelen + 2]; | ||
|
||
strcpy (buf, fname); | ||
buf[fnamelen - 1] = '?'; | ||
e = glob (buf, 0, NULL, &gl); | ||
if (e == 0) | ||
{ | ||
printf ("glob(\"%s\") succeeded\n", buf); | ||
retval = 1; | ||
} | ||
globfree (&gl); | ||
|
||
strcpy (buf, fname); | ||
buf[fnamelen] = '*'; | ||
buf[fnamelen + 1] = '\0'; | ||
e = glob (buf, 0, NULL, &gl); | ||
if (e == 0) | ||
{ | ||
printf ("glob(\"%s\") succeeded\n", buf); | ||
retval = 1; | ||
} | ||
globfree (&gl); | ||
|
||
return retval; | ||
} |