From a8fe7bce0ea33f71485cf8c2e4c8330831c849ce Mon Sep 17 00:00:00 2001 From: Joursoir Date: Fri, 26 Feb 2021 13:36:16 +0000 Subject: rename handerror to xstd; create and use some routines --- src/xstd.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/xstd.c (limited to 'src/xstd.c') diff --git a/src/xstd.c b/src/xstd.c new file mode 100644 index 0000000..5669e8f --- /dev/null +++ b/src/xstd.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include + +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; +} + -- cgit v1.2.3-18-g5258