Subversion Repositories SvarDOS

Rev

Rev 219 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
219 mateuszvis 1
/*
236 mateuszvis 2
 * This file is part of pkginst (SvarDOS).
219 mateuszvis 3
 *
236 mateuszvis 4
 * Reads environment variables that will be used by pkginst.
219 mateuszvis 5
 * Returns 0 on success, non-zero otherwise.
6
 *
236 mateuszvis 7
 * Copyright (C) 2012-2021 Mateusz Viste
219 mateuszvis 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
 
236 mateuszvis 17
int readenv(char **dosdir, char *cfgfile, int cfgfilemaxlen) {
219 mateuszvis 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
  /* look for the FDNPKG.CFG env. variable */
29
  cfg = getenv("FDNPKG.CFG");
30
  cfgfilemaxlen -= 1; /* make room for the null terminator */
31
  if (cfg != NULL) {
32
    snprintf(cfgfile, cfgfilemaxlen, "%s", cfg);
33
  } else { /* not set, so fallback to hardcoded location */
34
    snprintf(cfgfile, cfgfilemaxlen, "%s\\bin\\fdnpkg.cfg", *dosdir);
35
  }
36
 
37
  return(0);
38
}