]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/dlist.c
Tweak version date
[bacula/bacula] / bacula / src / lib / dlist.c
index 1e0034604712bcf202e0b1552cabc78de72a02a8..2d4e507c49c1ccf8c4dea61aea2fabe77f04f0b6 100644 (file)
@@ -1,26 +1,26 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2003-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2003-2011 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
@@ -33,8 +33,6 @@
  *
  *   Kern Sibbald, July MMIII
  *
- *   Version $Id$
- *
  */
 
 #include "bacula.h"
@@ -79,7 +77,7 @@ void dlist::prepend(void *item)
 
 void dlist::insert_before(void *item, void *where)
 {
-   dlink *where_link = (dlink *)((char *)where+loffset);
+   dlink *where_link = get_link(where);
 
    set_next(item, where);
    set_prev(item, where_link->prev);
@@ -96,7 +94,7 @@ void dlist::insert_before(void *item, void *where)
 
 void dlist::insert_after(void *item, void *where)
 {
-   dlink *where_link = (dlink *)((char *)where+loffset);
+   dlink *where_link = get_link(where);
 
    set_next(item, where_link->next);
    set_prev(item, where);
@@ -290,7 +288,7 @@ void *dlist::binary_search(void *item, int compare(void *item1, void *item2))
 void dlist::remove(void *item)
 {
    void *xitem;
-   dlink *ilink = (dlink *)(((char *)item)+loffset);   /* item's link */
+   dlink *ilink = get_link(item);   /* item's link */
    if (item == head) {
       head = ilink->next;
       if (head) {
@@ -316,20 +314,20 @@ void dlist::remove(void *item)
    }
 }
 
-void * dlist::next(const void *item) const
+void *dlist::next(void *item)
 {
    if (item == NULL) {
       return head;
    }
-   return ((dlink *)(((char *)item)+loffset))->next;
+   return get_next(item);
 }
 
-void * dlist::prev(const void *item) const
+void *dlist::prev(void *item)
 {
    if (item == NULL) {
       return tail;
    }
-   return ((dlink *)(((char *)item)+loffset))->prev;
+   return get_prev(item);
 }
 
 
@@ -337,7 +335,7 @@ void * dlist::prev(const void *item) const
 void dlist::destroy()
 {
    for (void *n=head; n; ) {
-      void *ni = ((dlink *)(((char *)n)+loffset))->next;
+      void *ni = get_next(n);
       free(n);
       n = ni;
    }
@@ -355,8 +353,8 @@ dlistString *new_dlistString(const char *str)
 dlistString *new_dlistString(const char *str, int len)
 {
    dlistString *node;
-   node = (dlistString *)malloc(sizeof(dlistString) + len);
-   bstrncpy(node->c_str(), str, len);
+   node = (dlistString *)malloc(sizeof(dlink) + len +1);
+   bstrncpy(node->c_str(), str, len + 1);
    return node;
 }
 
@@ -521,7 +519,7 @@ int main()
     *  it.
     */
    dlist chain;
-   dlistString *node;
+   chain.append(new_dlistString("This is a long test line"));
 #define CNT 26
    printf("append %d dlistString items\n", CNT*CNT*CNT);
    strcpy(buf, "ZZZ");
@@ -533,8 +531,7 @@ int main()
             if ((count & 0x3FF) == 0) {
                Dmsg1(000, "At %d\n", count);
             }
-            node = new_dlistString(buf);
-            chain.append(node);
+            chain.append(new_dlistString(buf));
             buf[1]--;
          }
          buf[1] = 'Z';
@@ -544,13 +541,14 @@ int main()
       buf[0]--;
    }
    printf("dlistString items appended, walking chain\n");
+   dlistString *node;
    foreach_dlist(node, &chain) {
       printf("%s\n", node->c_str());
    }
    printf("destroy dlistString chain\n");
    chain.destroy();
 
-   sm_dump(false);
+   sm_dump(false);    /* unit test */
 
 }
 #endif