Files
mars-tinyldap/strduptab.c
leitner 0cc9c5b1ec don't build strstorage and strduptab (tinyldap doesn't use it anymore)
add comments in strstorage.c and strduptab.c that they are obsolete
2024-02-02 10:54:25 +00:00

35 lines
801 B
C

/* This is no longer used in tinyldap (see mduptab.h).
* The sources are here for historic reference. */
#include <stdlib.h>
#include <libowfat/str.h>
#include "strduptab.h"
#include "strstorage.h"
#include <libowfat/str.h>
#define PAGESIZE 4096
const char* strduptab_add(struct stringduptable* t,const char* s) {
size_t i;
for (i=0; i<t->n; ++i)
if (str_equal(t->s[i],s))
return t->s[i];
if (t->n>=t->a) {
const char** x;
size_t a=t->a*2; // this can not overflow
// t->s is t->a*sizeof(char*), which is always at least *2
if (!a) a=1024;
if (!(x=reallocarray((char**)t->s,a,sizeof(char*))))
return 0;
t->a=a;
t->s=x;
}
{
const char* x=strstorage_add(s,str_len(s)+1);
if (!x) return 0;
s=x;
}
t->s[t->n]=s; ++t->n;
return s;
}