/usr/share/doc/uthash-dev/examples/test68.c is in uthash-dev 1.9.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include <stdlib.h>
#include <stdio.h>
#include "utlist.h"
typedef struct el {
int id;
struct el *next, *prev;
} el;
el *headA, *headB = NULL;
int main(int argc, char *argv[]) {
int i;
el els[20], *e, *tmp;
for(i=0;i<20;i++) els[i].id='a'+i;
/* test DL macros */
printf("DL replace elem\n");
DL_APPEND(headA,&els[0]);
DL_APPEND(headA,&els[1]);
DL_APPEND(headA,&els[2]);
DL_APPEND(headA,&els[3]);
DL_FOREACH(headA,e) printf("%c ", e->id); printf("\n");
/* replace head elem */
DL_REPLACE_ELEM(headA, &els[0], &els[4]);
DL_FOREACH(headA,e) printf("%c ", e->id); printf("\n");
DL_REPLACE_ELEM(headA, &els[4], &els[5]);
DL_FOREACH(headA,e) printf("%c ", e->id); printf("\n");
/* replace last elem */
DL_REPLACE_ELEM(headA, &els[3], &els[6]);
DL_FOREACH(headA,e) printf("%c ", e->id); printf("\n");
DL_REPLACE_ELEM(headA, &els[6], &els[7]);
DL_FOREACH(headA,e) printf("%c ", e->id); printf("\n");
/* replace middle elem */
DL_REPLACE_ELEM(headA, &els[1], &els[8]);
DL_REPLACE_ELEM(headA, &els[2], &els[9]);
DL_FOREACH(headA,e) printf("%c ", e->id); printf("\n");
/* replace all just to be sure the list is intact... */
i = 10;
DL_FOREACH_SAFE(headA, e, tmp) {
DL_REPLACE_ELEM(headA, e, &els[i]);
i++;
}
DL_FOREACH(headA,e) printf("%c ", e->id); printf("\n");
/* single elem */
DL_APPEND(headB, &els[18]);
DL_FOREACH(headB,e) printf("%c ", e->id); printf("\n");
DL_REPLACE_ELEM(headB, &els[18], &els[19]);
DL_FOREACH(headB,e) printf("%c ", e->id); printf("\n");
return 0;
}
|