From 8ec5cef55b0a328992210b42f1186a1402b21169 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 26 Sep 2022 14:43:49 +0000 Subject: ntux_cmd_fspath(): initial implementation and driver integration. --- src/cmds/ntux_cmd_fspath.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/cmds/ntux_cmd_fspath.c (limited to 'src/cmds') diff --git a/src/cmds/ntux_cmd_fspath.c b/src/cmds/ntux_cmd_fspath.c new file mode 100644 index 0000000..9b25062 --- /dev/null +++ b/src/cmds/ntux_cmd_fspath.c @@ -0,0 +1,91 @@ +/***********************************************************/ +/* ntux: native translation und extension */ +/* Copyright (C) 2016--2022 SysDeer Technologies, LLC */ +/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */ +/***********************************************************/ + +#include +#include +#include + +#include +#include +#include + +#include +#include "ntux_driver_impl.h" +#include "ntux_nolibc_impl.h" +#include "ntux_errinfo_impl.h" + +static int ntux_cmd_fspath_ret(void * buf, int ret) +{ + if (buf) + ntux_free(buf); + + return ret; +} + +int ntux_cmd_fspath(const struct ntux_driver_ctx * dctx, const char * dunit) +{ + intptr_t ret; + int fdout; + int fdcwd; + const unsigned char * unit; + char * str; + void * buf = 0; + const size_t bufsize = 0x10000; + + /* init */ + ntux_driver_set_ectx( + dctx,0,dunit); + + unit = (const unsigned char *)dunit; + + /* fdctx */ + fdout = ntux_driver_fdout(dctx); + fdcwd = ntux_driver_fdcwd(dctx); + + /* buffer */ + if (!(buf = ntux_calloc(1,bufsize))) + if (ntux_errno_set(dctx,ENOMEM)) + return ntux_cmd_fspath_ret( + buf, + NTUX_SYSTEM_ERROR(dctx)); + + str = (char *)buf; + + /* root-relative notation? */ + if (dctx->cctx->drvflags & NTUX_DRIVER_RPATH) { + if ((ret = __sys_fs_rpath( + fdcwd, + (const char *)unit, + 0,buf,bufsize)) < 0) + return ntux_cmd_fspath_ret(buf,ret); + + } else if (dctx->cctx->drvflags & NTUX_DRIVER_APATH) { + if ((ret = __sys_fs_apath( + fdcwd, + (const char *)unit, + 0,buf,bufsize)) < 0) + return ntux_cmd_fspath_ret(buf,ret); + } else if (dctx->cctx->drvflags & NTUX_DRIVER_NPATH) { + if ((ret = __sys_fs_npath( + fdcwd, + (const char *)unit, + 0,buf,bufsize)) < 0) + return ntux_cmd_fspath_ret(buf,ret); + + } else if (dctx->cctx->drvflags & NTUX_DRIVER_DPATH) { + if ((ret = __sys_fs_dpath( + fdcwd, + (const char *)unit, + 0,buf,bufsize)) < 0) + return ntux_cmd_fspath_ret(buf,ret); + } + + /* outupt */ + ntux_dprintf(fdout,"%s\n",str); + + /* all done */ + return ntux_cmd_fspath_ret(buf,0); +} -- cgit v1.2.3