hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

+openbsd.ha (608B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use rt;
      5 use io;
      6 
      7 // Fills the given buffer with cryptographically random data. If the system is
      8 // unable to provide random data, abort. If you need to handle errors or want to
      9 // use whatever random data the system can provide, even if less than the
     10 // requested amount, use [[stream]] instead.
     11 export fn buffer(buf: []u8) void = {
     12 	rt::arc4random_buf(buf: *[*]u8: *const opaque, len(buf));
     13 };
     14 
     15 fn rand_reader(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = {
     16 	assert(s == stream);
     17 	buffer(buf);
     18 	return len(buf);
     19 };