hare

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

rt.ha (1066B)


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