aboutsummaryrefslogtreecommitdiff
path: root/core/sys/windows/util.odin
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2026-01-02 11:32:39 +0000
committergingerBill <gingerBill@users.noreply.github.com>2026-01-02 11:32:39 +0000
commite154489f013c66627975a6ba0d8d4c67b8ea33f9 (patch)
tree989c61f6962139660a8d8b0d8b124cd29d80a042 /core/sys/windows/util.odin
parent274e7e7e5848ec63d6c817151591b02281e2aa66 (diff)
More formatting improvements
Diffstat (limited to 'core/sys/windows/util.odin')
-rw-r--r--core/sys/windows/util.odin34
1 files changed, 29 insertions, 5 deletions
diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin
index 4729d5c72..8cabdeb04 100644
--- a/core/sys/windows/util.odin
+++ b/core/sys/windows/util.odin
@@ -7,74 +7,89 @@ import "base:intrinsics"
L :: intrinsics.constant_utf16_cstring
// https://learn.microsoft.com/en-us/windows/win32/winmsg/makeword
+@(require_results)
MAKEWORD :: #force_inline proc "contextless" (#any_int a, b: int) -> WORD {
return WORD(BYTE(DWORD_PTR(a) & 0xff)) | (WORD(BYTE(DWORD_PTR(b) & 0xff)) << 8)
}
// https://learn.microsoft.com/en-us/windows/win32/winmsg/makelong
+@(require_results)
MAKELONG :: #force_inline proc "contextless" (#any_int a, b: int) -> LONG {
return LONG(WORD(DWORD_PTR(a) & 0xffff)) | (LONG(WORD(DWORD_PTR(b) & 0xffff)) << 16)
}
// https://learn.microsoft.com/en-us/windows/win32/winmsg/loword
+@(require_results)
LOWORD :: #force_inline proc "contextless" (#any_int x: int) -> WORD {
return WORD(x & 0xffff)
}
// https://learn.microsoft.com/en-us/windows/win32/winmsg/hiword
+@(require_results)
HIWORD :: #force_inline proc "contextless" (#any_int x: int) -> WORD {
return WORD(x >> 16)
}
// https://learn.microsoft.com/en-us/windows/win32/winmsg/lobyte
+@(require_results)
LOBYTE :: #force_inline proc "contextless" (w: WORD) -> BYTE {
return BYTE((DWORD_PTR(w)) & 0xff)
}
// https://learn.microsoft.com/en-us/windows/win32/winmsg/hibyte
+@(require_results)
HIBYTE :: #force_inline proc "contextless" (w: WORD) -> BYTE {
return BYTE(((DWORD_PTR(w)) >> 8) & 0xff)
}
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-makewparam
+@(require_results)
MAKEWPARAM :: #force_inline proc "contextless" (#any_int l, h: int) -> WPARAM {
return WPARAM(MAKELONG(l, h))
}
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-makelparam
+@(require_results)
MAKELPARAM :: #force_inline proc "contextless" (#any_int l, h: int) -> LPARAM {
return LPARAM(MAKELONG(l, h))
}
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-makelresult
+@(require_results)
MAKELRESULT :: #force_inline proc "contextless" (#any_int l, h: int) -> LRESULT {
return LRESULT(MAKELONG(l, h))
}
// https://learn.microsoft.com/en-us/windows/win32/api/windowsx/nf-windowsx-get_x_lparam
+@(require_results)
GET_X_LPARAM :: #force_inline proc "contextless" (lp: LPARAM) -> c_int {
return cast(c_int)cast(c_short)LOWORD(cast(DWORD)lp)
}
// https://learn.microsoft.com/en-us/windows/win32/api/windowsx/nf-windowsx-get_y_lparam
+@(require_results)
GET_Y_LPARAM :: #force_inline proc "contextless" (lp: LPARAM) -> c_int {
return cast(c_int)cast(c_short)HIWORD(cast(DWORD)lp)
}
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-makelcid
+@(require_results)
MAKELCID :: #force_inline proc "contextless" (lgid, srtid: WORD) -> LCID {
return (DWORD(WORD(srtid)) << 16) | DWORD(WORD(lgid))
}
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-makelangid
+@(require_results)
MAKELANGID :: #force_inline proc "contextless" (p, s: WORD) -> DWORD {
return DWORD(WORD(s)) << 10 | DWORD(WORD(p))
}
+@(require_results)
LANGIDFROMLCID :: #force_inline proc "contextless" (lcid: LCID) -> LANGID {
return LANGID(lcid)
}
+@(require_results)
utf8_to_utf16_alloc :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
if len(s) < 1 {
return nil
@@ -102,6 +117,7 @@ utf8_to_utf16_alloc :: proc(s: string, allocator := context.temp_allocator) -> [
return text[:n]
}
+@(require_results)
utf8_to_utf16_buf :: proc(buf: []u16, s: string) -> []u16 {
n1 := MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, raw_data(s), c_int(len(s)), nil, 0)
if n1 == 0 {
@@ -120,6 +136,7 @@ utf8_to_utf16_buf :: proc(buf: []u16, s: string) -> []u16 {
}
utf8_to_utf16 :: proc{utf8_to_utf16_alloc, utf8_to_utf16_buf}
+@(require_results)
utf8_to_wstring_alloc :: proc(s: string, allocator := context.temp_allocator) -> wstring {
if res := utf8_to_utf16(s, allocator); len(res) > 0 {
return wstring(raw_data(res))
@@ -127,6 +144,7 @@ utf8_to_wstring_alloc :: proc(s: string, allocator := context.temp_allocator) ->
return nil
}
+@(require_results)
utf8_to_wstring_buf :: proc(buf: []u16, s: string) -> wstring {
if res := utf8_to_utf16(buf, s); len(res) > 0 {
return wstring(raw_data(res))
@@ -136,6 +154,7 @@ utf8_to_wstring_buf :: proc(buf: []u16, s: string) -> wstring {
utf8_to_wstring :: proc{utf8_to_wstring_alloc, utf8_to_wstring_buf}
+@(require_results)
wstring_to_utf8_alloc :: proc(s: wstring, N: int, allocator := context.temp_allocator) -> (res: string, err: runtime.Allocator_Error) {
context.allocator = allocator
@@ -170,6 +189,7 @@ wstring_to_utf8_alloc :: proc(s: wstring, N: int, allocator := context.temp_allo
return string(text[:n]), nil
}
+@(require_results)
wstring_to_utf8_buf :: proc(buf: []u8, s: wstring, N := -1) -> (res: string) {
n := WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, s, c_int(N), nil, 0, nil, nil)
if n == 0 {
@@ -211,6 +231,7 @@ Returns:
- res: A cloned and converted string
- err: An optional allocator error if one occured, `nil` otherwise
*/
+@(require_results)
utf16_to_utf8_alloc :: proc(s: []u16, allocator := context.temp_allocator) -> (res: string, err: runtime.Allocator_Error) {
if len(s) == 0 {
return "", nil
@@ -232,6 +253,7 @@ Inputs:
Returns:
- res: A converted string, backed byu `buf`
*/
+@(require_results)
utf16_to_utf8_buf :: proc(buf: []u8, s: []u16) -> (res: string) {
if len(s) == 0 {
return
@@ -244,8 +266,9 @@ utf16_to_utf8 :: proc{utf16_to_utf8_alloc, utf16_to_utf8_buf}
// AdvAPI32, NetAPI32 and UserENV helpers.
-allowed_username :: proc(username: string) -> bool {
- contains_any :: proc(s, chars: string) -> bool {
+@(require_results)
+allowed_username :: proc "contextless" (username: string) -> bool {
+ contains_any :: proc "contextless" (s, chars: string) -> bool {
if chars == "" {
return false
}
@@ -287,8 +310,8 @@ allowed_username :: proc(username: string) -> bool {
}
// Returns .Success on success.
+@(require_results)
_add_user :: proc(servername: string, username: string, password: string) -> (ok: NET_API_STATUS) {
-
servername_w: wstring
username_w: []u16
password_w: []u16
@@ -339,8 +362,8 @@ _add_user :: proc(servername: string, username: string, password: string) -> (ok
return
}
+@(require_results)
get_computer_name_and_account_sid :: proc(username: string) -> (computer_name: string, sid := SID{}, ok: bool) {
-
username_w := utf8_to_utf16(username, context.temp_allocator)
cbsid: DWORD
computer_name_size: DWORD
@@ -381,8 +404,8 @@ get_computer_name_and_account_sid :: proc(username: string) -> (computer_name: s
return
}
+@(require_results)
get_sid :: proc(username: string, sid: ^SID) -> (ok: bool) {
-
username_w := utf8_to_utf16(username, context.temp_allocator)
cbsid: DWORD
computer_name_size: DWORD
@@ -451,6 +474,7 @@ add_del_from_group :: proc(sid: ^SID, group: string) -> (ok: NET_API_STATUS) {
return
}
+@(require_results)
add_user_profile :: proc(username: string) -> (ok: bool, profile_path: string) {
username_w := utf8_to_utf16(username, context.temp_allocator)