UCI C API - How to work with list options
<p>Using UCI we can retrieve entire lists with the following command:</p>

<pre><code>$ uci get system.ntp.server
</code></pre>

<p>This would read the kind of configuration below:</p>

<pre><code>config system
    option hostname 'OpenWrt'
    option timezone 'UTC'

config timeserver 'ntp'
    list server '0.openwrt.pool.ntp.org'
    list server '1.openwrt.pool.ntp.org'
    list server '2.openwrt.pool.ntp.org'
    list server '3.openwrt.pool.ntp.org'
    option enabled '1'
    option enable_server '0'
</code></pre>

<p>That returns all the ntp servers in one long string fine.</p>

<pre><code>0.openwrt.pool.ntp.org 1.openwrt.pool.ntp.org 2.openwrt.pool.ntp.org 3.openwrt.pool.ntp.org
</code></pre>

<p>I wish to achieve the same (or equivalent) using the C api.</p>

<p>I put together the following code:</p>

<pre><code>#include &lt;uci.h&gt;
#include &lt;string.h&gt;
void main()
{
    //char path[] = "system.ntp.enabled";
    char path[] = "system.ntp.server";
    char buffer[80];
    get_config_entry(path, &amp;buffer);
    printf("%s\n", buffer);

}

int get_config_entry (char *path, char *buffer)
{
  struct uci_context *c;
  struct uci_ptr ptr;

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

  strcpy(buffer, ptr.o-&gt;v.string);
  uci_free_context (c);
  return 0;
}
</code></pre>

<p>Running this just returns garbage in the output string.</p>

<p>How should I deal with list content using UCI C API?</p>