mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
lots of Windows fixes and cross compilation for Windows
This commit is contained in:
56
vlib/os/os.v
56
vlib/os/os.v
@@ -6,11 +6,24 @@ module os
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
//#include <unistd.h>
|
||||
#include <errno.h>
|
||||
//#include <execinfo.h> // for backtrace_symbols_fd
|
||||
|
||||
/*
|
||||
struct dirent {
|
||||
d_ino int
|
||||
d_off int
|
||||
d_reclen u16
|
||||
d_type byte
|
||||
d_name [256]byte
|
||||
}
|
||||
*/
|
||||
|
||||
struct C.dirent {
|
||||
d_name byteptr
|
||||
}
|
||||
|
||||
const (
|
||||
args = []string
|
||||
MAX_PATH = 4096
|
||||
@@ -20,6 +33,10 @@ const (
|
||||
FILE_ATTRIBUTE_DIRECTORY = 16 // Windows
|
||||
)
|
||||
|
||||
import const (
|
||||
INVALID_FILE_ATTRIBUTES
|
||||
)
|
||||
|
||||
struct FILE {
|
||||
}
|
||||
|
||||
@@ -50,10 +67,10 @@ struct C.DIR {
|
||||
|
||||
}
|
||||
|
||||
struct C.dirent {
|
||||
d_name byteptr
|
||||
//struct C.dirent {
|
||||
//d_name byteptr
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
struct C.sigaction {
|
||||
mut:
|
||||
@@ -302,15 +319,22 @@ pub fn file_exists(path string) bool {
|
||||
}
|
||||
|
||||
pub fn dir_exists(path string) bool {
|
||||
dir := C.opendir(path.cstr())
|
||||
res := !isnil(dir)
|
||||
if res {
|
||||
C.closedir(dir)
|
||||
}
|
||||
return res
|
||||
$if windows {
|
||||
attr := int(C.GetFileAttributes(path.cstr()))
|
||||
println('ATTR =$attr')
|
||||
return attr == FILE_ATTRIBUTE_DIRECTORY
|
||||
}
|
||||
$else {
|
||||
dir := C.opendir(path.cstr())
|
||||
res := !isnil(dir)
|
||||
if res {
|
||||
C.closedir(dir)
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
// `mkdir` creates a new directory with the specified path.
|
||||
// mkdir creates a new directory with the specified path.
|
||||
pub fn mkdir(path string) {
|
||||
$if windows {
|
||||
path = path.replace('/', '\\')
|
||||
@@ -321,7 +345,7 @@ pub fn mkdir(path string) {
|
||||
}
|
||||
}
|
||||
|
||||
// `rm` removes file in `path`.
|
||||
// rm removes file in `path`.
|
||||
pub fn rm(path string) {
|
||||
$if windows {
|
||||
// os.system2('del /f $path')
|
||||
@@ -530,6 +554,11 @@ pub fn getwd() string {
|
||||
}
|
||||
|
||||
pub fn ls(path string) []string {
|
||||
$if windows {
|
||||
return []string
|
||||
}
|
||||
$else {
|
||||
|
||||
mut res := []string
|
||||
dir := C.opendir(path.str)
|
||||
if isnil(dir) {
|
||||
@@ -550,6 +579,7 @@ pub fn ls(path string) []string {
|
||||
}
|
||||
C.closedir(dir)
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
fn log(s string) {
|
||||
|
||||
3
vlib/os/os_mac.v
Normal file
3
vlib/os/os_mac.v
Normal file
@@ -0,0 +1,3 @@
|
||||
module os
|
||||
|
||||
#include <dirent.h>
|
||||
@@ -1,140 +0,0 @@
|
||||
module os
|
||||
|
||||
// Ref - https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types
|
||||
|
||||
type BOOL bool
|
||||
type BOOLEAN BOOL
|
||||
|
||||
// A byte (8 bits)
|
||||
type BYTE u8
|
||||
|
||||
// An 8-bit Windows (ANSI) character.
|
||||
type CHAR u8
|
||||
|
||||
// An 16-bit Windows character.
|
||||
type WCHAR u16
|
||||
|
||||
// A 32-bit signed integer. The range is -2147483648 through 2147483647 decimal.
|
||||
type INT i32
|
||||
|
||||
// A signed integer type for pointer precision.
|
||||
type INT_PTR INT*
|
||||
|
||||
// A pointer to an INT (INT32).
|
||||
type PINT INT*
|
||||
|
||||
// A 8-bit signed integer.
|
||||
type INT8 i8
|
||||
|
||||
// // A pointer to an INT8.
|
||||
type PINT8 INT8*
|
||||
|
||||
// A 16-bit signed integer.
|
||||
type INT16 i16
|
||||
|
||||
// // A pointer to an INT16.
|
||||
type PINT16 INT16*
|
||||
|
||||
// A 32-bit signed integer.
|
||||
type INT32 i32
|
||||
|
||||
// A pointer to an INT32.
|
||||
type PINT32 INT32*
|
||||
|
||||
// A 64-bit signed integer.
|
||||
type INT64 i64
|
||||
|
||||
// A pointer to an INT64.
|
||||
type PINT64 INT64*
|
||||
|
||||
// An unsigned INT. The range is 0 through 4294967295 decimal.
|
||||
type UINT u32
|
||||
|
||||
// An unsigned INT_PTR.
|
||||
type UINT_PTR UINT*
|
||||
|
||||
// An unsigned INT8.
|
||||
type UINT8 u8
|
||||
|
||||
// An unsigned INT16.
|
||||
type UINT16 u16
|
||||
|
||||
// An unsigned INT32.
|
||||
type UINT32 u32
|
||||
|
||||
// An unsigned INT64.
|
||||
type UINT64 u64
|
||||
|
||||
// A 16-bit unsigned integer. The range is 0 through 65535 decimal.
|
||||
type WORD u16
|
||||
|
||||
// A pointer to an WORD.
|
||||
type LPWORD WORD*
|
||||
|
||||
// A 32-bit unsigned integer. The range is 0 through 4294967295 decimal.
|
||||
type DWORD u32
|
||||
|
||||
// A pointer to an DWORD.
|
||||
type DWORD_PTR DWORD*
|
||||
type LPDWORD DWORD*
|
||||
|
||||
// A 64-bit unsigned integer. The range is 0 through 18446744073709551615 decimal.
|
||||
type DWORDLONG u64
|
||||
type PDWORDLONG DWORDLONG*
|
||||
|
||||
// A 32-bit unsigned integer.
|
||||
type DWORD32 u32
|
||||
type PDWORD32 DWORD32*
|
||||
|
||||
// A 64-bit unsigned integer.
|
||||
type DWORD64 u64
|
||||
type PDWORD64 DWORD64*
|
||||
|
||||
// A floating-point variable.
|
||||
type FLOAT f32
|
||||
type FLOAT64 f64
|
||||
type PFLOAT FLOAT*
|
||||
|
||||
// A 32-bit signed integer. The range is 2147483648 through 2147483647 decimal.
|
||||
type LONG i32
|
||||
type LONG_PTR LONG*
|
||||
type LPLONG LONG*
|
||||
|
||||
// A 64-bit signed integer. The range is 9223372036854775808 through 9223372036854775807 decimal.
|
||||
type LONGLONG i64
|
||||
type LONG32 i32
|
||||
type LONG64 i64
|
||||
|
||||
// A pointer to a BOOL.
|
||||
type LPBOOL BOOL*
|
||||
|
||||
// A pointer to a BYTE.
|
||||
type LPBYTE BYTE*
|
||||
|
||||
// An 8-bit Windows (ANSI) character. For more information, see Character Sets Used By Fonts.
|
||||
type LPCSTR CHAR*
|
||||
|
||||
// A 16-bit Unicode character. For more information, see Character Sets Used By Fonts.
|
||||
type LPWSTR WCHAR*
|
||||
|
||||
// A pointer to an CHAR.
|
||||
type PCHAR CHAR*
|
||||
|
||||
// A pointer to an BYTE.
|
||||
type PBYTE BYTE*
|
||||
|
||||
//
|
||||
// Descriptor
|
||||
//
|
||||
|
||||
// A handle to an object.
|
||||
type HANDLE C.HANDLE // voidptr?
|
||||
|
||||
// A pointer to a HANDLE.
|
||||
type PHANDLE *HANDLE
|
||||
|
||||
// A handle to a registry key.
|
||||
type HKEY HANDLE
|
||||
|
||||
// A pointer to a HKEY.
|
||||
type PHKEY *HKEY
|
||||
Reference in New Issue
Block a user