1
0
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:
0x9ef
2019-07-18 21:21:48 +03:00
committed by Alexander Medvednikov
parent 67c2932f34
commit d6ddfa124d
4 changed files with 42 additions and 9 deletions

View File

@@ -67,7 +67,9 @@ const (
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)
// Check for code overflow
if code > u32(MAX_ERROR_CODE) {
@@ -81,10 +83,14 @@ fn ptr_get_error_message(code u32) voidptr {
return buf
}
pub fn get_error_msg(code u32) string {
_ptrdata := ptr_get_error_message(code)
if _ptrdata == voidptr(0) {
// get_error_msg return error code representation in string.
pub fn get_error_msg(code int) string {
if code < 0 { // skip negative
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))
}