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

Last change on this file since 1494 was 1494, checked in by Sam Hocevar, 16 years ago
  • Split preload.c into load-fd.c and load-stream.c.
  • Property svn:keywords set to Id
File size: 2.2 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 1494 2006-12-17 17:17:31Z 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 "load.h"
39
40/* Global variables */
41int   _zzuf_ready   = 0;
42int   _zzuf_debug   = 0;
43int   _zzuf_seed    = 0;
44float _zzuf_ratio   = 0.004f;
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    tmp = getenv("ZZUF_DEBUG");
58    if(tmp && *tmp)
59        _zzuf_debug = 1;
60
61    tmp = getenv("ZZUF_SEED");
62    if(tmp && *tmp)
63        _zzuf_seed = atol(tmp);
64
65    tmp = getenv("ZZUF_RATIO");
66    if(tmp && *tmp)
67        _zzuf_ratio = atof(tmp);
68    if(_zzuf_ratio < 0.0f)
69        _zzuf_ratio = 0.0f;
70    else if(_zzuf_ratio > 5.0f)
71        _zzuf_ratio = 5.0f;
72
73    tmp = getenv("ZZUF_INCLUDE");
74    if(tmp && *tmp)
75    {
76        _zzuf_include = malloc(sizeof(*_zzuf_include));
77        regcomp(_zzuf_include, tmp, 0);
78    }
79
80    tmp = getenv("ZZUF_EXCLUDE");
81    if(tmp && *tmp)
82    {
83        _zzuf_exclude = malloc(sizeof(*_zzuf_exclude));
84        regcomp(_zzuf_exclude, tmp, 0);
85    }
86
87    for(i = 0; i < MAXFD; i++)
88        files[i].managed = 0;
89
90    zzuf_load_fd();
91    zzuf_load_stream();
92
93    _zzuf_ready = 1;
94
95    debug("libzzuf initialised");
96}
97
98/* Deinitialisation */
99void zzuf_fini(void)
100{
101    int i;
102
103    for(i = 0; i < MAXFD; i++)
104    {
105        if(!files[i].managed)
106            continue;
107
108        /* TODO */
109    }
110}
111
Note: See TracBrowser for help on using the repository browser.