linux-sysprog · intermediate · ~15 min
The set-difference primitive that every plugin loader runs.
You're writing the contract for a plugin loader. Each plugin must expose a set of named functions; the loader walks them and reports which are missing.
Implement int count_missing_symbols(const char *plugin_symbols[], int n_plug, const char *required[], int n_req).
plugin_symbols[] is the list of symbols the plugin actually exports;
required[] is the list the loader needs. Return the count of required
symbols not present in plugin_symbols.
dlopen lets a program load a shared library at runtime and resolve named symbols. A defensive plugin loader checks every required symbol BEFORE running any code from the module.
Two arrays of symbol-name strings.
Count of missing.
O(n_req * n_plug). String compare.
#include <stddef.h>
int count_missing_symbols(const char *plugin_symbols[], int n_plug, const char *required[], int n_req) { /* TODO */ (void)plugin_symbols; (void)n_plug; (void)required; (void)n_req; return 0; }
Returning the count present instead of missing.
Empty required (return 0). Empty plugin (return n_req).
O(n_req * n_plug).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.