| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "signature.h" |
| 20 |
SIGNATURE_CHECK (getopt, int, (int, char * const[], char const *)); |
| 21 |
|
| 22 |
#include <stdio.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <string.h> |
| 25 |
#include <unistd.h> |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#define BACKUP_STDERR_FILENO 10 |
| 32 |
#define ASSERT_STREAM myerr |
| 33 |
#include "macros.h" |
| 34 |
|
| 35 |
static FILE *myerr; |
| 36 |
|
| 37 |
#include "test-getopt.h" |
| 38 |
#if TEST_GETOPT_GNU |
| 39 |
# include "test-getopt_long.h" |
| 40 |
#endif |
| 41 |
|
| 42 |
int |
| 43 |
main (void) |
| 44 |
{ |
| 45 |
|
| 46 |
|
| 47 |
if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO |
| 48 |
|| (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL) |
| 49 |
return 2; |
| 50 |
|
| 51 |
ASSERT (freopen (TEST_GETOPT_TMP_NAME, "w", stderr) == stderr); |
| 52 |
|
| 53 |
|
| 54 |
ASSERT (optind == 1); |
| 55 |
ASSERT (opterr != 0); |
| 56 |
|
| 57 |
setenv ("POSIXLY_CORRECT", "1", 1); |
| 58 |
test_getopt (); |
| 59 |
|
| 60 |
#if TEST_GETOPT_GNU |
| 61 |
test_getopt_long_posix (); |
| 62 |
#endif |
| 63 |
|
| 64 |
unsetenv ("POSIXLY_CORRECT"); |
| 65 |
test_getopt (); |
| 66 |
|
| 67 |
#if TEST_GETOPT_GNU |
| 68 |
test_getopt_long (); |
| 69 |
test_getopt_long_only (); |
| 70 |
#endif |
| 71 |
|
| 72 |
ASSERT (fclose (stderr) == 0); |
| 73 |
ASSERT (remove (TEST_GETOPT_TMP_NAME) == 0); |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |