/usr/share/doc/uthash-dev/examples/test30.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 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utlist.h"
#define BUFLEN 20
typedef struct el {
char bname[BUFLEN];
struct el *next, *prev;
} el;
int namecmp(void *_a, void *_b) {
el *a = (el*)_a;
el *b = (el*)_b;
return strcmp(a->bname,b->bname);
}
el *head = NULL;
int main(int argc, char *argv[]) {
el *name, *tmp;
char linebuf[BUFLEN];
FILE *file;
if ( (file = fopen( "test11.dat", "r" )) == NULL ) {
perror("can't open: ");
exit(-1);
}
while (fgets(linebuf,BUFLEN,file) != NULL) {
if ( (name = (el*)malloc(sizeof(el))) == NULL) exit(-1);
strncpy(name->bname,linebuf,BUFLEN);
CDL_PREPEND(head, name);
}
CDL_SORT(head, namecmp);
CDL_FOREACH(head,tmp) printf("%s", tmp->bname);
fclose(file);
return 0;
}
|