aboutsummaryrefslogtreecommitdiffstats
path: root/src/xstd.c
blob: 5669e8fea89a835c2d562a7e2ccf88416a064923 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>

void callError(int num)
{
	fprintf(stderr, "lpass: Sorry, there was an error in the program [#%d]\n", num);
	exit(3);
}

void printError(const char *text)
{
	fprintf(stderr, "%s", text);
	exit(4);
}

void easyFork(char *name, char *arguments[])
{
	int pid;
	pid = fork();
	if(pid == -1) callError(100);
	if(pid == 0) { /* new process */
		execvp(name, arguments);
		perror(name);
		exit(4);
	}
	wait(&pid);
}

char *xstrcat(const char *first, const char *second,
	const char *delimiter)
{
	size_t size = sizeof(char) * (strlen(first) + strlen(second) + 1);
	if(delimiter)
		size += sizeof(char) * strlen(delimiter);
	char *res = malloc(size);
	strcpy(res, first);
	if(delimiter)
		strcat(res, delimiter);
	strcat(res, second);
	return res;
}