Ignore:
Timestamp:
Jan 18, 2007, 1:21:07 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Added enough autoconf checks and #ifdefs so that libzzuf builds on Win32. zzuf itself doesn't build yet, though.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/zzuf.c

    r1692 r1695  
    2424#   include <inttypes.h>
    2525#endif
    26 #if defined(HAVE_GETOPT_H)
     26#if defined HAVE_GETOPT_H
    2727#   include <getopt.h>
    2828#endif
     
    3030#include <stdlib.h>
    3131#include <unistd.h>
    32 #include <regex.h>
     32#if defined HAVE_REGEX_H
     33#   include <regex.h>
     34#endif
    3335#include <string.h>
    3436#include <errno.h>
    3537#include <signal.h>
    36 #include <sys/wait.h>
     38#if defined HAVE_SYS_WAIT_H
     39#   include <sys/wait.h>
     40#endif
    3741#include <sys/time.h>
    38 #include <sys/resource.h>
     42#if defined HAVE_SYS_RESOURCE_H
     43#   include <sys/resource.h>
     44#endif
    3945
    4046#include "libzzuf.h"
     
    4652#include "timer.h"
    4753
     54#if !defined SIGKILL
     55#   define SIGKILL 9
     56#endif
     57
    4858static void loop_stdin(struct opts *opts);
    4959
     
    5363
    5464static char const *sig2str(int);
     65#if defined HAVE_REGEX_H
    5566static char *merge_regex(char *, char *);
    5667static char *merge_file(char *, char *);
     68#endif
    5769static void set_environment(char const *);
    5870static void version(void);
    59 #if defined(HAVE_GETOPT_H)
     71#if defined HAVE_GETOPT_H
    6072static void usage(void);
    6173#endif
     
    7587{
    7688    struct opts _opts, *opts = &_opts;
    77     char *tmp, *include, *exclude;
    78     int i, cmdline = 0;
    79 
    80     include = exclude = NULL;
     89    char *tmp;
     90#if defined HAVE_REGEX_H
     91    char *include = NULL, *exclude = NULL;
     92    int cmdline = 0;
     93#endif
     94    int i;
    8195
    8296    _zz_opts_init(opts);
    8397
    84 #if defined(HAVE_GETOPT_H)
     98#if defined HAVE_GETOPT_H
    8599    for(;;)
    86100    {
    87 #   define OPTSTR "AB:cC:dD:E:F:iI:mM:nP:qr:R:s:ST:vxhV"
    88 #   ifdef HAVE_GETOPT_LONG
     101#   if defined HAVE_REGEX_H
     102#       define OPTSTR "AB:cC:dD:E:F:iI:mM:nP:qr:R:s:ST:vxhV"
     103#   else
     104#       define OPTSTR "AB:C:dD:F:imM:nP:qr:R:s:ST:vxhV"
     105#   endif
     106#   if defined HAVE_GETOPT_LONG
    89107#       define MOREINFO "Try `%s --help' for more information.\n"
    90108        int option_index = 0;
     
    94112            { "autoinc",     0, NULL, 'A' },
    95113            { "max-bytes",   1, NULL, 'B' },
     114#if defined HAVE_REGEX_H
    96115            { "cmdline",     0, NULL, 'c' },
     116#endif
    97117            { "max-crashes", 1, NULL, 'C' },
    98118            { "debug",       0, NULL, 'd' },
    99119            { "delay",       1, NULL, 'D' },
     120#if defined HAVE_REGEX_H
    100121            { "exclude",     1, NULL, 'E' },
     122#endif
    101123            { "max-forks",   1, NULL, 'F' },
    102124            { "stdin",       0, NULL, 'i' },
     125#if defined HAVE_REGEX_H
    103126            { "include",     1, NULL, 'I' },
     127#endif
    104128            { "md5",         0, NULL, 'm' },
    105129            { "max-memory",  1, NULL, 'M' },
     
    134158            opts->maxbytes = atoi(optarg);
    135159            break;
     160#if defined HAVE_REGEX_H
    136161        case 'c': /* --cmdline */
    137162            cmdline = 1;
    138163            break;
     164#endif
    139165        case 'C': /* --max-crashes */
    140166            opts->maxcrashes = atoi(optarg);
     
    148174            opts->delay = (int64_t)(atof(optarg) * 1000000.0);
    149175            break;
     176#if defined HAVE_REGEX_H
    150177        case 'E': /* --exclude */
    151178            exclude = merge_regex(exclude, optarg);
     
    157184            }
    158185            break;
     186#endif
    159187        case 'F': /* --max-forks */
    160188            opts->maxchild = atoi(optarg) > 1 ? atoi(optarg) : 1;
     
    163191            setenv("ZZUF_STDIN", "1", 1);
    164192            break;
     193#if defined HAVE_REGEX_H
    165194        case 'I': /* --include */
    166195            include = merge_regex(include, optarg);
     
    172201            }
    173202            break;
     203#endif
    174204        case 'm': /* --md5 */
    175205            opts->md5 = 1;
     
    255285
    256286    /* If asked to launch programs */
     287#if defined HAVE_REGEX_H
    257288    if(cmdline)
    258289    {
     
    274305    if(exclude)
    275306        setenv("ZZUF_EXCLUDE", exclude, 1);
     307#endif
     308
    276309    if(opts->protect)
    277310        setenv("ZZUF_PROTECT", opts->protect, 1);
     
    371404}
    372405
     406#if defined HAVE_REGEX_H
    373407static char *merge_file(char *regex, char *file)
    374408{
     
    418452    return regex;
    419453}
     454#endif
    420455
    421456static void spawn_children(struct opts *opts)
     
    770805}
    771806
    772 #if defined(HAVE_GETOPT_H)
     807#if defined HAVE_GETOPT_H
    773808static void usage(void)
    774809{
     810#if defined HAVE_REGEX_H
    775811    printf("Usage: zzuf [-AcdimnqSvx] [-r ratio] [-s seed | -s start:stop]\n");
    776812    printf("                          [-D delay] [-F forks] [-C crashes] [-B bytes]\n");
    777813    printf("                          [-T seconds] [-M bytes] [-P protect] [-R refuse]\n");
    778814    printf("                          [-I include] [-E exclude] [PROGRAM [--] [ARGS]...]\n");
    779 #   ifdef HAVE_GETOPT_LONG
     815#else
     816    printf("Usage: zzuf [-AdimnqSvx] [-r ratio] [-s seed | -s start:stop]\n");
     817    printf("                         [-D delay] [-F forks] [-C crashes] [-B bytes]\n");
     818    printf("                         [-T seconds] [-M bytes] [-P protect] [-R refuse]\n");
     819    printf("                         [PROGRAM [--] [ARGS]...]\n");
     820#endif
     821#   if defined HAVE_GETOPT_LONG
    780822    printf("       zzuf -h | --help\n");
    781823    printf("       zzuf -V | --version\n");
     
    787829    printf("\n");
    788830    printf("Mandatory arguments to long options are mandatory for short options too.\n");
    789 #   ifdef HAVE_GETOPT_LONG
     831#   if defined HAVE_GETOPT_LONG
    790832    printf("  -A, --autoinc             increment seed each time a new file is opened\n");
    791833    printf("  -B, --max-bytes <n>       kill children that output more than <n> bytes\n");
     834#if defined HAVE_REGEX_H
    792835    printf("  -c, --cmdline             only fuzz files specified in the command line\n");
     836#endif
    793837    printf("  -C, --max-crashes <n>     stop after <n> children have crashed (default 1)\n");
    794838    printf("  -d, --debug               print debug messages\n");
    795839    printf("  -D, --delay               delay between forks\n");
     840#if defined HAVE_REGEX_H
    796841    printf("  -E, --exclude <regex>     do not fuzz files matching <regex>\n");
     842#endif
    797843    printf("  -F, --max-forks <n>       number of concurrent children (default 1)\n");
    798844    printf("  -i, --stdin               fuzz standard input\n");
     845#if defined HAVE_REGEX_H
    799846    printf("  -I, --include <regex>     only fuzz files matching <regex>\n");
     847#endif
    800848    printf("  -m, --md5                 compute the output's MD5 hash\n");
    801849    printf("  -M, --max-memory <n>      maximum child virtual memory size in MB\n");
     
    817865    printf("  -A               increment seed each time a new file is opened\n");
    818866    printf("  -B <n>           kill children that output more than <n> bytes\n");
     867#if defined HAVE_REGEX_H
    819868    printf("  -c               only fuzz files specified in the command line\n");
     869#endif
    820870    printf("  -C <n>           stop after <n> children have crashed (default 1)\n");
    821871    printf("  -d               print debug messages\n");
    822872    printf("  -D               delay between forks\n");
     873#if defined HAVE_REGEX_H
    823874    printf("  -E <regex>       do not fuzz files matching <regex>\n");
     875#endif
    824876    printf("  -F <n>           number of concurrent forks (default 1)\n");
    825877    printf("  -i               fuzz standard input\n");
     878#if defined HAVE_REGEX_H
    826879    printf("  -I <regex>       only fuzz files matching <regex>\n");
     880#endif
    827881    printf("  -m               compute the output's MD5 hash\n");
    828882    printf("  -M               maximum child virtual memory size in MB\n");
Note: See TracChangeset for help on using the changeset viewer.