mirror of
https://github.com/libvirt/libvirt.git
synced 2026-08-13 06:34:42 -05:00
virmock.h: Introduce VIR_MOCK_CALL_STAT
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 <mprivozn@redhat.com>
This commit is contained in:
@@ -558,7 +558,7 @@ int __lxstat(int ver, const char *path, struct stat *sb)
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
ret = real___lxstat(ver, newpath, sb);
|
||||
ret = VIR_MOCK_CALL_LSTAT(ver, newpath, sb);
|
||||
free(newpath);
|
||||
} else if (STRPREFIX(path, fakedevicedir0)) {
|
||||
sb->st_mode = S_IFBLK;
|
||||
@@ -569,7 +569,7 @@ int __lxstat(int ver, const char *path, struct stat *sb)
|
||||
sb->st_rdev = makedev(9, 0);
|
||||
return 0;
|
||||
} else {
|
||||
ret = real___lxstat(ver, path, sb);
|
||||
ret = VIR_MOCK_CALL_LSTAT(ver, path, sb);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -589,7 +589,7 @@ int lstat(const char *path, struct stat *sb)
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
ret = real_lstat(newpath, sb);
|
||||
ret = VIR_MOCK_CALL_LSTAT(_STAT_VER, newpath, sb);
|
||||
free(newpath);
|
||||
} else if (STRPREFIX(path, fakedevicedir0)) {
|
||||
sb->st_mode = S_IFBLK;
|
||||
@@ -600,7 +600,7 @@ int lstat(const char *path, struct stat *sb)
|
||||
sb->st_rdev = makedev(9, 0);
|
||||
return 0;
|
||||
} else {
|
||||
ret = real_lstat(path, sb);
|
||||
ret = VIR_MOCK_CALL_LSTAT(_STAT_VER, path, sb);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -620,7 +620,7 @@ int __xstat(int ver, const char *path, struct stat *sb)
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
ret = real___xstat(ver, newpath, sb);
|
||||
ret = VIR_MOCK_CALL_STAT(ver, newpath, sb);
|
||||
free(newpath);
|
||||
} else if (STRPREFIX(path, fakedevicedir0)) {
|
||||
sb->st_mode = S_IFBLK;
|
||||
@@ -631,7 +631,7 @@ int __xstat(int ver, const char *path, struct stat *sb)
|
||||
sb->st_rdev = makedev(9, 0);
|
||||
return 0;
|
||||
} else {
|
||||
ret = real___xstat(ver, path, sb);
|
||||
ret = VIR_MOCK_CALL_STAT(ver, path, sb);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -671,7 +671,7 @@ int stat(const char *path, struct stat *sb)
|
||||
if (!(newpath = strdup(path)))
|
||||
return -1;
|
||||
}
|
||||
ret = real_stat(newpath, sb);
|
||||
ret = VIR_MOCK_CALL_STAT(_STAT_VER, newpath, sb);
|
||||
free(newpath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user