What's the difference between uci_lookup_package and uci_load?

Take the following code as an example.

struct uci_context *c;
struct uci_package *p;
c = uci_alloc_context();
p = uci_lookup_package(c, "dhcp");
uci_perror(c, "Debug"); // Entry not found
uci_load(c, "dhcp", &p);
uci_perror(c, "Debug"); // Success

By uci_load, it works well.
I'd like to ask the difference between these two functions?
Or how to use uci_lookup_package properly?

The uci_lookup_package() procedure finds the given package among the configurations currently loaded by the uci context while uci_load() loads the given configuration if it is not already loaded yet.

Calling uci_lookup_package() is useful if you need to obtain the package pointer normally returned by uci_load() from a given uci context later in your program flow.


struct uci_context *c;
c = uci_alloc_context();
uci_load(c, "network", NULL);
uci_load(c, "firewall", NULL);
uci_load(c, "wireless", NULL);

// ...

struct uci_package *p;
p = uci_lookup_package(c, "firewall");
if (!p)
    fprintf(stderr, "Package firewall not loaded in context\n");
1 Like

Thanks a lot! =D

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.