os: move C struct declarations in their own _default.c.v files (#12268)

pull/12271/head
Delyan Angelov 2021-10-22 17:08:08 +03:00 committed by GitHub
parent 0401b5ece0
commit eed94c727c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 78 additions and 55 deletions

View File

@ -70,7 +70,7 @@ fn (ctx Context) write_file_or_print(file string) {
// generate ast json file and c source code file
fn (ctx Context) watch_for_changes(file string) {
println('start watching...')
mut timestamp := 0
mut timestamp := i64(0)
for {
new_timestamp := os.file_last_mod_unix(file)
if timestamp != new_timestamp {

View File

@ -61,7 +61,7 @@ fn get_scan_timeout_seconds() int {
struct VFileStat {
path string
mtime int
mtime i64
}
[unsafe]

View File

@ -144,7 +144,11 @@ fn C.sleep(seconds u32) u32
[trusted]
fn C.usleep(usec u32) int
fn C.opendir(&char) voidptr
[typedef]
struct C.DIR {
}
fn C.opendir(&char) &C.DIR
fn C.closedir(dirp &C.DIR) int

View File

@ -7,10 +7,6 @@ pub const (
args = []string{}
)
struct C.dirent {
d_name [256]char
}
fn C.readdir(voidptr) &C.dirent
fn C.readlink(pathname &char, buf &char, bufsiz usize) int
@ -41,36 +37,6 @@ fn C.ftruncate(voidptr, u64) int
fn C._chsize_s(voidptr, u64) int
// fn C.proc_pidpath(int, byteptr, int) int
struct C.stat {
st_size u64
st_mode u32
st_mtime int
}
struct C.__stat64 {
st_size u64
st_mode u32
st_mtime int
}
struct C.DIR {
}
type FN_SA_Handler = fn (sig int)
struct C.sigaction {
mut:
sa_mask int
sa_sigaction int
sa_flags int
sa_handler FN_SA_Handler
}
struct C.dirent {
d_name &byte
}
// read_bytes returns all bytes read from file in `path`.
[manualfree]
pub fn read_bytes(path string) ?[]byte {
@ -890,12 +856,12 @@ pub fn wait() int {
}
// file_last_mod_unix returns the "last modified" time stamp of file in `path`.
pub fn file_last_mod_unix(path string) int {
pub fn file_last_mod_unix(path string) i64 {
attr := C.stat{}
// # struct stat attr;
unsafe { C.stat(&char(path.str), &attr) }
// # stat(path.str, &attr);
return attr.st_mtime
return i64(attr.st_mtime)
// # return attr.st_mtime ;
}

View File

@ -43,20 +43,6 @@ pub const (
s_ixoth = 0o0001 // Execute by others
)
struct C.utsname {
mut:
sysname &char
nodename &char
release &char
version &char
machine &char
}
struct C.utimbuf {
actime int
modtime int
}
fn C.utime(&char, voidptr) int
fn C.uname(name voidptr) int

View File

@ -0,0 +1,5 @@
module os
struct C.dirent {
d_name [256]char
}

View File

@ -0,0 +1,11 @@
module os
pub type FN_SA_Handler = fn (sig int)
struct C.sigaction {
mut:
sa_mask int
sa_sigaction int
sa_flags int
sa_handler FN_SA_Handler
}

View File

@ -0,0 +1,13 @@
module os
struct C.stat {
st_size u64
st_mode u32
st_mtime int
}
struct C.__stat64 {
st_size u64
st_mode u32
st_mtime int
}

View File

@ -0,0 +1,23 @@
module os
struct C.stat {
st_dev u64 // 8
st_ino u64 // 8
st_nlink u64 // 8
st_mode u32 // 4
st_uid u32 // 4
st_gid u32 // 4
st_rdev u64 // 8
st_size u64 // 8
st_blksize u64 // 8
st_blocks u64 // 8
st_atime i64 // 8
st_mtime i64 // 8
st_ctime i64 // 8
}
struct C.__stat64 {
st_mode u32
st_size u64
st_mtime u64
}

View File

@ -0,0 +1,15 @@
module os
struct C.utsname {
mut:
sysname &char
nodename &char
release &char
version &char
machine &char
}
struct C.utimbuf {
actime int
modtime int
}

View File

@ -22,7 +22,7 @@ pub mut:
reloads int // how many times a reloading was tried
reloads_ok int // how many times the reloads succeeded
reload_time_ms int // how much time the last reload took (compilation + loading)
last_mod_ts int // a timestamp for when the original was last changed
last_mod_ts i64 // a timestamp for when the original was last changed
recheck_period_ms int = 100 // how often do you want to check for changes
cb_recheck FNLiveReloadCB = voidptr(0) // executed periodically
cb_compile_failed FNLiveReloadCB = voidptr(0) // executed when a reload compilation failed

View File

@ -186,7 +186,7 @@ pub fn should_recompile_tool(vexe string, tool_source string, tool_name string,
if os.is_dir(tool_source) {
source_files := os.walk_ext(tool_source, '.v')
mut newest_sfile := ''
mut newest_sfile_mtime := 0
mut newest_sfile_mtime := i64(0)
for sfile in source_files {
mtime := os.file_last_mod_unix(sfile)
if mtime > newest_sfile_mtime {