File: libnoprofile.c

package info (click to toggle)
apt 3.1.13
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 22,764 kB
  • sloc: cpp: 71,085; sh: 31,750; xml: 5,553; perl: 217; python: 197; ansic: 191; makefile: 41
file content (45 lines) | stat: -rw-r--r-- 1,272 bytes parent folder | download | duplicates (4)
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
43
44
45
#define _GNU_SOURCE
#undef _FORTIFY_SOURCE
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>

int vprintf(const char *format, va_list ap) {
    if (strncmp(format, "profiling:", strlen("profiling:")) == 0)
        return 0;

    static int (*func_fprintf)(const char *format, va_list ap) = NULL;
    if (func_fprintf == NULL)
       func_fprintf = (int (*)(const char *format, va_list ap))dlsym(RTLD_NEXT, "vprintf");

    return func_fprintf(format, ap);
}
int printf(const char *format, ...) {
    va_list ap;
    va_start(ap, format);
    int res = vprintf(format, ap);
    va_end(ap);
    return res;
}

int vfprintf(FILE *stream, const char *format, va_list ap) {
    if (strncmp(format, "profiling:", strlen("profiling:")) == 0)
        return 0;

    static int (*func_vfprintf)(FILE * stream, const char *format, va_list ap) = NULL;
    if (func_vfprintf == NULL)
       func_vfprintf = (int (*)(FILE * stream, const char *format, va_list ap))dlsym(RTLD_NEXT, "vfprintf");

    return func_vfprintf(stream, format, ap);
}

int fprintf(FILE *stream, const char *format, ...) {
    va_list ap;
    va_start(ap, format);
    int res = vfprintf(stream, format, ap);
    va_end(ap);
    return res;
}