summaryrefslogtreecommitdiff
path: root/src/base/homeDirector.c
blob: 0533d2ed7a5fb47c4639825ff404b602e0182f3d (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

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <sys/stat.h>

#include "base/main.h"
#include "base/homeDirector.h"

static char homeDirector[STR_PATH_SIZE];

void createHomeDirector()
{
	char *envHome;

	envHome = getenv("HOME");

	if( envHome == NULL )
	{
		fprintf(stderr, "Environment HOME not found !\n");
		exit(0);
	}

	sprintf(homeDirector, "%s/%s", envHome, HOMEDIRECTOR_NAME);

	if ( access(homeDirector, F_OK) != 0 )
	{
		printf("Create home director %s\n", homeDirector);

		if( mkdir(homeDirector, 0755) != 0 )
		{
			fprintf(stderr, "Can't create home directory!\n");
			exit(0);
		}
	}
}

char *getHomeDirector()
{
	return homeDirector;
}