Beispiel #1
0
static GBuffer *
zone_for_constant_offset (const gchar *name)
{
  const gchar fake_zoneinfo_headers[] =
    "TZif" "2..." "...." "...." "...."
    "\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0"
    "TZif" "2..." "...." "...." "...."
    "\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\1" "\0\0\0\7";
  struct {
    struct tzhead headers[2];
    struct ttinfo info;
    gchar abbr[8];
  } *fake;
  gint32 offset;

  if (name == NULL || !parse_constant_offset (name, &offset))
    return NULL;

  offset = GINT32_TO_BE (offset);

  fake = g_malloc (sizeof *fake);
  memcpy (fake, fake_zoneinfo_headers, sizeof fake_zoneinfo_headers);
  memcpy (&fake->info.tt_gmtoff, &offset, sizeof offset);
  fake->info.tt_isdst = FALSE;
  fake->info.tt_abbrind = 0;
  strcpy (fake->abbr, name);

  return g_buffer_new_take_data (fake, sizeof *fake);
}
Beispiel #2
0
/* < private >
 * g_variant_ensure_serialised:
 * @value: a #GVariant
 *
 * Ensures that @value is in serialised form.
 *
 * If @value is in tree form then this function ensures that the
 * serialised size is known and then allocates a buffer of that size and
 * serialises the instance into the buffer.  The 'children' array is
 * then released and the instance is set to serialised form based on the
 * contents of the buffer.
 *
 * The current thread must hold the lock on @value.
 */
static void
g_variant_ensure_serialised (GVariant *value)
{
  g_assert (value->state & STATE_LOCKED);

  if (~value->state & STATE_SERIALISED)
    {
      GBuffer *buffer;
      gpointer data;

      g_variant_ensure_size (value);
      data = g_malloc (value->size);
      g_variant_serialise (value, data);

      g_variant_release_children (value);

      buffer = g_buffer_new_take_data (data, value->size);
      value->contents.serialised.data = buffer->data;
      value->contents.serialised.buffer = buffer;
      value->state |= STATE_SERIALISED;
    }
}