-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
73 lines (57 loc) · 1.17 KB
/
util.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2013, Dowhaus Systems, LLC
// All rights reserved.
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "redside.h"
static char *home = NULL;
static size_t homeLen;
void
progError(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
fflush(stdout);
va_end(ap);
exit(1);
}
char *
mkName(char *n)
{
char *name;
if (home == NULL) {
home = getenv("HOME");
if (home == NULL)
progError("HOME: cannot get environment value\n");
homeLen = strlen(home);
}
name = malloc(homeLen + strlen(n) + 2);
if (name == NULL)
progError("cannot allocate memory\n");
strcpy(name, home);
strcat(name, "/");
strcat(name, n);
return(name);
}
char *
mkName2(char *n, char *n1)
{
char *name;
if (home == NULL) {
home = getenv("HOME");
if (home == NULL)
progError("HOME: cannot get environment value\n");
homeLen = strlen(home);
}
name = malloc(homeLen + strlen(n) + strlen(n1) + 3);
if (name == NULL)
progError("cannot allocate memory\n");
strcpy(name, home);
strcat(name, "/");
strcat(name, n);
strcat(name, "/");
strcat(name, n1);
return(name);
}