/* Internal function: ensure that an fseek() is called on a file pointer in between reading and writing operations, and vice versa. This will only come up for ReadWrite or WriteAppend files. */ static void ensure_file_operation(strid_t str, glui32 op) { if(str->lastop != 0 && str->lastop != op) { long pos = ftell(str->file_pointer); if(pos == -1) WARNING_S("ftell() failed", g_strerror(errno)); if(fseek(str->file_pointer, pos, SEEK_SET) != 0) WARNING_S("fseek() failed", g_strerror(errno)); } str->lastop = op; /* Not 0, because we are about to do the operation anyway */ }
/* Internal function: convert a null-terminated UTF-8 string to a null-terminated UCS4 string. If items_written is not NULL it will be filled with the number of code points returned, not counting the terminator. The returned string must be freed afterwards. Returns NULL on error. */ gunichar * convert_utf8_to_ucs4(const gchar *s, glong *items_written) { gunichar *retval = g_utf8_to_ucs4_fast(s, -1, items_written); if(retval == NULL) WARNING_S("Error during utf8->unicode conversion of string", s); return retval; }
/* Internal function: Convert a Unicode buffer to a null-terminated UTF-8 string. The returned string must be freed afterwards. Returns NULL on error. */ gchar * convert_ucs4_to_utf8(const gunichar *buf, const glong len) { GError *error = NULL; gchar *retval = g_ucs4_to_utf8(buf, len, NULL, NULL, &error); if(retval == NULL) WARNING_S("Error during unicode->utf8 conversion", error->message); return retval; }