Skip to content

Commit

Permalink
kernel: add GAP_realpath helper
Browse files Browse the repository at this point in the history
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/"
  • Loading branch information
fingolfin committed Feb 5, 2025
1 parent 6800c66 commit 52d1aee
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
Expand Down Expand Up @@ -1080,6 +1081,22 @@ static Obj FuncGAP_chdir(Obj self, Obj path)
return True;
}

/****************************************************************************
**
*F FuncGAP_realpath( <self>, <path> ) . . . . TODO
*/
static Obj FuncGAP_realpath(Obj self, Obj path)
{
RequireStringRep(SELF_NAME, path);
char resolved_path[PATH_MAX];

if (NULL == realpath(CONST_CSTR_STRING(path), resolved_path)) {
SySetErrorNo();
return Fail;
}
return MakeString(resolved_path);
}


/****************************************************************************
**
Expand Down Expand Up @@ -1716,6 +1733,7 @@ static StructGVarFunc GVarFuncs[] = {
GVAR_FUNC_1ARGS(IS_DIR, path),
GVAR_FUNC_0ARGS(GAP_getcwd),
GVAR_FUNC_1ARGS(GAP_chdir, path),
GVAR_FUNC_1ARGS(GAP_realpath, path),
GVAR_FUNC_0ARGS(LastSystemError),
GVAR_FUNC_1ARGS(IsExistingFile, filename),
GVAR_FUNC_1ARGS(IsReadableFile, filename),
Expand Down

0 comments on commit 52d1aee

Please sign in to comment.