mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
Fixed get_error_msg for *nix
* Fixed undefined: get_error_msg
This commit is contained in:
parent
67c2932f34
commit
d6ddfa124d
@ -3,3 +3,23 @@ module net
|
|||||||
#flag -lws2_32
|
#flag -lws2_32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <Ws2tcpip.h>
|
#include <Ws2tcpip.h>
|
||||||
|
|
||||||
|
// Ref - https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsastartup
|
||||||
|
const (
|
||||||
|
WSA_V1 = 0x100 // C.MAKEWORD(1, 0)
|
||||||
|
WSA_V11 = 0x101 // C.MAKEWORD(1, 1)
|
||||||
|
WSA_V2 = 0x200 // C.MAKEWORD(2, 0)
|
||||||
|
WSA_V21 = 0x201 // C.MAKEWORD(2, 1)
|
||||||
|
WSA_V22 = 0x202 // C.MAKEWORD(2, 2)
|
||||||
|
)
|
||||||
|
|
||||||
|
pub fn socket(family int, stype int, prototype int) Socket {
|
||||||
|
sockfd := C.socket(family, _type, proto)
|
||||||
|
s := Socket {
|
||||||
|
sockfd: sockfd
|
||||||
|
family: family
|
||||||
|
_type: _type
|
||||||
|
proto: proto
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
@ -483,8 +483,6 @@ pub fn user_os() string {
|
|||||||
return 'unknown'
|
return 'unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// home_dir returns path to user's home directory.
|
// home_dir returns path to user's home directory.
|
||||||
pub fn home_dir() string {
|
pub fn home_dir() string {
|
||||||
mut home := os.getenv('HOME')
|
mut home := os.getenv('HOME')
|
||||||
|
@ -5,3 +5,12 @@ module os
|
|||||||
const (
|
const (
|
||||||
PathSeparator = '/'
|
PathSeparator = '/'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// get_error_msg return error code representation in string.
|
||||||
|
pub fn get_error_msg(code int) string {
|
||||||
|
_ptr_text := C.strerror(code) // voidptr?
|
||||||
|
if _ptr_text == 0 {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return tos(_ptr_text, C.strlen(_ptr_text))
|
||||||
|
}
|
@ -67,7 +67,9 @@ const (
|
|||||||
MAX_ERROR_CODE = 15841 // ERROR_API_UNAVAILABLE
|
MAX_ERROR_CODE = 15841 // ERROR_API_UNAVAILABLE
|
||||||
)
|
)
|
||||||
|
|
||||||
fn ptr_get_error_message(code u32) voidptr {
|
// ptr_win_get_error_msg return string (voidptr)
|
||||||
|
// representation of error, only for windows.
|
||||||
|
fn ptr_win_get_error_msg(code u32) voidptr {
|
||||||
mut buf := voidptr(0)
|
mut buf := voidptr(0)
|
||||||
// Check for code overflow
|
// Check for code overflow
|
||||||
if code > u32(MAX_ERROR_CODE) {
|
if code > u32(MAX_ERROR_CODE) {
|
||||||
@ -81,10 +83,14 @@ fn ptr_get_error_message(code u32) voidptr {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_error_msg(code u32) string {
|
// get_error_msg return error code representation in string.
|
||||||
_ptrdata := ptr_get_error_message(code)
|
pub fn get_error_msg(code int) string {
|
||||||
if _ptrdata == voidptr(0) {
|
if code < 0 { // skip negative
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
return tos(_ptrdata, C.strlen(_ptrdata))
|
_ptr_text := ptr_win_get_error_msg(u32(code))
|
||||||
|
if _ptr_text == 0 { // compare with null
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return tos(_ptr_text, C.strlen(_ptr_text))
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user