summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/krb/cleanup.h
blob: 3a018330ab804529b18141f44120686c12727cf9 (plain)
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
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */

#ifndef KRB5_CLEANUP
#define KRB5_CLEANUP

struct cleanup {
    void                * arg;
    void                (*func)(void *);
};

#define CLEANUP_INIT(x)                         \
    struct cleanup cleanup_data[x];             \
    int cleanup_count = 0;

#define CLEANUP_PUSH(x, y)                      \
    cleanup_data[cleanup_count].arg = x;        \
    cleanup_data[cleanup_count].func = y;       \
    cleanup_count++;

#define CLEANUP_POP(x)                                                  \
    if ((--cleanup_count) && x && (cleanup_data[cleanup_count].func))   \
        cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);

#define CLEANUP_DONE()                                                  \
    while(cleanup_count--)                                              \
        if (cleanup_data[cleanup_count].func)                           \
            cleanup_data[cleanup_count].func(cleanup_data[cleanup_count].arg);


#endif