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; }
static gboolean test_init( Test* test, const MMSConfig* config, const TestDesc* desc) { gboolean ok = FALSE; GError* error = NULL; const char* dir = desc->name; char* ni = g_strconcat(DATA_DIR, dir, "/", desc->ind_file, NULL); memset(test, 0, sizeof(*test)); test->config = config; test->notification_ind = g_mapped_file_new(ni, FALSE, &error); if (test->notification_ind) { test->desc = desc; test->cm = mms_connman_test_new(); test->handler = mms_handler_test_new(); test->disp = mms_dispatcher_new(config, test->cm, test->handler); test->loop = g_main_loop_new(NULL, FALSE); test->timeout_id = g_timeout_add_seconds(10, test_timeout, test); test->delegate.fn_done = test_done; mms_dispatcher_set_delegate(test->disp, &test->delegate); test->id = g_strdup(mms_handler_test_send_new(test->handler, "IMSI")); mms_handler_message_sent(test->handler, test->id, desc->mmsid); test->ret = RET_ERR; ok = TRUE; } else { MMS_ERR("%s", MMS_ERRMSG(error)); g_error_free(error); } g_free(ni); return ok; }
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); } }
/** * gimp_scanner_new_file: * @filename: * @error: * * Return value: * * Since: GIMP 2.4 **/ GScanner * gimp_scanner_new_file (const gchar *filename, GError **error) { GScanner *scanner; GMappedFile *file; 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) { if (error) { (*error)->domain = GIMP_CONFIG_ERROR; (*error)->code = ((*error)->code == G_FILE_ERROR_NOENT ? GIMP_CONFIG_ERROR_OPEN_ENOENT : GIMP_CONFIG_ERROR_OPEN); } return NULL; } /* gimp_scanner_new() takes a "name" for the scanner, not a filename */ scanner = gimp_scanner_new (gimp_filename_to_utf8 (filename), file, error); g_scanner_input_text (scanner, g_mapped_file_get_contents (file), g_mapped_file_get_length (file)); return scanner; }
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; }
/** * 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 ); } }
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; }
static GMappedFile * file_to_mmap (const char *location) { GFile *file; GMappedFile *mapped_file = NULL; char *path; GError *error = NULL; file = g_file_new_for_uri (location); /* NOTE: this is broken if original filename contains "%20" etc. This * is because g_file_get_path() will translate this to " ", etc. But * the filename really may have used "%20" (not " "). */ path = g_file_get_path (file); if (path == NULL) { g_warning ("Couldn't mmap %s: couldn't get path", path); g_object_unref (file); return mapped_file; } g_object_unref (file); mapped_file = g_mapped_file_new (path, FALSE, &error); if (mapped_file == NULL) { g_warning ("Unable to map file %s: %s", path, error->message); } g_free (path); return mapped_file; }
/*********************************************** * 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; }
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; }
static void server_callback (SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, SoupClientContext *client, gpointer user_data) { RemoteDisplayHost *host = user_data; RemoteDisplayHostPrivate *priv = GET_PRIVATE (host); RemoteDisplayHostFile *file; if (!client_allowed (host, client)) { g_debug ("Client %s not allowed", soup_client_context_get_host (client)); soup_message_set_status (msg, SOUP_STATUS_FORBIDDEN); return; } if (msg->method != SOUP_METHOD_GET && msg->method != SOUP_METHOD_HEAD) { g_debug ("Method is not GET or HEAD"); soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED); return; } if (path == NULL || *path != '/') { g_debug ("Invalid path '%s'requested", path); soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND); return; } file = g_hash_table_lookup (priv->files, path + 1); if (!file) { soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND); return; } if (!file->mapped_file) { file->mapped_file = g_mapped_file_new (file->path, FALSE, NULL); if (!file->mapped_file) { soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND); return; } } if (msg->method == SOUP_METHOD_GET) { soup_message_set_response (msg, file->mime_type, SOUP_MEMORY_STATIC, g_mapped_file_get_contents (file->mapped_file), g_mapped_file_get_length (file->mapped_file)); } else { soup_message_headers_set_content_type (msg->response_headers, file->mime_type, NULL); soup_message_headers_set_content_length (msg->response_headers, g_mapped_file_get_length (file->mapped_file)); } soup_message_set_status(msg, SOUP_STATUS_OK); }
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; }
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; }
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 gboolean test_init( Test* test, MMSConfig* config, const TestDesc* desc) { gboolean ok = FALSE; memset(test, 0, sizeof(*test)); if (desc->resp_file) { GError* error = NULL; char* f = g_strconcat(DATA_DIR, desc->name, "/", desc->resp_file, NULL); test->resp_file = g_mapped_file_new(f, FALSE, &error); if (!test->resp_file) { MMS_ERR("%s", MMS_ERRMSG(error)); g_error_free(error); } g_free(f); } if (!desc->resp_file || test->resp_file) { int i; guint port; MMSSettings* settings = mms_settings_default_new(config); test->parts = g_new0(MMSAttachmentInfo, desc->nparts); test->files = g_new0(char*, desc->nparts); for (i=0; i<desc->nparts; i++) { test->files[i] = g_strconcat(DATA_DIR, desc->name, "/", desc->parts[i].file_name, NULL); test->parts[i] = desc->parts[i]; test->parts[i].file_name = test->files[i]; } test->config = config; test->desc = desc; test->cm = mms_connman_test_new(); test->handler = mms_handler_test_new(); test->disp = mms_dispatcher_new(settings, test->cm, test->handler); test->loop = g_main_loop_new(NULL, FALSE); test->delegate.fn_done = test_done; mms_dispatcher_set_delegate(test->disp, &test->delegate); test->http = test_http_new(test->resp_file, desc->resp_type, desc->resp_status); port = test_http_get_port(test->http); mms_connman_test_set_port(test->cm, port, TRUE); if (desc->flags & TEST_FLAG_CANCEL) { mms_connman_test_set_connect_callback(test->cm, test_cancel, test); } if (desc->size_limit) { MMSSettingsSimData sim_settings; mms_settings_sim_data_default(&sim_settings); sim_settings.size_limit = desc->size_limit; mms_settings_set_sim_defaults(settings, NULL); mms_settings_set_sim_defaults(settings, &sim_settings); } mms_settings_unref(settings); test->ret = RET_ERR; ok = TRUE; }
static void prv_soup_server_cb(SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, SoupClientContext *client, gpointer user_data) { rsu_host_file_t *hf; rsu_host_server_t *hs = user_data; const gchar *file_name; SoupMessageHeaders *hdrs; if (msg->method != SOUP_METHOD_GET) { soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); goto on_error; } hf = prv_host_server_find_file(hs, path, &file_name); if (!hf) { soup_message_set_status(msg, SOUP_STATUS_NOT_FOUND); goto on_error; } if (hf->mapped_file) { g_mapped_file_ref(hf->mapped_file); ++hf->mapped_count; } else { hf->mapped_file = g_mapped_file_new(file_name, FALSE, NULL); if (!hf->mapped_file) { soup_message_set_status(msg, SOUP_STATUS_NOT_FOUND); goto on_error; } hf->mapped_count = 1; } g_signal_connect(msg, "finished", G_CALLBACK(prv_soup_message_finished_cb), hf); g_object_get(msg, "response-headers", &hdrs, NULL); /* TODO: Need to add the relevant DLNA headers */ /* soup_message_headers_append(hdrs, "contentFeatures.dlna.org", "DLNA.ORG_PN=PNG_LRG;DLNA.ORG_OP=01;"DLNA.ORG_FLAGS=00f00000000000000000000000000000"); soup_message_headers_append(hdrs, "Connection", "close"); */ soup_message_set_status(msg, SOUP_STATUS_OK); soup_message_set_response(msg, hf->mime_type, SOUP_MEMORY_STATIC, g_mapped_file_get_contents(hf->mapped_file), g_mapped_file_get_length(hf->mapped_file)); on_error: return; }
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); }
static gboolean rgbe_file_init (rgbe_file *file, const gchar *path) { g_return_val_if_fail (file != NULL, FALSE); rgbe_header_init (&file->header); file->file = g_mapped_file_new (path, FALSE, NULL); file->scanlines = NULL; return file->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); }
static gboolean start_decoder (App * app) { GstCaps *caps; app->file = g_mapped_file_new (app->file_name, FALSE, NULL); if (!app->file) return FALSE; app->file_size = g_mapped_file_get_length (app->file); app->file_data = (guint8 *) g_mapped_file_get_contents (app->file); if (!app->file_data) return FALSE; caps = caps_from_codec (app->codec); switch (app->codec) { case GST_VAAPI_CODEC_H264: app->decoder = gst_vaapi_decoder_h264_new (app->display, caps); break; #if USE_JPEG_DECODER case GST_VAAPI_CODEC_JPEG: app->decoder = gst_vaapi_decoder_jpeg_new (app->display, caps); break; #endif case GST_VAAPI_CODEC_MPEG2: app->decoder = gst_vaapi_decoder_mpeg2_new (app->display, caps); break; case GST_VAAPI_CODEC_MPEG4: app->decoder = gst_vaapi_decoder_mpeg4_new (app->display, caps); break; case GST_VAAPI_CODEC_VC1: app->decoder = gst_vaapi_decoder_vc1_new (app->display, caps); break; default: app->decoder = NULL; break; } if (!app->decoder) return FALSE; gst_vaapi_decoder_set_codec_state_changed_func (app->decoder, handle_decoder_state_changes, app); g_timer_start (app->timer); app->decoder_thread = g_thread_try_new ("Decoder Thread", decoder_thread, app, NULL); if (!app->decoder_thread) return FALSE; return TRUE; }
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_malloc(sizeof(dt_gpx_t)); memset(gpx, 0, 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; /* clenup and return gpx context */ g_markup_parse_context_free(ctx); 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); if (gpx) g_free(gpx); return NULL; }
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; }
static int compare_files(const gchar *f1, const gchar *f2) { GError *error = NULL; GMappedFile *file1 = NULL, *file2 = NULL; int err; file1 = g_mapped_file_new (f1, FALSE, &error); if (error != NULL) { file1 = NULL; err = -1; goto out_err; } file2 = g_mapped_file_new (f2, FALSE, &error); if (error != NULL) { file2 = NULL; err = -1; goto out_err; } /* Then update */ err = compare_data(g_mapped_file_get_contents (file1), g_mapped_file_get_length (file1), g_mapped_file_get_contents (file2), g_mapped_file_get_length (file2)); goto out; out_err: g_warning ("error opening file: %s",error->message); g_error_free (error); out: if (file1) g_mapped_file_free (file1); if (file2) g_mapped_file_free (file2); return err; }
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; }
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); }
/* 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; }
xmlDocPtr e_xml_parse_file (const char *filename) { xmlDocPtr result = NULL; GMappedFile *mapped_file; mapped_file = g_mapped_file_new (filename, FALSE, NULL); if (mapped_file) { result = xmlParseMemory (g_mapped_file_get_contents (mapped_file), g_mapped_file_get_length (mapped_file)); g_mapped_file_free (mapped_file); } return result; }
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; }
static JsonObject * read_package_manifest (const gchar *directory, const gchar *package) { JsonObject *manifest = NULL; GError *error = NULL; GMappedFile *mapped; gchar *filename; GBytes *bytes; filename = g_build_filename (directory, "manifest.json", NULL); mapped = g_mapped_file_new (filename, FALSE, &error); if (!mapped) { if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) g_debug ("no manifest found: %s", filename); else if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR)) g_message ("%s: %s", package, error->message); g_clear_error (&error); } else { if (!validate_package (package)) { g_warning ("package has invalid name: %s", package); } else { bytes = g_mapped_file_get_bytes (mapped); manifest = cockpit_json_parse_bytes (bytes, &error); g_bytes_unref (bytes); if (!manifest) { g_message ("%s: invalid manifest: %s", package, error->message); g_clear_error (&error); } } g_mapped_file_unref (mapped); } g_free (filename); return manifest; }