sys

A set of unix utils in hare!
Log | Files | Refs | README

error.ha (469B)


      1 use encoding::utf8;
      2 use fmt;
      3 
      4 export type syntax = !str;
      5 export type error = !(syntax | nomem | utf8::invalid);
      6 
      7 export fn strerror(err: error) str = {
      8 	match (err) {
      9 	case let err: syntax => return err;
     10 	case let err: utf8::invalid => return utf8::strerror(err);
     11 	case nomem => return "nomem";
     12 	};
     13 };
     14 
     15 export fn syntaxf(msg: const str, args: fmt::field...) syntax = {
     16 	static let buf: [2048]u8 = [0...];
     17 	const msg = fmt::bsprintf(buf, msg, args...)!;
     18 	return msg;
     19 };