"Fossies" - the Fresh Open Source Software Archive

Member "geoipupdate-3.1.1/bin/edition_s.c" (12 Jan 2018, 1205 Bytes) of package /linux/misc/geoipupdate-3.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "edition_s.c" see the Fossies "Dox" file reference documentation.

    1 
    2 #include "geoipupdate.h"
    3 #include <errno.h>
    4 #include <stdlib.h>
    5 #include <string.h>
    6 
    7 int edition_count(geoipupdate_s *gu) {
    8     int cnt = 0;
    9     for (edition_s *p = gu->license.first; p; p = p->next) {
   10         cnt++;
   11     }
   12     return cnt;
   13 }
   14 
   15 void edition_delete_all(geoipupdate_s *gu) {
   16     edition_s *next, *current;
   17 
   18     for (next = gu->license.first; (current = next);) {
   19         next = current->next;
   20         edition_delete(current);
   21     }
   22 }
   23 
   24 void edition_insert_once(geoipupdate_s *gu, const char *edition_id) {
   25     edition_s **next = &gu->license.first;
   26     for (; *next; next = &(*next)->next) {
   27         if (strcmp((*next)->edition_id, edition_id) == 0) {
   28             return;
   29         }
   30     }
   31     *next = edition_new(edition_id);
   32     say_if(gu->verbose, "Insert edition_id %s\n", edition_id);
   33 }
   34 
   35 edition_s *edition_new(const char *edition_id) {
   36     edition_s *p = xcalloc(1, sizeof(edition_s));
   37     p->edition_id = strdup(edition_id);
   38     exit_if(NULL == p->edition_id,
   39             "Unable to allocate memory for edition ID: %s\n",
   40             strerror(errno));
   41     p->next = NULL;
   42     return p;
   43 }
   44 
   45 void edition_delete(edition_s *p) {
   46     if (p) {
   47         free(p->edition_id);
   48     }
   49     free(p);
   50 }