219 |
mateuszvis |
1 |
/*
|
|
|
2 |
* This file is part of FDNPKG.
|
|
|
3 |
*
|
|
|
4 |
* Reads environment variables that will be used by FDNPKG and FDINST.
|
|
|
5 |
* Returns 0 on success, non-zero otherwise.
|
|
|
6 |
*
|
|
|
7 |
* Copyright (C) 2012-2016 Mateusz Viste
|
|
|
8 |
*/
|
|
|
9 |
|
|
|
10 |
#include <stdio.h> /* snprintf() */
|
|
|
11 |
#include <stdlib.h> /* getenv() */
|
|
|
12 |
#include "kprintf.h" /* kprintf(), kputs() */
|
|
|
13 |
|
|
|
14 |
#include "readenv.h"
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
int readenv(char **dosdir, char **tempdir, char *cfgfile, int cfgfilemaxlen) {
|
|
|
18 |
char *cfg;
|
|
|
19 |
|
|
|
20 |
/* check if %DOSDIR% is set, and retrieve it */
|
|
|
21 |
*dosdir = getenv("DOSDIR");
|
|
|
22 |
if (*dosdir == NULL) {
|
|
|
23 |
kitten_puts(2, 2, "%DOSDIR% not set! You should make it point to the FreeDOS main directory.");
|
|
|
24 |
kitten_puts(2, 3, "Example: SET DOSDIR=C:\\FDOS");
|
|
|
25 |
return(-1);
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
/* check if %TEMP% is set, and retrieve it */
|
|
|
29 |
*tempdir = getenv("TEMP");
|
|
|
30 |
if (*tempdir == NULL) {
|
|
|
31 |
kitten_puts(2, 0, "%TEMP% not set! You should make it point to a writeable directory.");
|
|
|
32 |
kitten_puts(2, 1, "Example: SET TEMP=C:\\TEMP");
|
|
|
33 |
return(-2);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
/* look for the FDNPKG.CFG env. variable */
|
|
|
37 |
cfg = getenv("FDNPKG.CFG");
|
|
|
38 |
cfgfilemaxlen -= 1; /* make room for the null terminator */
|
|
|
39 |
if (cfg != NULL) {
|
|
|
40 |
snprintf(cfgfile, cfgfilemaxlen, "%s", cfg);
|
|
|
41 |
} else { /* not set, so fallback to hardcoded location */
|
|
|
42 |
snprintf(cfgfile, cfgfilemaxlen, "%s\\bin\\fdnpkg.cfg", *dosdir);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
return(0);
|
|
|
46 |
}
|