os: fix compiler warnings when just importing os

pull/3659/head
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
/hello_world
/hanoi
/json
/links_scraper
/log

View File

@ -119,13 +119,14 @@ pub fn read_file(path string) ?string {
if isnil(fp) {
return error('failed to open file "$path"')
}
defer { C.fclose(fp) }
C.fseek(fp, 0, C.SEEK_END)
fsize := C.ftell(fp)
// C.fseek(fp, 0, SEEK_SET) // same as `C.rewind(fp)` below
C.rewind(fp)
mut str := malloc(fsize + 1)
mut str := &byte(0)
unsafe { str = malloc(fsize + 1) }
C.fread(str, fsize, 1, fp)
C.fclose(fp)
str[fsize] = 0
return string(str,fsize)
}
@ -707,13 +708,15 @@ pub fn get_raw_line() string {
}
return string(buf, offset)
} $else {
max := size_t(256)
buf := charptr(malloc(int(max)))
max := size_t(0)
mut buf := byteptr(0)
nr_chars := C.getline(&buf, &max, stdin)
if nr_chars == 0 {
defer { unsafe{ free(buf) } }
if nr_chars == 0 || nr_chars == -1 {
return ''
}
return string(byteptr(buf),nr_chars)
res := tos_clone( buf )
return res
}
}