Theoretically, this allows debuggers to tell them apart. https://devblogs.microsoft.com/oldnewthing/20110429-00/?p=10803
But in practice, this is more about cleanliness than anything else; I'm not aware of anyone running SetLastError-aware debuggers in Wine. Feel free to reject if this is a waste of time.
The changeable SetLastError calls were found by this script:
```python #!/usr/bin/env python3 import os import re
for (dirpath, dirnames, filenames) in os.walk("."): for fn in filenames: if not fn.endswith(".c") and not fn.endswith(".h"): continue text = open(dirpath+"/"+fn,"rt").read() text = text.replace("RtlSetLastWin32Error","SetLastError") text = text.replace("RtlGetLastWin32Error","GetLastError") if "SetLastError" not in text: continue varname = None for line in text.split("\n"): if "GetLastError" in line: if m := re.search(r"([A-Za-z0-9_]+) *= *GetLastError", line): prevline = line varname = m[1] if line == "}": varname = None if varname is not None and "SetLastError" in line: if m := re.search(r"SetLastError( *([A-Za-z0-9_]+) *)", line): if m[1] == varname: print(dirpath+"/"+fn, prevline, line) ```
The script also flags https://gitlab.winehq.org/wine/wine/-/blob/master/dlls/mpr/wnet.c#L2811, which is half set and half restore; I chose to left it unchanged.
Idea from https://gitlab.winehq.org/wine/wine/-/merge_requests/5020/diffs#6c845445f68f...
-- v3: win32u: Use RtlRestoreLastWin32Error instead of RtlSetLastWin32Error if appropriate everywhere: Change SetLastError to RestoreLastError if appropriate