Michal Privoznik wrote: > There is some magic going on when it comes to stat() or lstat(). > Basically, stat() can either be a regular function, an inline > function that calls __xstat(_STAT_VER, ...) or a macro that does > the same as the inline func. Don't ask why is that, just read the > documentation in sys/stat.h and make sure you have a bucket next > to you. Anyway, currently there will not be both stat and __xstat > symbols at the same time, as one of them gets overwritten to the > other one during compilation. But this is not true anymore once > we start chaining our mocking libraries. Therefore we need a > wrapper that calls desired function from glibc. > > Signed-off-by: Michal Privoznik <[email protected]> > --- > tests/vircgroupmock.c | 14 +++++++------- > tests/virmock.h | 23 +++++++++++++++++++++++ > tests/virpcimock.c | 19 +++++++++---------- > 3 files changed, 39 insertions(+), 17 deletions(-)
...
> diff --git a/tests/virmock.h b/tests/virmock.h
> index 62a7c8f..27c03ba 100644
> --- a/tests/virmock.h
> +++ b/tests/virmock.h
> @@ -27,6 +27,7 @@
> # endif
> # include <stdlib.h>
> # include <stdio.h>
> +# include <sys/stat.h>
>
> # include "internal.h"
>
> @@ -254,6 +255,28 @@
> static void (*real_##name)(void); \
> void name(void)
>
> +static inline int
> +callStat(int (*realStat)(const char *, struct stat *),
> + int (*realXstat)(int, const char *, struct stat *),
> + int __ver, const char *__filename, struct stat *__stat_buf)
> +{
> + if (!realXstat) {
> + if (__ver == _STAT_VER) {
> + return realStat(__filename, __stat_buf);
> + } else {
> + fprintf(stderr, "Not handled __xstat(ver=%d)", __ver);
> + abort();
> + }
> + }
> +
> + return realXstat(__ver, __filename, __stat_buf);
> +}
Hm, this fails on FreeBSD with:
CC nssmock_la-nssmock.lo
In file included from nssmock.c:24:
./virmock.h:264:22: error: use of undeclared identifier '_STAT_VER'
if (__ver == _STAT_VER) {
^
1 error generated.
Makefile:4932: recipe for target 'nssmock_la-nssmock.lo' failed
gmake: *** [nssmock_la-nssmock.lo] Error 1
Roman Bogorodskiy
signature.asc
Description: PGP signature
-- libvir-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/libvir-list
