File: _libstat_wrapper.c

package info (click to toggle)
libqb 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,092 kB
  • sloc: ansic: 22,191; sh: 5,232; makefile: 607
file content (55 lines) | stat: -rw-r--r-- 1,363 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
51
52
53
54
55
/*
 * Simulate FORCESOCKETSFILE existing for the IPC tests
 */
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <string.h>
#include <sys/stat.h>
#include "../include/config.h"

// __xstat for earlier libc
int __xstat(int __ver, const char *__filename, struct stat *__stat_buf)
{
#if defined(QB_LINUX) || defined(QB_CYGWIN)
	static int opened = 0;
	static int (*real_xstat)(int __ver, const char *__filename, void *__stat_buf);

	if (!opened) {
		real_xstat = dlsym(RTLD_NEXT, "__xstat");
		opened = 1;
	}

	if (strcmp(__filename, FORCESOCKETSFILE) == 0) {
		fprintf(stderr, "__xstat called for %s\n", __filename);
		return 0; /* it exists! */
	}

	return real_xstat(__ver, __filename, __stat_buf);
#else
	return -1; /* Error in the unlikely event we get called on *BSD* */
#endif
}

// stat for F35 and later
int stat(const char *__filename, struct stat *__stat_buf)
{
#if defined(QB_LINUX) || defined(QB_CYGWIN)
	static int opened = 0;
	static int (*real_stat)(const char *__filename, void *__stat_buf);

	if (!opened) {
		real_stat = dlsym(RTLD_NEXT, "stat");
		opened = 1;
	}

	if (strcmp(__filename, FORCESOCKETSFILE) == 0) {
		fprintf(stderr, "stat called for %s\n", __filename);
		return 0; /* it exists! */
	}

	return real_stat(__filename, __stat_buf);
#else
	return -1; /* Error in the unlikely event we get called on *BSD* */
#endif
}