Previous: , Up: IO Space Functions   [Contents][Index]


21.9.2 with_temp_ios

The standard function with_temp_ios provides the following interface:

fun with_temp_ios = (string handler = pk_get_unique_mem_ios_handler,
                     uint<32> flags = 0,
                     Pk_With_Ios_Fn do = lambda void:{},
                     int<32> endian = get_endian) void:

Where handler is the handler to use for the IO space.

flags are the flags passed to open when opening the temporary IO space. Defaults to 0, which means to use whatever opening mode makes more sense depending on the kind of the IO space and it’s permissions.

do is a function of type ()void. Defaults to a function that does nothing.

endian is the endianness to use by default when accessing the temporary IO space. Defaults to the current endianness.

When invoked it opens a IO space, like openset, but takes care of calling close and restoring the original current IO space and endianness after the lambda returns or raises an exception.

It can be used to deal with files without risk of leaking file descriptors.

with_cur_ios
  :handler "*buf*"
  :do lambda void:
  {
    var arr = uint<32>[1]  0#B;
    arr[0] = 0x1234;
    printf("%v", byte[4]  0#b);
  }