hare

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

fcntl.ha (854B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use errors;
      5 use fs;
      6 use io;
      7 use rt;
      8 
      9 // Returns the [[fs::flag]]s associated with a file descriptor. See fcntl(2),
     10 // ref F_GETFL.
     11 export fn getflags(file: io::file) (fs::flag | errors::error) = {
     12 	match (rt::fcntl(file, rt::F_GETFL, void)) {
     13 	case let i: int =>
     14 		return i: fs::flag;
     15 	case let err: rt::errno =>
     16 		return errors::errno(err);
     17 	};
     18 };
     19 
     20 // Sets the [[fs::flag]]s associated with a file descriptor. Changes to the
     21 // access mode (e.g. [[fs::flag::RDWR]] and file creation flags (e.g.
     22 // [[fs::flag::CREATE]]) are ignored. See fcntl(2), ref F_SETFL.
     23 export fn setflags(file: io::file, flags: fs::flag) (void | errors::error) = {
     24 	match (rt::fcntl(file, rt::F_SETFL, flags)) {
     25 	case int =>
     26 		return;
     27 	case let err: rt::errno =>
     28 		return errors::errno(err);
     29 	};
     30 };