Skip to content

Commit ddca1be

Browse files
committed
kernel: add SyDefaultRootPath
The main motivation here is to avoid calling `SySetGapRootPath` in `main` -- instead we want to defer this until just before we parse the command line arguments specifying root paths. This will in the future allow us to switch `SySetGapRootPath` to using GAP objects.
1 parent e64351f commit ddca1be

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/main.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern int realmain(int argc, const char * argv[]);
4141

4242
static void SetupInitialGapRoot(const char * argv0)
4343
{
44-
SySetGapRootPath(SYS_DEFAULT_PATHS);
44+
gap_strlcpy(SyDefaultRootPath, SYS_DEFAULT_PATHS, sizeof(SyDefaultRootPath));
4545
}
4646

4747
#else
@@ -165,19 +165,14 @@ static void SySetInitialGapRootPaths(const char * GAPExecLocation)
165165
strxcat(initgbuf, "lib/init.g", sizeof(initgbuf));
166166

167167
if (SyIsReadableFile(initgbuf) == 0) {
168-
SySetGapRootPath(pathbuf);
168+
gap_strlcpy(SyDefaultRootPath, pathbuf, sizeof(SyDefaultRootPath));
169169
// escape from loop
170170
return;
171171
}
172172
// try up a directory level
173173
strxcat(pathbuf, "../", sizeof(pathbuf));
174174
}
175175
}
176-
177-
// Set GAP root path to current directory, if we have no other
178-
// idea, and for backwards compatibility.
179-
// Note that GAPExecLocation must always end with a slash.
180-
SySetGapRootPath("./");
181176
}
182177

183178
static void SetupInitialGapRoot(const char * argv0)

src/sysroots.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
#include <stdlib.h>
2222

2323

24+
/****************************************************************************
25+
**
26+
*V SyDefaultRootPath
27+
**
28+
** Default initial root path. Default is the current directory, if we have
29+
** no other idea, for backwards compatibility.
30+
*/
31+
char SyDefaultRootPath[GAP_PATH_MAX] = "./";
32+
33+
2434
/****************************************************************************
2535
**
2636
*V SyGapRootPaths . . . . . . . . . . . . . . . . . . . array of root paths

src/sysroots.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
#define GAP_SYSROOTS_H
1414

1515
#include "common.h"
16+
#include "system.h"
17+
18+
19+
/****************************************************************************
20+
**
21+
*V SyDefaultRootPath
22+
**
23+
** Default initial root path. Default is the current directory, if we have
24+
** no other idea, for backwards compatibility.
25+
*/
26+
extern char SyDefaultRootPath[GAP_PATH_MAX];
1627

1728
#include <stddef.h>
1829

src/system.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ void InitSystem(int argc, const char * argv[], BOOL handleSignals)
710710

711711
void InitRootPaths(int argc, const char * argv[])
712712
{
713+
SySetGapRootPath(SyDefaultRootPath);
714+
713715
// second stage of command line options parsing: handle root paths
714716
ParseCommandLineOptions(argc, argv, 1);
715717

0 commit comments

Comments
 (0)