1
0
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:
Delyan Angelov 2020-02-05 12:23:49 +02:00 committed by GitHub
parent 06b5f43e48
commit 1618596218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

1
examples/.gitignore vendored
View File

@ -1,5 +1,6 @@
/cli /cli
/hello_world /hello_world
/hanoi
/json /json
/links_scraper /links_scraper
/log /log

View File

@ -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
} }
} }