From: fennecdjay Date: Tue, 18 Jun 2019 23:16:00 +0000 (+0200) Subject: :art: Define dirname X-Git-Tag: nightly~2438 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=05ad2c0b6c6e278e16b43befa19066cc48a3a1c1;p=gwion.git :art: Define dirname --- 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)