source: zzuf/trunk/src/libzzuf.c @ 1486

Last change on this file since 1486 was 1486, checked in by Sam Hocevar, 16 years ago
  • Rename percent to ratio.
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/*
2 *  zzuf - general purpose fuzzer
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: libzzuf.c 1486 2006-12-15 16:10:56Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 *  libzzuf.c: preloaded wrapper library
17 */
18
19#include "config.h"
20#define _GNU_SOURCE
21
22#if defined HAVE_STDINT_H
23#   include <stdint.h>
24#elif defined HAVE_INTTYPES_H
25#   include <inttypes.h>
26#endif
27#include <stdio.h>
28#include <unistd.h>
29#include <stdlib.h>
30#include <fcntl.h>
31#include <regex.h>
32
33#include <stdarg.h>
34#include <dlfcn.h>
35
36#include "libzzuf.h"
37#include "debug.h"
38#include "preload.h"
39
40/* Global variables */
41int   _zzuf_ready   = 0;
42int   _zzuf_debug   = 0;
43int   _zzuf_seed    = 0;
44float _zzuf_ratio   = 0.057f;
45regex_t * _zzuf_include = NULL;
46regex_t * _zzuf_exclude = NULL;
47
48#define MAXFD 1024
49struct zzuf files[MAXFD];
50
51/* Library initialisation shit */
52void zzuf_init(void)
53{
54    char *tmp;
55    int i;
56
57    if(zzuf_preload())
58        abort();
59
60    tmp = getenv("ZZUF_DEBUG");
61    if(tmp && *tmp)
62        _zzuf_debug = 1;
63
64    tmp = getenv("ZZUF_SEED");
65    if(tmp && *tmp)
66        _zzuf_seed = atol(tmp);
67
68    tmp = getenv("ZZUF_RATIO");
69    if(tmp && *tmp)
70        _zzuf_ratio = atof(tmp);
71    if(_zzuf_ratio < 0.0f)
72        _zzuf_ratio = 0.0f;
73    else if(_zzuf_ratio > 5.0f)
74        _zzuf_ratio = 5.0f;
75
76    tmp = getenv("ZZUF_INCLUDE");
77    if(tmp && *tmp)
78    {
79        _zzuf_include = malloc(sizeof(*_zzuf_include));
80        regcomp(_zzuf_include, tmp, 0);
81    }
82
83    tmp = getenv("ZZUF_EXCLUDE");
84    if(tmp && *tmp)
85    {
86        _zzuf_exclude = malloc(sizeof(*_zzuf_exclude));
87        regcomp(_zzuf_exclude, tmp, 0);
88    }
89
90    for(i = 0; i < MAXFD; i++)
91        files[i].managed = 0;
92
93    _zzuf_ready = 1;
94}
95
96/* Deinitialisation */
97void zzuf_fini(void)
98{
99    int i;
100
101    for(i = 0; i < MAXFD; i++)
102    {
103        if(!files[i].managed)
104            continue;
105
106        /* TODO */
107    }
108}
109
Note: See TracBrowser for help on using the repository browser.