aboutsummaryrefslogtreecommitdiffstats
path: root/libgamma_method_capabilities.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgamma_method_capabilities.c')
-rw-r--r--libgamma_method_capabilities.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/libgamma_method_capabilities.c b/libgamma_method_capabilities.c
index d5bdb93..6c44056 100644
--- a/libgamma_method_capabilities.c
+++ b/libgamma_method_capabilities.c
@@ -6,23 +6,43 @@
* Return the capabilities of an adjustment method
*
* @param this The data structure to fill with the method's capabilities
+ * @param size Should be `sizeof(*this)`, used to let the library know which version
+ * of the structure is used so that it does not write outside of it
* @param method The adjustment method (display server and protocol)
* @return Zero on success, otherwise (negative) the value of an
* error identifier provided by this library
*/
int
-libgamma_method_capabilities(libgamma_method_capabilities_t *restrict this, int method)
+libgamma_method_capabilities(libgamma_method_capabilities_t *restrict this, size_t size, int method)
{
+ libgamma_method_capabilities_t caps_;
+ void (*func)(libgamma_method_capabilities_t *restrict);
+
memset(this, 0, sizeof(*this));
switch (method) {
#define X(CONST, CNAME, ...)\
case CONST:\
- libgamma_##CNAME##_method_capabilities(this);\
- return 0;
+ func = libgamma_##CNAME##_method_capabilities;\
+ break;
LIST_AVAILABLE_METHODS(X)
#undef X
default:
return LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD;
}
+
+ if (size == sizeof(caps_)) {
+ func(this);
+ this->struct_version = LIBGAMMA_METHOD_CAPABILITIES_STRUCT_VERSION;
+ } else {
+ func(&caps_);
+ caps_.struct_version = LIBGAMMA_METHOD_CAPABILITIES_STRUCT_VERSION;
+ if (size < sizeof(caps_)) {
+ memcpy(this, &caps_, size);
+ } else {
+ memcpy(this, &caps_, sizeof(caps_));
+ memset(&((char *)this)[size], 0, size - sizeof(caps_));
+ }
+ }
+ this->crtc_information__old = (int32_t)this->crtc_information;
}