os.read_file(): replace C code with V, return ?string, handle errors

everywhere
This commit is contained in:
Alexander Medvednikov 2019-06-26 10:57:13 +02:00
parent b00a47be66
commit 8417fec5dc
3 changed files with 30 additions and 17 deletions

View file

@ -762,13 +762,19 @@ fn new_v(args[]string) *V {
// Location of all vlib files
mut lang_dir = ''
// First try fetching it from VROOT if it's defined
for { // TODO tmp hack for optionals
vroot_path := TmpPath + '/VROOT'
if os.file_exists(vroot_path) {
vroot := os.read_file(vroot_path).trim_space()
mut vroot := os.read_file(vroot_path) or {
break
}
vroot=vroot.trim_space()
if os.dir_exists(vroot) && os.dir_exists(vroot + '/builtin') {
lang_dir = vroot
}
}
break
}
// no "~/.vlang/VROOT" file, so the user must be running V for the first
// time.
if lang_dir == '' {