httpdirfs/src/util.c

21 lines
431 B
C
Raw Normal View History

2019-04-21 00:46:08 +02:00
#include "util.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *strndupcat(const char *a, const char *b, int n)
{
int na = strnlen(a, n/2);
int nb = strnlen(b, n/2);
int nc = na + nb + 1;
char *c = calloc(nc, sizeof(char));
if (!c) {
fprintf(stderr, "strndupcat(): calloc failure!\n");
exit(EXIT_FAILURE);
}
strncpy(c, a, na);
strncat(c, b, nb);
return c;
}