hare

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

rt.ha (1022B)


      1 // License: MPL-2.0
      2 // (c) 2021 Drew DeVault <sir@cmpwn.com>
      3 use rt;
      4 
      5 // Wraps an [[rt::errno]] to produce an [[errors::opaque]]. This is a non-portable
      6 // interface which is mainly provided to support internal stdlib requirements.
      7 export fn errno(errno: rt::errno) error = {
      8 	switch (errno) {
      9 	case rt::ECONNREFUSED =>
     10 		return refused;
     11 	case rt::ECANCELED =>
     12 		return cancelled;
     13 	case rt::EOVERFLOW =>
     14 		return overflow;
     15 	case rt::EACCES =>
     16 		return noaccess;
     17 	case rt::EINVAL =>
     18 		return invalid;
     19 	case rt::EEXIST =>
     20 		return exists;
     21 	case rt::ENOENT =>
     22 		return noentry;
     23 	case rt::ETIME =>
     24 		return timeout;
     25 	case rt::EBUSY =>
     26 		return busy;
     27 	case rt::EINTR =>
     28 		return interrupted;
     29 	case rt::EAGAIN =>
     30 		return again;
     31 	case => void;
     32 	};
     33 
     34 	static assert(size(rt::errno) <= size(opaque_data));
     35 	let err = opaque { strerror = &rt_strerror, ... };
     36 	let ptr = &err.data: *rt::errno;
     37 	*ptr = errno;
     38 	return err;
     39 };
     40 
     41 fn rt_strerror(err: *opaque_data) const str = {
     42 	let err = err: *rt::errno;
     43 	return rt::strerror(*err);
     44 };