hare

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

file.ha (735B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use rt;
      5 
      6 // Lock operation to use with [[lock]].
      7 export type lockop = enum int {
      8 	// shared file lock
      9 	SHARED    = rt::LOCK_SH,
     10 	// exclusive file lock
     11 	EXCLUSIVE = rt::LOCK_EX,
     12 	// unlock file
     13 	UNLOCK    = rt::LOCK_UN,
     14 };
     15 
     16 // Apply or remove an advisory lock on an open file. If block is true, the
     17 // request will block while waiting for the lock.
     18 export fn lock(fd: file, block: bool, op: lockop) (bool | error) = {
     19 	let flags = op: int;
     20 	if (!block) flags |= rt::LOCK_NB;
     21 	return fd_lock(fd, flags);
     22 };
     23 
     24 // Truncate a file to a specified length. The file must be open for writing.
     25 export fn trunc(fd: file, ln: size) (void | error) = fd_trunc(fd, ln);