hare

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

unknown_errno.ha (804B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 fn unknown_errno(err: errno) str = {
      5 	static let buf: [27]u8 = [0...];
      6 	let ubuf: [U64_BUFSZ]u8 = [0...];
      7 	let sl = buf[..0];
      8 
      9 	const s = *(&"[unknown errno ": *[]u8);
     10 	static append(sl, s...)!;
     11 
     12 	if (err < 0) {
     13 		static append(sl, '-')!;
     14 		const s = u64tos(ubuf, -err: u64);
     15 		static append(sl, *(&s: *[]u8)...)!;
     16 		static append(sl, ']')!;
     17 	} else {
     18 		const s = u64tos(ubuf, err: u64);
     19 		static append(sl, *(&s: *[]u8)...)!;
     20 		static append(sl, ']')!;
     21 	};
     22 
     23 	return *(&sl: *str);
     24 };
     25 
     26 @test fn unknown_errno() void = {
     27 	let err: errno = -1;
     28 	assert(strerror(err) == "[unknown errno -1]");
     29 	err = 0;
     30 	assert(strerror(err) == "[unknown errno 0]");
     31 	err = 2147483647;
     32 	assert(strerror(err) == "[unknown errno 2147483647]");
     33 };