1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: support v -watch run (#9577)

This commit is contained in:
Delyan Angelov
2021-04-04 17:05:06 +03:00
committed by GitHub
parent 82f3ca2d55
commit c698fa1a58
16 changed files with 701 additions and 78 deletions

View File

@@ -4,10 +4,16 @@ module os
// close filedescriptor
pub fn fd_close(fd int) int {
if fd == -1 {
return 0
}
return C.close(fd)
}
pub fn fd_write(fd int, s string) {
if fd == -1 {
return
}
mut sp := s.str
mut remaining := s.len
for remaining > 0 {
@@ -23,6 +29,9 @@ pub fn fd_write(fd int, s string) {
// read from filedescriptor, block until data
pub fn fd_slurp(fd int) []string {
mut res := []string{}
if fd == -1 {
return res
}
for {
s, b := fd_read(fd, 4096)
if b <= 0 {
@@ -36,6 +45,9 @@ pub fn fd_slurp(fd int) []string {
// read from filedescriptor, don't block
// return [bytestring,nrbytes]
pub fn fd_read(fd int, maxbytes int) (string, int) {
if fd == -1 {
return '', 0
}
unsafe {
mut buf := malloc(maxbytes)
nbytes := C.read(fd, buf, maxbytes)