Make all file-handling functions/methods use to_c_str().with_ref().

For `img::load`, `as_imm_buf()` was used without converting the string to a null-terminated string and it caused errors quite hard to reason (as it caused `get_error()` to trigger `!is_utf8()` assertion). For others, there are no functional changes but I updated them anyway for consistency.