trg_torrent_file *trg_parse_torrent_file(const gchar * filename)
{
    GError *error = NULL;
    trg_torrent_file *ret = NULL;
    GMappedFile *mf;

    if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
        g_message("%s does not exist", filename);
        return NULL;
    }

    mf = g_mapped_file_new(filename, FALSE, &error);

    if (error) {
        g_error("%s", error->message);
        g_error_free(error);
        g_mapped_file_unref(mf);
        return NULL;
    } else {
        ret = trg_parse_torrent_data(g_mapped_file_get_contents(mf), g_mapped_file_get_length(mf));
    }

    g_mapped_file_unref(mf);

    return ret;
}
Exemple #2
0
struct kml *
kml_parse(const gchar *file, GError **er)
{
	GMarkupParseContext	*ctx;
	GMarkupParser	  	 parse;
	GMappedFile		*f;
	int			 rc;
	struct kmlparse		 data;
	struct kml		*kml;

	if (NULL != er)
		*er = NULL;

	memset(&parse, 0, sizeof(GMarkupParser));
	memset(&data, 0, sizeof(struct kmlparse));

	data.elem = KML_INIT;

	parse.start_element = kml_elem_start;
	parse.end_element = kml_elem_end;
	parse.text = kml_text;
	parse.error = kml_error;

	if (NULL == (f = g_mapped_file_new(file, FALSE, er)))
		return(NULL);

	ctx = g_markup_parse_context_new
		(&parse, 0, &data, NULL);
	g_assert(NULL != ctx);
	rc = g_markup_parse_context_parse
		(ctx, g_mapped_file_get_contents(f),
		 g_mapped_file_get_length(f), er);

	g_markup_parse_context_free(ctx);
	g_free(data.buf);
	g_free(data.altbuf);
	g_free(data.ign);
	kmlparse_free(data.cur);

	if (0 == rc) {
		g_list_free_full(data.places, kmlparse_free);
		g_mapped_file_unref(f);
		return(NULL);
	} else if (NULL == data.places) {
		g_mapped_file_unref(f);
		return(NULL);
	}

	g_assert(NULL != data.places);
	kml = g_malloc0(sizeof(struct kml));
	kml->file = f;
	kml->kmls = data.places;
	return(kml);
}
Exemple #3
0
static gboolean
CompareFile(const gchar *fname1,                 // IN
            const gchar *fname2,                 // IN
            gboolean *same)                      // OUT
{
   gsize num;
   gboolean ret = FALSE;
   GMappedFile *m1;
   GMappedFile *m2 = NULL;
   GError *error = NULL;

   m1 = g_mapped_file_new(fname1, FALSE, &error);
   if (m1 == NULL) {
      Error("Unable to map %s: %s.\n", fname1, error->message);
      goto exit;
   }

   m2 = g_mapped_file_new(fname2, FALSE, &error);
   if (m2 == NULL) {
      Error("Unable to map %s: %s.\n", fname2, error->message);
      goto exit;
   }

   ret = TRUE;
   *same = FALSE;

   num = g_mapped_file_get_length(m1);
   if (g_mapped_file_get_length(m2) == num) {
      if (num) {
         if (memcmp(g_mapped_file_get_contents(m1),
                    g_mapped_file_get_contents(m2), num) == 0) {
            *same = TRUE;
         }
      } else {
         /* Two empty files */
         *same = TRUE;
      }
   }

exit:
   g_clear_error(&error);
   if (m1) {
      g_mapped_file_unref(m1);
   }
   if (m2) {
      g_mapped_file_unref(m2);
   }

   return ret;
}
Exemple #4
0
dt_gpx_t *dt_gpx_new(const gchar *filename)
{
  dt_gpx_t *gpx = NULL;
  GMarkupParseContext *ctx = NULL;
  GError *err = NULL;
  GMappedFile *gpxmf = NULL;
  gchar *gpxmf_content = NULL;
  gint gpxmf_size = 0;


  /* map gpx file to parse into memory */
  gpxmf = g_mapped_file_new(filename, FALSE, &err);
  if(err) goto error;

  gpxmf_content = g_mapped_file_get_contents(gpxmf);
  gpxmf_size = g_mapped_file_get_length(gpxmf);
  if(!gpxmf_content || gpxmf_size < 10) goto error;

  /* allocate new dt_gpx_t context */
  gpx = g_malloc0(sizeof(dt_gpx_t));

  /* initialize the parser and start parse gpx xml data */
  ctx = g_markup_parse_context_new(&_gpx_parser, 0, gpx, NULL);
  g_markup_parse_context_parse(ctx, gpxmf_content, gpxmf_size, &err);
  if(err) goto error;


  /* cleanup and return gpx context */
  g_markup_parse_context_free(ctx);
  g_mapped_file_unref(gpxmf);

  return gpx;

error:
  if(err)
  {
    fprintf(stderr, "dt_gpx_new: %s\n", err->message);
    g_error_free(err);
  }

  if(ctx) g_markup_parse_context_free(ctx);

  g_free(gpx);

  if(gpxmf) g_mapped_file_unref(gpxmf);

  return NULL;
}
static GBytes *
load_file (const gchar *filename,
           GError **error)
{
  GError *local_error = NULL;
  GMappedFile *mapped;
  GBytes *bytes;

  mapped = g_mapped_file_new (filename, FALSE, &local_error);

  if (g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_NOENT) ||
      g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) ||
      g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_NAMETOOLONG) ||
      g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_LOOP) ||
      g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_INVAL))
    {
      g_clear_error (&local_error);
      return NULL;
    }

  /* A real error to stop on */
  else if (local_error)
    {
      g_propagate_error (error, local_error);
      return NULL;
    }

  bytes = g_mapped_file_get_bytes (mapped);
  g_mapped_file_unref (mapped);

  return bytes;
}
static void
iso_codes_parse (const GMarkupParser *parser,
const gchar *basename,
GHashTable *hash_table)
{
	GMappedFile *mapped_file;
	gchar *filename;
	GError *error = NULL;

	filename = g_build_filename (ISO_CODES_PREFIX, "share", "xml", "iso-codes",
		basename, NULL);
	mapped_file = g_mapped_file_new (filename, FALSE, &error);
	g_free (filename);

	if (mapped_file != NULL)
	{
		GMarkupParseContext *context;
		const gchar *contents;
		gsize length;

		context = g_markup_parse_context_new (parser, 0, hash_table, NULL);
		contents = g_mapped_file_get_contents (mapped_file);
		length = g_mapped_file_get_length (mapped_file);
		g_markup_parse_context_parse (context, contents, length, &error);
		g_markup_parse_context_free (context);
		g_mapped_file_unref (mapped_file);
	}

	if (error != NULL)
	{
		g_warning ("%s: %s", basename, error->message);
		g_error_free (error);
	}
}
Exemple #7
0
/**
 * ot_util_variant_map:
 * @src: a #GFile
 * @type: Use this for variant
 * @trusted: See documentation of g_variant_new_from_data()
 * @out_variant: (out): Return location for new variant
 * @error:
 *
 * Memory-map @src, and store a new #GVariant referring to this memory
 * in @out_variant.  Note the returned @out_variant is not floating.
 */
gboolean
ot_util_variant_map (GFile              *src,
                     const GVariantType *type,
                     gboolean            trusted,
                     GVariant          **out_variant,
                     GError            **error)
{
  gboolean ret = FALSE;
  gs_unref_variant GVariant *ret_variant = NULL;
  GMappedFile *mfile = NULL;

  mfile = gs_file_map_noatime (src, NULL, error);
  if (!mfile)
    goto out;

  ret_variant = g_variant_new_from_data (type,
                                         g_mapped_file_get_contents (mfile),
                                         g_mapped_file_get_length (mfile),
                                         trusted,
                                         (GDestroyNotify) g_mapped_file_unref,
                                         mfile);
  mfile = NULL;
  g_variant_ref_sink (ret_variant);
  
  ret = TRUE;
  ot_transfer_out_value(out_variant, &ret_variant);
 out:
  if (mfile)
    g_mapped_file_unref (mfile);
  return ret;
}
Exemple #8
0
/**
 * Unzip a file - replacing the file with the unzipped contents of the self
 */
static void uncompress_zip ( gchar *name )
{
	GError *error = NULL;
	GMappedFile *mf;

	if ((mf = g_mapped_file_new ( name, FALSE, &error )) == NULL) {
		g_critical(_("Couldn't map file %s: %s"), name, error->message);
		g_error_free(error);
		return;
	}
	gchar *file_contents = g_mapped_file_get_contents ( mf );

	void *unzip_mem = NULL;
	gulong ucsize;

	if ((unzip_mem = unzip_file (file_contents, &ucsize)) == NULL) {
		g_mapped_file_unref ( mf );
		return;
	}

	// This overwrites any previous file contents
	if ( ! g_file_set_contents ( name, unzip_mem, ucsize, &error ) ) {
		g_critical ( "Couldn't write file '%s', because of %s", name, error->message );
		g_error_free ( error );
	}
}
Exemple #9
0
/***********************************************
 * PUBLIC
 **********************************************/
WqqQQChat *wqq_qqchat_new(const gchar * base, const gchar * css_file)
{
	WqqQQChat *chat = (WqqQQChat *) g_object_new(WQQ_TYPE_QQCHAT, NULL);
	GtkWidget *webview = chat->webview;

	GMappedFile *file = g_mapped_file_new(css_file, FALSE, NULL);
	if (file != NULL) {
		gchar *CSS = g_mapped_file_get_contents(file);
		gchar *tmp =
			g_base64_encode((guchar *) CSS, strlen((gchar *) CSS));
		gchar *css = g_strconcat("data:text/css;charset=utf-8;base64,",
								 tmp, NULL);
		g_object_set(webkit_web_view_get_settings
					 (WEBKIT_WEB_VIEW(webview)), "user-stylesheet-uri",
					 css, NULL);
		g_free(css);
		g_free(tmp);
		g_mapped_file_unref(file);
	}
	webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview),
				"<html><body></body></html>",
				"text/html", "UTF-8", base);
	chat->loading = TRUE;

	g_signal_connect(G_OBJECT(chat->webview), "size-allocate",
				G_CALLBACK(_on_auto_scroll), chat);
	g_signal_connect(G_OBJECT(chat->webview), "context-menu",
					 G_CALLBACK(_block_context_menu), NULL);
	g_signal_connect(G_OBJECT(chat->webview), "load-finished",
					 G_CALLBACK(on_webview_load_finished), chat);


	return chat;
}
Exemple #10
0
GimpColorProfile
gimp_lcms_profile_open_from_file (const gchar  *filename,
                                  GError      **error)
{
  GimpColorProfile  profile;
  GMappedFile      *file;
  const guint8     *data;
  gsize             length;

  g_return_val_if_fail (filename != NULL, NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  file = g_mapped_file_new (filename, FALSE, error);

  if (! file)
    return NULL;

  data   = (const guint8 *) g_mapped_file_get_contents (file);
  length = g_mapped_file_get_length (file);

  profile = cmsOpenProfileFromMem (data, length);

  if (! profile)
    g_set_error (error, gimp_lcms_error_quark (), 0,
                 _("'%s' does not appear to be an ICC color profile"),
                 gimp_filename_to_utf8 (filename));

  g_mapped_file_unref (file);

  return profile;
}
int
main (int argc, char **argv)
{
  GMappedFile *f;
  gchar *xml_data;
  gsize xml_len;

  f = g_mapped_file_new (ISO_639_XML_PATH, FALSE, NULL);
  if (f != NULL) {
    xml_data = (gchar *) g_mapped_file_get_contents (f);
    xml_len = g_mapped_file_get_length (f);
  } else {
    GError *err = NULL;

    if (!g_file_get_contents (ISO_639_XML_PATH, &xml_data, &xml_len, &err))
      g_error ("Could not read %s: %s", ISO_639_XML_PATH, err->message);
  }

  languages = g_array_new (FALSE, TRUE, sizeof (IsoLang));

  parse_iso_639_xml (xml_data, xml_len);

  g_array_sort (languages, (GCompareFunc) languages_sort_func);

  dump_languages ();

  g_array_free (languages, TRUE);

  if (f != NULL)
    g_mapped_file_unref (f);
  else
    g_free (xml_data);

  return 0;
}
Exemple #12
0
static gboolean
zone_info_read(const gchar *zonename, ZoneInfo **zone, ZoneInfo **zone64)
{
    unsigned char *buff = NULL;
    gchar *filename = NULL;
    int byte_read = 0;
    int version;
    GError *error = NULL;
    GMappedFile *file_map = NULL;

    *zone = NULL;
    *zone64 = NULL;

    filename = g_build_path(G_DIR_SEPARATOR_S, get_time_zone_basedir(), zonename, NULL);

    file_map = g_mapped_file_new(filename, FALSE, &error);
    if (!file_map)
    {
        msg_error("Failed to open the time zone file", evt_tag_str("filename", filename), evt_tag_str("message", error->message), NULL);
        g_error_free(error);
        g_free(filename);
        return FALSE;
    }

    byte_read = g_mapped_file_get_length(file_map);
    buff = (unsigned char*)g_mapped_file_get_contents(file_map);

    if (byte_read == -1)
    {
        msg_error("Failed to read the time zone file", evt_tag_str("filename", filename), NULL);
        g_mapped_file_unref(file_map);
        g_free(filename);
        return FALSE;
    }

    msg_debug("Processing the time zone file (32bit part)", evt_tag_str("filename", filename), NULL);
    *zone = zone_info_parser(&buff, FALSE, &version);
    if (version == 2)
    {
        msg_debug("Processing the time zone file (64bit part)", evt_tag_str("filename", filename), NULL);
        *zone64 = zone_info_parser(&buff, TRUE, &version);
    }

    g_mapped_file_unref(file_map);
    g_free(filename);
    return TRUE;
}
Exemple #13
0
int
main (int argc, char **argv)
{
  GError *local_error = NULL;
  GError **error = &local_error;
  GBytes *from_bytes = NULL;
  GBytes *to_bytes = NULL;
  const char *from_path;
  const char *to_path;
  OstreeRollsumMatches *matches;
  GMappedFile *mfile;

  g_setenv ("GIO_USE_VFS", "local", TRUE);

  if (argc < 3)
    exit (EXIT_FAILURE);

  from_path = argv[1];
  to_path = argv[2];

  mfile = g_mapped_file_new (from_path, FALSE, error);
  if (!mfile)
    goto out;
  from_bytes = g_mapped_file_get_bytes (mfile);
  g_mapped_file_unref (mfile);
  mfile = g_mapped_file_new (to_path, FALSE, error);
  if (!mfile)
    goto out;
  to_bytes = g_mapped_file_get_bytes (mfile);
  g_mapped_file_unref (mfile);

  matches = _ostree_compute_rollsum_matches (from_bytes, to_bytes);

  g_printerr ("rollsum crcs=%u bufs=%u total=%u matchsize=%llu\n",
              matches->crcmatches,
              matches->bufmatches,
              matches->total, (unsigned long long)matches->match_size);

 out:
  if (local_error)
    {
      g_printerr ("%s\n", local_error->message);
      g_error_free (local_error);
      return 1;
    }
  return 0;
}
static GList *
log_store_empathy_search_new (EmpathyLogStore *self,
                              const gchar *text)
{
  GList *files, *l;
  GList *hits = NULL;
  gchar *text_casefold;

  g_return_val_if_fail (EMPATHY_IS_LOG_STORE (self), NULL);
  g_return_val_if_fail (!EMP_STR_EMPTY (text), NULL);

  text_casefold = g_utf8_casefold (text, -1);

  files = log_store_empathy_get_all_files (self, NULL);
  DEBUG ("Found %d log files in total", g_list_length (files));

  for (l = files; l; l = g_list_next (l))
    {
      gchar *filename;
      GMappedFile *file;
      gsize length;
      gchar *contents;
      gchar *contents_casefold;

      filename = l->data;

      file = g_mapped_file_new (filename, FALSE, NULL);
      if (!file)
        continue;

      length = g_mapped_file_get_length (file);
      contents = g_mapped_file_get_contents (file);
      contents_casefold = g_utf8_casefold (contents, length);

      g_mapped_file_unref (file);

      if (strstr (contents_casefold, text_casefold))
        {
          EmpathyLogSearchHit *hit;

          hit = log_store_empathy_search_hit_new (self, filename);

          if (hit)
            {
              hits = g_list_prepend (hits, hit);
              DEBUG ("Found text:'%s' in file:'%s' on date:'%s'",
                  text, hit->filename, hit->date);
            }
        }

      g_free (contents_casefold);
      g_free (filename);
    }

  g_list_free (files);
  g_free (text_casefold);

  return hits;
}
Exemple #15
0
static gboolean
DisplayServerCert(const gchar *serverCertPemFile) // IN
{
   gboolean ret = FALSE;
   gchar *cert = NULL;
   FILE *file = NULL;
   GMappedFile *fmap = NULL;

   if (!ValidateEnvironment(FALSE)) {
      goto exit;
   }

   cert = g_build_filename(guestProxyServerDir, "cert.pem", NULL);
   if (!g_file_test(cert, G_FILE_TEST_IS_REGULAR)) {
      Error("Couldn't find the server certificate file: %s.\n", cert);
      goto exit;
   }

   if (serverCertPemFile && strlen(serverCertPemFile)) {
      printf("Copying the server certificate to %s.\n", serverCertPemFile);

      if (!CertUtil_CopyFile(cert, serverCertPemFile)) {
         Error("Failed to copy the certificate file to the file.\n");
         goto exit;
      }
      printf("Successfully copied the server certificate.\n");

   } else {

      fmap = g_mapped_file_new(cert, FALSE, NULL);
      if (fmap) {

         const gchar *content = g_mapped_file_get_contents(fmap);
         gsize length = g_mapped_file_get_length(fmap);

         if (fwrite(content, 1, length, stdout) < length) {
            Error("Failed to display %s: %s.\n", cert, strerror(errno));
            goto exit;
         }
      } else {
         Error("Couldn't open the server certificate file.\n");
         goto exit;
      }
   }

   ret = TRUE;

exit:
   g_free(cert);
   if (file) {
      fclose(file);
   }
   if (fmap) {
      g_mapped_file_unref(fmap);
   }

   return ret;
}
static void
file_free (RemoteDisplayHostFile *file)
{
	g_free (file->uri);
	g_free (file->path);
	g_free (file->mime_type);
	g_mapped_file_unref (file->mapped_file);
	g_free (file);
}
Exemple #17
0
void
rgbe_file_free (rgbe_file *file)
{
  if (!file)
      return;

  g_mapped_file_unref (file->file);
  file->scanlines = NULL;

  g_free (file);
}
Exemple #18
0
void
db_parse_context_destroy (DBParseContext *ctx) 
{
	g_return_if_fail (ctx != NULL);

	if (ctx->mapped_file) {
		g_mapped_file_unref(ctx->mapped_file);
	}

	g_free (ctx);
}
Exemple #19
0
void
kml_free(struct kml *kml)
{

	if (NULL == kml)
		return;

	g_list_free_full(kml->kmls, kmlparse_free);

	if (NULL != kml->file)
		g_mapped_file_unref(kml->file);
}
static void
sim_timezone_impl_finalize (GObject  *gobject)
{
    SimTimezone * timezone = SIM_TIMEZONE (gobject);

    g_free (timezone->_priv->name);
    g_mapped_file_unref (timezone->_priv->zoneinfo);

    g_free (timezone->_priv);
    G_OBJECT_CLASS (parent_class)->finalize (gobject);
    return;
}
Exemple #21
0
static void prv_soup_message_finished_cb(SoupMessage *msg, gpointer user_data)
{
	dlr_host_file_t *hf = user_data;

	if (hf->mapped_count > 0) {
		g_mapped_file_unref(hf->mapped_file);
		--hf->mapped_count;

		if (hf->mapped_count == 0)
			hf->mapped_file = NULL;
	}
}
static void
send_login_html (CockpitWebResponse *response,
                 CockpitHandlerData *ws)
{
  GHashTable *headers = NULL;
  GList *l, *output = NULL;
  gchar *login_html;
  GMappedFile *file;
  GError *error = NULL;
  GBytes *body = NULL;
  gsize length;

  login_html = g_build_filename (ws->static_roots[0], "login.html", NULL);
  file = g_mapped_file_new (login_html, FALSE, &error);
  if (file == NULL)
    {
      g_warning ("%s: %s", login_html, error->message);
      cockpit_web_response_error (response, 500, NULL, NULL);
      g_clear_error (&error);
      goto out;
    }

  body = g_mapped_file_get_bytes (file);
  output = cockpit_template_expand (body, substitute_environment, ws->os_release);

  length = 0;
  for (l = output; l != NULL; l = g_list_next (l))
    length += g_bytes_get_size (l->data);

  headers = cockpit_web_server_new_table ();
  g_hash_table_insert (headers, g_strdup ("Content-Type"), g_strdup ("text/html; charset=utf8"));

  cockpit_web_response_headers_full (response, 200, "OK", length, headers);

  for (l = output; l != NULL; l = g_list_next (l))
    {
      if (!cockpit_web_response_queue (response, l->data))
        break;
    }
  if (l == NULL)
    cockpit_web_response_complete (response);

out:
  g_list_free_full (output, (GDestroyNotify)g_bytes_unref);
  if (headers)
    g_hash_table_unref (headers);
  g_free (login_html);
  if (body)
    g_bytes_unref (body);
  if (file)
    g_mapped_file_unref (file);
}
Exemple #23
0
gboolean xr_server_simple(const char* cert, const char* privkey, int threads, const char* bind, xr_servlet_def** servlets, GError** err)
{
  GError *local_err= NULL;

  GMappedFile *cert_file = g_mapped_file_new(cert, FALSE, &local_err);
  if (local_err)
  {
    g_propagate_prefixed_error(err, local_err, "Certificate load failed: ");
    g_mapped_file_unref(cert_file);
    return FALSE;
  }

  gchar *cert_pem = g_mapped_file_get_contents(cert_file);

  gchar *privkey_pem = NULL;
  GMappedFile *privkey_file = NULL;
  if (privkey)
  {
    privkey_file = g_mapped_file_new(privkey, FALSE, &local_err);
    if (local_err)
    {
      g_free(cert_pem);
      g_propagate_prefixed_error(err, local_err, "Certificate load failed: ");
      g_mapped_file_unref(privkey_file);
      g_mapped_file_unref(cert_file);
      return FALSE;
    }

    privkey_pem = g_mapped_file_get_contents(privkey_file);
  }

  gboolean retval = xr_server_simple_pem(cert_pem, privkey_pem, threads, bind, servlets, err);

  g_mapped_file_unref(cert_file);
  g_mapped_file_unref(privkey_file);

  return retval;
}
Exemple #24
0
DBParseContext *
db_parse_context_new_from_file (const char *filename, Itdb_DB *db)
{
	DBParseContext *ctx;
	Itdb_Device *device;
	GError* error;
	GMappedFile* mapped_file;
	struct stat stat_buf;

	ctx = NULL;
	error = NULL;
	mapped_file = NULL;

	device = db_get_device (db);
	g_return_val_if_fail (device, NULL);

	if (g_stat (filename, &stat_buf) != 0) {
		return NULL;	
	};
	if (stat_buf.st_size > 64 * 1024 * 1024) {
		g_warning ("%s is too big to be mmapped (%llu bytes)\n",
			   filename, (unsigned long long)stat_buf.st_size);
		return NULL;
	}

	mapped_file = g_mapped_file_new(filename, FALSE, &error);
	
	if (mapped_file == NULL) {
		g_print ("Error while mapping %s: %s\n", filename, 
                    error->message);
		g_error_free(error);
		return NULL;
	}

	if (device->byte_order == 0)
	    itdb_device_autodetect_endianess (device);

	ctx = db_parse_context_new ((guchar *)g_mapped_file_get_contents(mapped_file),
					g_mapped_file_get_length(mapped_file), 
					device->byte_order);

	if (ctx == NULL) {
		g_mapped_file_unref(mapped_file);
		return NULL;
	}
	ctx->db = db;
	ctx->mapped_file = mapped_file;

        return ctx;
}
Exemple #25
0
void
gtk_icon_cache_unref (GtkIconCache *cache)
{
  cache->ref_count --;

  if (cache->ref_count == 0)
    {
      GTK_NOTE (ICONTHEME, g_message ("unmapping icon cache"));

      if (cache->map)
	g_mapped_file_unref (cache->map);
      g_free (cache);
    }
}
Exemple #26
0
static void
set_indenter (EditorApplicationWindow *window, const gchar *filename)
{
  GMappedFile *mapped_file;
  smie_symbol_pool_t *pool;
  smie_prec2_grammar_t *prec2;
  smie_grammar_t *grammar;
  const gchar *contents;
  GError *error;

  error = NULL;
  mapped_file = g_mapped_file_new (filename, FALSE, &error);
  if (!mapped_file)
    {
      g_warning ("Error while loading the file: %s", error->message);
      g_error_free (error);
      return;
    }

  pool = smie_symbol_pool_alloc ();
  error = NULL;
  contents = (const gchar *) g_mapped_file_get_contents (mapped_file);
  prec2 = smie_prec2_grammar_load (contents, &error);
  g_mapped_file_unref (mapped_file);
  if (!prec2)
    {
      g_warning ("Error while loading the grammar: %s", error->message);
      g_error_free (error);
      smie_symbol_pool_unref (pool);
      return;
    }

  error = NULL;
  grammar = smie_prec2_to_grammar (prec2, &error);
  smie_prec2_grammar_free (prec2);
  if (!grammar)
    {
      g_warning ("Error while converting prec2 to grammar: %s", error->message);
      g_error_free (error);
      smie_symbol_pool_unref (pool);
      smie_grammar_free (grammar);
      return;
    }

  window->indenter
    = smie_indenter_new (grammar,
			 &smie_gtk_source_buffer_cursor_functions,
			 &editor_rules);
}
Exemple #27
0
/* filecmp:
 */
static gint filecmp ( const gchar *fname1,
                      const gchar *fname2 )
{
  struct stat s1, s2;
  GMappedFile *m1, *m2;
  gint r;
  GError *error = NULL;
  if (stat(fname1, &s1) != 0)
    CL_ERROR("could not stat '%s' : %s", fname1, strerror(errno));
  if (stat(fname2, &s2) != 0)
    CL_ERROR("could not stat '%s' : %s", fname2, strerror(errno));
  if (s1.st_size != s2.st_size)
    return 1;
  if (!(m1 = g_mapped_file_new(fname1, FALSE, &error)))
    CL_ERROR("could not open '%s' : %s", fname1, error->message);
  if (!(m2 = g_mapped_file_new(fname2, FALSE, &error)))
    CL_ERROR("could not open '%s' : %s", fname2, error->message);
  r = memcmp(g_mapped_file_get_contents(m1),
             g_mapped_file_get_contents(m2),
             s1.st_size);
  g_mapped_file_unref(m1);
  g_mapped_file_unref(m2);
  return r;
}
static void prv_host_file_delete(gpointer host_file)
{
	rsu_host_file_t *hf = host_file;
	unsigned int i;

	if (hf) {
		g_free(hf->path);
		for (i = 0; i < hf->mapped_count; ++i)
			g_mapped_file_unref(hf->mapped_file);

		g_ptr_array_unref(hf->clients);

		g_free(hf->mime_type);
		g_free(hf);
	}
}
Exemple #29
0
void
test_http_unref(
    TestHttp* http)
{
    if (http) {
        MMS_ASSERT(http->ref_count > 0);
        if (g_atomic_int_dec_and_test(&http->ref_count)) {
            test_http_close(http);
            if (http->resp_file) g_mapped_file_unref(http->resp_file);
            if (http->req_bytes) g_bytes_unref(http->req_bytes);
            g_object_unref(http->server);
            g_free(http->resp_content_type);
            g_free(http);
        }
    }
}
Exemple #30
0
static
void
test_finalize(
    Test* test)
{
    if (test->timeout_id) {
        g_source_remove(test->timeout_id);
        test->timeout_id = 0;
    }
    mms_connman_test_close_connection(test->cm);
    mms_connman_unref(test->cm);
    mms_handler_unref(test->handler);
    mms_dispatcher_unref(test->disp);
    g_main_loop_unref(test->loop);
    g_mapped_file_unref(test->notification_ind);
    g_free(test->id);
}