static bool fifo_update_and_get_i64(IVShmemState *s, const uint8_t *buf, int size, int64_t *i64) { if (fifo_update_and_get(s, buf, size, i64, sizeof(*i64))) { *i64 = GINT64_FROM_LE(*i64); return true; } return false; }
static int64_t *extract_one_optimisation(FILE *opt_f, int32_t num_tiles_down, int32_t num_tiles_across, int32_t mcu_starts_count) { int64_t *mcu_starts = g_new(int64_t, mcu_starts_count); for (int32_t i = 0; i < mcu_starts_count; i++) { mcu_starts[i] = -1; // UNKNOWN value } // optimisation file is in a weird format, it is 32- (or 64- or 320- ?) bit // little endian values, giving the file offset into an MCU row, // each offset starts at a 40-byte alignment, and the last row (of the // entire file, not each image) seems to be missing // also, the offsets are all packed into 1 file, even with multiple images // we will read the file and verify at least that the markers // are valid, if anything is fishy, we will not use it // we represent missing data by -1, which we initialize to, // so if we run out of opt file, we can just stop for (int32_t row = 0; row < num_tiles_down; row++) { // read 40 bytes union { uint8_t buf[40]; int64_t i64; } u; if (fread(u.buf, 40, 1, opt_f) != 1) { // EOF or error, we've done all we can if (row == 0) { // if we don't even get the first one, deallocate goto FAIL; } break; } // get the offset int64_t offset = GINT64_FROM_LE(u.i64); // record this marker mcu_starts[row * num_tiles_across] = offset; } return mcu_starts; FAIL: g_free(mcu_starts); return NULL; }
/** * g_bytes_vector_read_int64: * @vector: (in): A #GBytesVector. * @value: (out): A location for a #gint64. * * Reads a #gint64 from the vector of buffers in @vector. If successful * then @value is set and %TRUE is returned. * * Returns: %TRUE if successful; otherwise %FALSE. */ gboolean g_bytes_vector_read_int64 (GBytesVector *vector, gint64 *value) { gboolean ret; if ((ret = g_bytes_vector_read(vector, (guint8 *)value, sizeof *value))) { *value = GINT64_FROM_LE(*value); } return ret; }
gboolean bson_cursor_get_int64 (const bson_cursor *c, gint64 *dest) { if (!dest) return FALSE; BSON_CURSOR_CHECK_TYPE (c, BSON_TYPE_INT64); memcpy (dest, bson_data (c->obj) + c->value_pos, sizeof (gint64)); *dest = GINT64_FROM_LE (*dest); return TRUE; }
/** * mongo_bson_iter_get_value_int64: * @iter: (in): A #MongoBsonIter. * * Fetches the current value pointed to by @iter if it is a * %MONGO_BSON_INT64. * * Returns: A #gint64. */ gint64 mongo_bson_iter_get_value_int64 (MongoBsonIter *iter) { gint64 value; g_return_val_if_fail(iter != NULL, 0L); g_return_val_if_fail(iter->user_data6 != NULL, 0L); if (ITER_IS_TYPE(iter, MONGO_BSON_INT64)) { memcpy(&value, iter->user_data6, sizeof value); return GINT64_FROM_LE(value); } g_warning("Current value is not an int64."); return 0L; }
/** * mongo_bson_iter_get_value_timeval: * @iter: (in): A #MongoBsonIter. * @value: (out): A location for a #GTimeVal. * * Fetches the current value pointed to by @iter as a #GTimeVal if the type * is a %MONGO_BSON_DATE_TIME. */ void mongo_bson_iter_get_value_timeval (MongoBsonIter *iter, GTimeVal *value) { gint64 v_int64; g_return_if_fail(iter != NULL); g_return_if_fail(value != NULL); if (ITER_IS_TYPE(iter, MONGO_BSON_DATE_TIME)) { memcpy(&v_int64, iter->user_data6, sizeof v_int64); v_int64 = GINT64_FROM_LE(v_int64); value->tv_sec = v_int64 / 1000; value->tv_usec = v_int64 % 1000; return; } g_warning("Current value is not a DateTime"); }
static inline gint64 gwy_serialize_unpack_int64(const guchar *buffer, gsize size, gsize *position) { gint64 value; gwy_debug("buf = %p, size = %" G_GSIZE_FORMAT ", pos = %" G_GSIZE_FORMAT, buffer, size, *position); g_assert(buffer); g_assert(position); g_return_val_if_fail(*position + sizeof(gint64) <= size, 0); memcpy(&value, buffer + *position, sizeof(gint64)); value = GINT64_FROM_LE(value); *position += sizeof(gint64); gwy_debug("value = <%lld>", value); return value; }
/** * qmi_utils_read_gint64_from_buffer: * @buffer: a buffer with raw binary data. * @buffer_size: size of @buffer. * @endian: endianness of firmware value; swapped to host byte order if necessary * @out: return location for the read variable. * * Reads a signed 64-bit integer from the buffer. The number in the buffer is * expected to be given in the byte order specified by @endian, and this method * takes care of converting the read value to the proper host endianness. * * The user needs to make sure that at least 8 bytes are available * in the buffer. * * Also note that both @buffer and @buffer_size get updated after the 8 bytes * read. */ void qmi_utils_read_gint64_from_buffer (const guint8 **buffer, guint16 *buffer_size, QmiEndian endian, gint64 *out) { g_assert (out != NULL); g_assert (buffer != NULL); g_assert (buffer_size != NULL); g_assert (*buffer_size >= 8); memcpy (out, &((*buffer)[0]), 8); if (endian == QMI_ENDIAN_BIG) *out = GINT64_FROM_BE (*out); else *out = GINT64_FROM_LE (*out); print_read_bytes_trace ("gint64", &(*buffer)[0], out, 8); *buffer = &((*buffer)[8]); *buffer_size = (*buffer_size) - 8; }