mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: fix compiler warnings when just importing os
This commit is contained in:
parent
06b5f43e48
commit
1618596218
1
examples/.gitignore
vendored
1
examples/.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
/cli
|
/cli
|
||||||
/hello_world
|
/hello_world
|
||||||
|
/hanoi
|
||||||
/json
|
/json
|
||||||
/links_scraper
|
/links_scraper
|
||||||
/log
|
/log
|
||||||
|
15
vlib/os/os.v
15
vlib/os/os.v
@ -119,13 +119,14 @@ pub fn read_file(path string) ?string {
|
|||||||
if isnil(fp) {
|
if isnil(fp) {
|
||||||
return error('failed to open file "$path"')
|
return error('failed to open file "$path"')
|
||||||
}
|
}
|
||||||
|
defer { C.fclose(fp) }
|
||||||
C.fseek(fp, 0, C.SEEK_END)
|
C.fseek(fp, 0, C.SEEK_END)
|
||||||
fsize := C.ftell(fp)
|
fsize := C.ftell(fp)
|
||||||
// C.fseek(fp, 0, SEEK_SET) // same as `C.rewind(fp)` below
|
// C.fseek(fp, 0, SEEK_SET) // same as `C.rewind(fp)` below
|
||||||
C.rewind(fp)
|
C.rewind(fp)
|
||||||
mut str := malloc(fsize + 1)
|
mut str := &byte(0)
|
||||||
|
unsafe { str = malloc(fsize + 1) }
|
||||||
C.fread(str, fsize, 1, fp)
|
C.fread(str, fsize, 1, fp)
|
||||||
C.fclose(fp)
|
|
||||||
str[fsize] = 0
|
str[fsize] = 0
|
||||||
return string(str,fsize)
|
return string(str,fsize)
|
||||||
}
|
}
|
||||||
@ -707,13 +708,15 @@ pub fn get_raw_line() string {
|
|||||||
}
|
}
|
||||||
return string(buf, offset)
|
return string(buf, offset)
|
||||||
} $else {
|
} $else {
|
||||||
max := size_t(256)
|
max := size_t(0)
|
||||||
buf := charptr(malloc(int(max)))
|
mut buf := byteptr(0)
|
||||||
nr_chars := C.getline(&buf, &max, stdin)
|
nr_chars := C.getline(&buf, &max, stdin)
|
||||||
if nr_chars == 0 {
|
defer { unsafe{ free(buf) } }
|
||||||
|
if nr_chars == 0 || nr_chars == -1 {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
return string(byteptr(buf),nr_chars)
|
res := tos_clone( buf )
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user