使用C API来操作UCI

Compiling UCI as stand alone with an example using the C API

1. Example code using the UCI C API
~/uci/main.c

#include <stdio.h>
#include <string.h>
#include <uci.h>
#include <stdlib.h>

int main (int argc, char **argv)
{
  struct uci_context *c;
  struct uci_ptr p;
  char *a = strdup ("wireless.@wifi-iface[0].ssid");

  c = uci_alloc_context ();
  if (uci_lookup_ptr (c, &p, a, true) != UCI_OK)
    {
      uci_perror (c, "XXX");
      return 1;
    }

  printf("%s\n", p.o->v.string);
  uci_free_context (c);
  free (a);
  return 0;
}

2. Compile the example

cc -I$HOME/usr/include -L$HOME/usr/lib main.c -luci -o uci-test

3. Run the compiled example binary

export LD_LIBRARY_PATH=$HOME/usr/lib
./uci-test
XXX: Entry not found

 

这样应用可以:

posted @ 2015-08-24 18:48  小青年%  阅读(388)  评论(0)    收藏  举报