summaryrefslogtreecommitdiff
path: root/src/postmulti/fake_strcmp.c
blob: 0f5da471e12c14ae38993dbd3a024afceb83f6a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* System library. */
#include <sys_defs.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <dlfcn.h>

/* Utility library. */
#include <msg.h>

/* Global library. */
#include <mail_params.h>

static int (*real_strcmp) (const char *, const char *);

/* find_real_func - libc lookup */

static void *find_real_func(const char *name)
{
    void   *sym;

    /*
     * XXX Casting a data pointer into a function pointer is non-portable.
     * Unfortunately, the dlfunc() function is available on FreeBSD but not
     * on Linux or Solaris. This is a cosmetic issue except on systems with
     * non-flat memory models.
     */
    if ((sym = dlsym(RTLD_NEXT, name)) == 0) {
	fprintf(stderr, "preload error for %s: %s\n", name, dlerror());
	exit(1);
    }
    return (sym);
}

int     strcmp(const char *s1, const char *s2)
{
    if (real_strcmp == 0)
	real_strcmp = find_real_func("strcmp");
    if (real_strcmp(DEF_CONFIG_DIR, s2) == 0)
	return (0);
    return real_strcmp(s1, s2);
}