Skip to content

Commit c37d510

Browse files
authored
kernel: add GAP_realpath helper (#5927)
Some usage examples: gap> GAP_getcwd(); "/Users/mhorn/Projekte/GAP/gap" gap> GAP_realpath("."); "/Users/mhorn/Projekte/GAP/gap" gap> GAP_realpath("../.."); "/Users/mhorn/Projekte/"
1 parent 0a4774e commit c37d510

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/streams.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include <dirent.h>
4444
#include <errno.h>
45+
#include <limits.h>
4546
#include <stdlib.h>
4647
#include <stdio.h>
4748
#include <time.h>
@@ -1080,6 +1081,22 @@ static Obj FuncGAP_chdir(Obj self, Obj path)
10801081
return True;
10811082
}
10821083

1084+
/****************************************************************************
1085+
**
1086+
*F FuncGAP_realpath( <self>, <path> ) . . . . TODO
1087+
*/
1088+
static Obj FuncGAP_realpath(Obj self, Obj path)
1089+
{
1090+
RequireStringRep(SELF_NAME, path);
1091+
char resolved_path[PATH_MAX];
1092+
1093+
if (NULL == realpath(CONST_CSTR_STRING(path), resolved_path)) {
1094+
SySetErrorNo();
1095+
return Fail;
1096+
}
1097+
return MakeString(resolved_path);
1098+
}
1099+
10831100

10841101
/****************************************************************************
10851102
**
@@ -1716,6 +1733,7 @@ static StructGVarFunc GVarFuncs[] = {
17161733
GVAR_FUNC_1ARGS(IS_DIR, path),
17171734
GVAR_FUNC_0ARGS(GAP_getcwd),
17181735
GVAR_FUNC_1ARGS(GAP_chdir, path),
1736+
GVAR_FUNC_1ARGS(GAP_realpath, path),
17191737
GVAR_FUNC_0ARGS(LastSystemError),
17201738
GVAR_FUNC_1ARGS(IsExistingFile, filename),
17211739
GVAR_FUNC_1ARGS(IsReadableFile, filename),

0 commit comments

Comments
 (0)