summaryrefslogtreecommitdiff
path: root/src/catfile.c
blob: 56ee0a98097b9eb39634023e190aba36c5411167 (plain)
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
#include <stdlib.h>
#include <string.h>
#include "fileserv.h"

char *
catfile_n(char const *dir, size_t len, char const *file)
{
	size_t sz;
	char *p;
	
	sz = len;
	if (sz > 0 && dir[sz-1] != '/')
		sz++;
	if (*file == '/')
		file++;
	sz += strlen(file);
	p = xmalloc(sz + 1);
	memcpy(p, dir, len);
	if (p[len-1] != '/')
		p[len++] = '/';
	strcpy(p + len, file);
	return p;
}

char *
catfile(char const *dir, char const *file)
{
	return catfile_n(dir, strlen(dir), file);
}

Return to:

Send suggestions and report system problems to the System administrator.