#Would std.os.mmap work on Windows

1 messages · Page 1 of 1 (latest)

whole drum
#

I see std.os.mmap in the Zig standard library. Does this only work on Linux?

I want to work with memory mapped files on Windows, so it would be awesome if this worked on Windows. However, I would assume that it doesn't work on Windows, given that there is a very different API for managing memory mapped files.

timber barn
#

I believe it should work if you're linking libc?

#

but otherwise, I don't see any code for it to work on windows

glacial valley
#

Last I checked you have to define the extern functions required for it yourself, and if you want crossplatform compatibility then you have to wrap that yourself too

timber barn
#

what are you referring to?

#

the functions to map memory are exposed in std.os.windows and std.os.linux afaik

#

it's just std.os.mmap specifically that only works on posixy systems or while linking libc

glacial valley
#

oh, are they actually defined (in std.os.windows) now? I had to declare CreateFileMappingW and friends because I didn't see it when I looked, though that was last month

timber barn
#

Oh, suppose those aren't there then

#

that is a bit odd

#

have you considered PRing them?

glacial valley
#

Anyway, the windows C interface doesn't declare mmap, so std.os.mmap is only posix-portable

timber barn
#

that seems like those should be in the stdlib

whole drum
#

How do I link libc?

timber barn
#

on the command line, -lc

#

in build.zig, artifact.linkLibC();

glacial valley
timber barn
#

ye, sounds a worthwhile endeavour