File: unknown_errno.ha

package info (click to toggle)
hare 0.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,948 kB
  • sloc: asm: 1,264; makefile: 123; sh: 114; lisp: 101
file content (33 lines) | stat: -rw-r--r-- 804 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

fn unknown_errno(err: errno) str = {
	static let buf: [27]u8 = [0...];
	let ubuf: [U64_BUFSZ]u8 = [0...];
	let sl = buf[..0];

	const s = *(&"[unknown errno ": *[]u8);
	static append(sl, s...)!;

	if (err < 0) {
		static append(sl, '-')!;
		const s = u64tos(ubuf, -err: u64);
		static append(sl, *(&s: *[]u8)...)!;
		static append(sl, ']')!;
	} else {
		const s = u64tos(ubuf, err: u64);
		static append(sl, *(&s: *[]u8)...)!;
		static append(sl, ']')!;
	};

	return *(&sl: *str);
};

@test fn unknown_errno() void = {
	let err: errno = -1;
	assert(strerror(err) == "[unknown errno -1]");
	err = 0;
	assert(strerror(err) == "[unknown errno 0]");
	err = 2147483647;
	assert(strerror(err) == "[unknown errno 2147483647]");
};