From bd97dc0134d23f2d8373741b4375504215d70348 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 15 Nov 2019 01:07:38 +0300 Subject: [PATCH] os: realpath potential fix --- vlib/builtin/cfns.v | 2 ++ vlib/os/os.v | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/vlib/builtin/cfns.v b/vlib/builtin/cfns.v index 7ce581cbfb..da2c89f9cc 100644 --- a/vlib/builtin/cfns.v +++ b/vlib/builtin/cfns.v @@ -25,6 +25,8 @@ fn backtrace_symbols_fd(voidptr, int, int) // fn proc_pidpath(int, voidptr, int) int +fn C.realpath(byteptr, byteptr) &char + // Windows diff --git a/vlib/os/os.v b/vlib/os/os.v index 0b3a3cf0e3..f9e0794fce 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -833,9 +833,15 @@ pub fn realpath(fpath string) string { res = int( C._fullpath( fullpath, fpath.str, MAX_PATH ) ) } $else{ - // here we want an int==0 if realpath failed, in which case - // realpath would return NULL, and !isnil(NULL) would be false==0 - res = int( !isnil(C.realpath( fpath.str, fullpath )) ) + if fpath.len != strlen(fpath.str) { + l := strlen(fpath.str) + println('FIXME realpath diff len $fpath.len strlen=$l') + } + ret := C.realpath(fpath.str, fullpath) + if ret == 0 { + return fpath + } + return string(fullpath) } if res != 0 { return string(fullpath, vstrlen(fullpath))