Skip to content

Commit eed94c7

Browse files
authored
os: move C struct declarations in their own _default.c.v files (#12268)
1 parent 0401b5e commit eed94c7

12 files changed

+78
-55
lines changed

cmd/tools/vast/vast.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn (ctx Context) write_file_or_print(file string) {
7070
// generate ast json file and c source code file
7171
fn (ctx Context) watch_for_changes(file string) {
7272
println('start watching...')
73-
mut timestamp := 0
73+
mut timestamp := i64(0)
7474
for {
7575
new_timestamp := os.file_last_mod_unix(file)
7676
if timestamp != new_timestamp {

cmd/tools/vwatch.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn get_scan_timeout_seconds() int {
6161

6262
struct VFileStat {
6363
path string
64-
mtime int
64+
mtime i64
6565
}
6666

6767
[unsafe]

vlib/builtin/cfns.c.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ fn C.sleep(seconds u32) u32
144144
[trusted]
145145
fn C.usleep(usec u32) int
146146

147-
fn C.opendir(&char) voidptr
147+
[typedef]
148+
struct C.DIR {
149+
}
150+
151+
fn C.opendir(&char) &C.DIR
148152

149153
fn C.closedir(dirp &C.DIR) int
150154

vlib/os/os.c.v

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ pub const (
77
args = []string{}
88
)
99

10-
struct C.dirent {
11-
d_name [256]char
12-
}
13-
1410
fn C.readdir(voidptr) &C.dirent
1511

1612
fn C.readlink(pathname &char, buf &char, bufsiz usize) int
@@ -41,36 +37,6 @@ fn C.ftruncate(voidptr, u64) int
4137

4238
fn C._chsize_s(voidptr, u64) int
4339

44-
// fn C.proc_pidpath(int, byteptr, int) int
45-
struct C.stat {
46-
st_size u64
47-
st_mode u32
48-
st_mtime int
49-
}
50-
51-
struct C.__stat64 {
52-
st_size u64
53-
st_mode u32
54-
st_mtime int
55-
}
56-
57-
struct C.DIR {
58-
}
59-
60-
type FN_SA_Handler = fn (sig int)
61-
62-
struct C.sigaction {
63-
mut:
64-
sa_mask int
65-
sa_sigaction int
66-
sa_flags int
67-
sa_handler FN_SA_Handler
68-
}
69-
70-
struct C.dirent {
71-
d_name &byte
72-
}
73-
7440
// read_bytes returns all bytes read from file in `path`.
7541
[manualfree]
7642
pub fn read_bytes(path string) ?[]byte {
@@ -890,12 +856,12 @@ pub fn wait() int {
890856
}
891857

892858
// file_last_mod_unix returns the "last modified" time stamp of file in `path`.
893-
pub fn file_last_mod_unix(path string) int {
859+
pub fn file_last_mod_unix(path string) i64 {
894860
attr := C.stat{}
895861
// # struct stat attr;
896862
unsafe { C.stat(&char(path.str), &attr) }
897863
// # stat(path.str, &attr);
898-
return attr.st_mtime
864+
return i64(attr.st_mtime)
899865
// # return attr.st_mtime ;
900866
}
901867

vlib/os/os_nix.c.v

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ pub const (
4343
s_ixoth = 0o0001 // Execute by others
4444
)
4545

46-
struct C.utsname {
47-
mut:
48-
sysname &char
49-
nodename &char
50-
release &char
51-
version &char
52-
machine &char
53-
}
54-
55-
struct C.utimbuf {
56-
actime int
57-
modtime int
58-
}
59-
6046
fn C.utime(&char, voidptr) int
6147

6248
fn C.uname(name voidptr) int

vlib/os/os_structs_dirent_default.c.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module os
2+
3+
struct C.dirent {
4+
d_name [256]char
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module os
2+
3+
pub type FN_SA_Handler = fn (sig int)
4+
5+
struct C.sigaction {
6+
mut:
7+
sa_mask int
8+
sa_sigaction int
9+
sa_flags int
10+
sa_handler FN_SA_Handler
11+
}

vlib/os/os_structs_stat_default.c.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module os
2+
3+
struct C.stat {
4+
st_size u64
5+
st_mode u32
6+
st_mtime int
7+
}
8+
9+
struct C.__stat64 {
10+
st_size u64
11+
st_mode u32
12+
st_mtime int
13+
}

vlib/os/os_structs_stat_linux.c.v

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module os
2+
3+
struct C.stat {
4+
st_dev u64 // 8
5+
st_ino u64 // 8
6+
st_nlink u64 // 8
7+
st_mode u32 // 4
8+
st_uid u32 // 4
9+
st_gid u32 // 4
10+
st_rdev u64 // 8
11+
st_size u64 // 8
12+
st_blksize u64 // 8
13+
st_blocks u64 // 8
14+
st_atime i64 // 8
15+
st_mtime i64 // 8
16+
st_ctime i64 // 8
17+
}
18+
19+
struct C.__stat64 {
20+
st_mode u32
21+
st_size u64
22+
st_mtime u64
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module os
2+
3+
struct C.utsname {
4+
mut:
5+
sysname &char
6+
nodename &char
7+
release &char
8+
version &char
9+
machine &char
10+
}
11+
12+
struct C.utimbuf {
13+
actime int
14+
modtime int
15+
}

0 commit comments

Comments
 (0)