From 05ad2c0b6c6e278e16b43befa19066cc48a3a1c1 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 19 Jun 2019 01:16:00 +0200 Subject: [PATCH] :art: Define dirname --- src/lib/shred.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/shred.c b/src/lib/shred.c index 25a24394..05de76fe 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -1,5 +1,4 @@ #include -#include #include "gwion_util.h" #include "gwion_ast.h" #include "gwion_thread.h" @@ -96,6 +95,12 @@ static MFUN(shred_arg) { *(m_uint*)RETURN = 0; } +#ifndef BUILD_ON_WINDOWS +#define PATH_CHR '/' +#else +#define PATH_CHR '\\' +#endif + #define describe_path_and_dir(name, src) \ static MFUN(shred##name##_path) { \ const VM_Shred s = ME(o); \ @@ -108,7 +113,15 @@ static MFUN(shred##name##_dir) { \ const size_t len = strlen(str); \ char c[len + 1]; \ strcpy(c, str); \ - *(m_uint*)RETURN = (m_uint)new_string(shred->info->mp, shred, dirname(c)); \ + size_t sz = len;\ + while(sz) {\ + if(c[sz] == PATH_CHR) {\ + c[sz] = 0;\ + break;\ + }\ + --sz;\ + }\ + *(m_uint*)RETURN = (m_uint)new_string(shred->info->mp, shred, c); \ } describe_path_and_dir(, s->info->name) describe_path_and_dir(_code, s->code->name) -- 2.43.0