GString *save_as_temp_file(void) { gchar *write_buffer = NULL; gsize text_length; gint status; gchar *rawfilename; GString *filename; int file_handle; file_handle = g_file_open_tmp("gphpeditXXXXXX",&rawfilename,NULL); if (file_handle != -1) { filename = g_string_new(rawfilename); text_length = gtk_scintilla_get_length(GTK_SCINTILLA(main_window.current_editor->scintilla)); write_buffer = g_malloc0(text_length+1); // Include terminating null if (write_buffer == NULL) { g_warning ("%s", _("Cannot allocate write buffer")); return NULL; } gtk_scintilla_get_text(GTK_SCINTILLA(main_window.current_editor->scintilla), text_length+1, write_buffer); status = write (file_handle, write_buffer, text_length+1); g_free (write_buffer); g_free(rawfilename); close(file_handle); return filename; } return NULL; }
/* * FIXME xpm loading progressively is not properly implemented. * Instead we will buffer to a file then load that file when done. * This is very broken but it should be relayively simple to fix * in the future. */ static gpointer gdk_pixbuf__xpm_image_begin_load (GdkPixbufModuleSizeFunc size_func, GdkPixbufModulePreparedFunc prepare_func, GdkPixbufModuleUpdatedFunc update_func, gpointer user_data, GError **error) { XPMContext *context; gint fd; context = g_new (XPMContext, 1); context->prepare_func = prepare_func; context->update_func = update_func; context->user_data = user_data; context->all_okay = TRUE; fd = g_file_open_tmp ("gdkpixbuf-xpm-tmp.XXXXXX", &context->tempname, NULL); if (fd < 0) { g_free (context); return NULL; } context->file = fdopen (fd, "w+"); if (context->file == NULL) { g_free (context->tempname); g_free (context); return NULL; } return context; }
/** * a_babel_convert_from_shellcommand: * @vt: The #VikTrwLayer where to insert the collected data * @input_cmd: the command to run * @input_file_type: * @cb: Optional callback function. Same usage as in a_babel_convert(). * @user_data: passed along to cb * @not_used: Must use NULL * * Runs the input command in a shell (bash) and optionally uses GPSBabel to convert from input_file_type. * If input_file_type is %NULL, doesn't use GPSBabel. Input must be GPX (or Geocaching *.loc) * * Uses babel_general_convert_from() to actually run the command. This function * prepares the command and temporary file, and sets up the arguments for bash. */ gboolean a_babel_convert_from_shellcommand ( VikTrwLayer *vt, const char *input_cmd, const char *input_file_type, BabelStatusFunc cb, gpointer user_data, gpointer not_used ) { int fd_dst; gchar *name_dst = NULL; gboolean ret = FALSE; gchar **args; if ((fd_dst = g_file_open_tmp("tmp-viking.XXXXXX", &name_dst, NULL)) >= 0) { g_debug ("%s: temporary file: %s", __FUNCTION__, name_dst); gchar *shell_command; if ( input_file_type ) shell_command = g_strdup_printf("%s | %s -i %s -f - -o gpx -F %s", input_cmd, gpsbabel_loc, input_file_type, name_dst); else shell_command = g_strdup_printf("%s > %s", input_cmd, name_dst); g_debug("%s: %s", __FUNCTION__, shell_command); close(fd_dst); args = g_malloc(sizeof(gchar *)*4); args[0] = BASH_LOCATION; args[1] = "-c"; args[2] = shell_command; args[3] = NULL; ret = babel_general_convert_from ( vt, cb, args, name_dst, user_data ); g_free ( args ); g_free ( shell_command ); (void)g_remove(name_dst); g_free(name_dst); } return ret; }
static FILE* ice_tmpfile (char **name) { GError *error = NULL; mode_t mode; FILE *fp = NULL; int fd; mode = umask (0077); fd = g_file_open_tmp(".xfsm-ICE-XXXXXX", name, &error); if (fd < 0) { g_warning ("Unable to open temporary file: %s", error->message); g_error_free (error); } else { fp = fdopen (fd, "wb"); } umask (mode); return fp; }
static void instantsave_document_new_cb(GObject *obj, GeanyDocument *doc, gpointer user_data) { if (enable_instantsave && doc->file_name == NULL) { gchar *new_filename; gint fd; GeanyFiletype *ft = doc->file_type; fd = g_file_open_tmp("gis_XXXXXX", &new_filename, NULL); if (fd != -1) close(fd); /* close the returned file descriptor as we only need the filename */ if (ft == NULL || ft->id == GEANY_FILETYPES_NONE) /* ft is NULL when a new file without template was opened, so use the * configured default file type */ ft = filetypes_lookup_by_name(instantsave_default_ft); if (ft != NULL) /* add the filetype's default extension to the new filename */ SETPTR(new_filename, g_strconcat(new_filename, ".", ft->extension, NULL)); doc->file_name = new_filename; if (doc->file_type->id == GEANY_FILETYPES_NONE) document_set_filetype(doc, filetypes_lookup_by_name(instantsave_default_ft)); /* force saving the file to enable all the related actions(tab name, filetype, etc.) */ document_save_file(doc, TRUE); } }
/** * Creates a temporary file with given content. * * Upon success, and if file is non-NULL, the actual file path used is * returned in file. This string should be freed with g_free() when not * needed any longer. */ gboolean util_create_tmp_file(const char *content, char **file) { int fp; ssize_t bytes, len; fp = g_file_open_tmp(PROJECT "-XXXXXX", file, NULL); if (fp == -1) { g_critical("Could not create temp file %s", *file); g_free(*file); return false; } len = strlen(content); /* write content into temporary file */ bytes = write(fp, content, len); if (bytes < len) { close(fp); unlink(*file); g_critical("Could not write temp file %s", *file); g_free(*file); return false; } close(fp); return true; }
static bool theme_install_read(const char *data, unsigned long len) { char *filename, *newfilename; size_t namelen; int handle = g_file_open_tmp("nsgtkthemeXXXXXX", &filename, NULL); if (handle == -1) { warn_user(messages_get("gtkFileError"), "temporary theme file"); return false; } ssize_t written = write(handle, data, len); close(handle); if ((unsigned)written != len) return false; /* get name of theme; set as dirname */ namelen = SLEN("themes/") + strlen(res_dir_location) + 1; char dirname[namelen]; snprintf(dirname, namelen, "%sthemes/", res_dir_location); /* save individual files in theme */ newfilename = container_extract_theme(filename, dirname); g_free(filename); if (newfilename == NULL) return false; nsgtk_theme_add(newfilename); free(newfilename); return true; }
/** * a_download_url_to_tmp_file: * @uri: The URI (Uniform Resource Identifier) * @options: Download options (maybe NULL) * * returns name of the temporary file created - NULL if unsuccessful * this string needs to be freed once used * the file needs to be removed once used */ gchar *a_download_uri_to_tmp_file ( const gchar *uri, DownloadFileOptions *options ) { FILE *tmp_file; int tmp_fd; gchar *tmpname; if ( (tmp_fd = g_file_open_tmp ("viking-download.XXXXXX", &tmpname, NULL)) == -1 ) { g_critical (_("couldn't open temp file")); return NULL; } tmp_file = fdopen(tmp_fd, "r+"); if ( !tmp_file ) return NULL; if ( curl_download_uri ( uri, tmp_file, options, NULL, NULL ) ) { // error fclose ( tmp_file ); (void)g_remove ( tmpname ); g_free ( tmpname ); return NULL; } fclose ( tmp_file ); return tmpname; }
void rspamd_async_test_func () { struct aio_context *aio_ctx; gchar *tmpfile; static gchar testbuf[BUFSIZ]; gint fd, afd, ret; aio_ctx = rspamd_aio_init (base); g_assert (aio_ctx != NULL); fd = g_file_open_tmp ("raXXXXXX", &tmpfile, NULL); g_assert (fd != -1); afd = rspamd_aio_open (aio_ctx, tmpfile, O_RDWR); g_assert (fd != -1); /* Write some data */ memset (testbuf, 0xef, sizeof (testbuf)); ret = rspamd_aio_write (afd, testbuf, sizeof (testbuf), 0, aio_ctx, aio_write_cb, aio_ctx); g_assert (ret != -1); event_base_loop (base, 0); close (afd); close (fd); unlink (tmpfile); }
static void save_greeter_settings (void) { char *str, *tfname; char buffer[256]; GKeyFile *kf; gsize len; gint handle; // read in data from file to a key file kf = g_key_file_new (); if (!g_key_file_load_from_file (kf, GREETER_CONFIG_FILE, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL)) return; // update changed values in the key file sprintf (buffer, "%s", gdk_color_to_string (&desktop_colour)); g_key_file_set_string (kf, "greeter", "desktop_bg", buffer); g_key_file_set_string (kf, "greeter", "wallpaper", desktop_picture); g_key_file_set_string (kf, "greeter", "wallpaper_mode", desktop_mode); g_key_file_set_string (kf, "greeter", "gtk-font-name", desktop_font); g_key_file_set_string (kf, "greeter", "gtk-theme-name", "PiX"); g_key_file_set_string (kf, "greeter", "gtk-icon-theme-name", "PiX"); // write the modified key file out to a temp file str = g_key_file_to_data (kf, &len, NULL); handle = g_file_open_tmp ("XXXXXX", &tfname, NULL); write (handle, str, len); close (handle); g_free (str); // copy the temp file to the correct place with sudo sprintf (buffer, "sudo cp %s %s", tfname, GREETER_CONFIG_FILE); system (buffer); }
static void dump_aml_files(test_data *data, bool rebuild) { AcpiSdtTable *sdt; GError *error = NULL; gchar *aml_file = NULL; gint fd; ssize_t ret; int i; for (i = 0; i < data->tables->len; ++i) { const char *ext = data->variant ? data->variant : ""; sdt = &g_array_index(data->tables, AcpiSdtTable, i); g_assert(sdt->aml); if (rebuild) { aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine, (gchar *)&sdt->header.signature, ext); fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); } else { fd = g_file_open_tmp("aml-XXXXXX", &sdt->aml_file, &error); g_assert_no_error(error); } g_assert(fd >= 0); ret = qemu_write_full(fd, sdt, sizeof(AcpiTableHeader)); g_assert(ret == sizeof(AcpiTableHeader)); ret = qemu_write_full(fd, sdt->aml, sdt->aml_len); g_assert(ret == sdt->aml_len); close(fd); g_free(aml_file); } }
static void test_secret_indirect_emptyfile(void) { Object *sec; char *fname = NULL; int fd = g_file_open_tmp("qemu-test-crypto-secretXXXXXX", &fname, NULL); g_assert(fd >= 0); g_assert_nonnull(fname); sec = object_new_with_props( TYPE_QCRYPTO_SECRET, object_get_objects_root(), "sec0", &error_abort, "file", fname, NULL); char *pw = qcrypto_secret_lookup_as_utf8("sec0", &error_abort); g_assert_cmpstr(pw, ==, ""); object_unparent(sec); g_free(pw); close(fd); unlink(fname); g_free(fname); }
static void xmr_service_init(XmrService *xs) { XmrServicePrivate *priv; xs->priv = XMR_SERVICE_GET_PRIVATE(xs); priv = xs->priv; priv->logged = FALSE; priv->usr_id = NULL; priv->usr_name = NULL; priv->cookie = NULL; { gint fd = g_file_open_tmp(NULL, &priv->cookie, NULL); if (fd != -1) close(fd); } priv->curl = curl_easy_init(); if (priv->curl) { curl_easy_setopt(priv->curl, CURLOPT_USERAGENT, XMR_USER_AGENT); curl_easy_setopt(priv->curl, CURLOPT_CONNECTTIMEOUT, 10); curl_easy_setopt(priv->curl, CURLOPT_NOSIGNAL, 1L); } }
/** * sp_memfd_create: * @name: (nullable): A descriptive name for the memfd or %NULL * * Creates a new memfd using the memfd_create syscall if available. * Otherwise, a tmpfile is used. Currently, no attempt is made to * ensure the tmpfile is on a tmpfs backed mount. * * Returns: An fd if successful; otherwise -1 and errno is set. */ int sp_memfd_create (const gchar *name) { #ifdef __NR_memfd_create if (name == NULL) name = "[sysprof]"; return syscall (__NR_memfd_create, name, 0); #else gchar *name_used = NULL; int fd; /* * TODO: It would be nice to ensure tmpfs * * It is not strictly required that the preferred temporary directory * will be mounted as tmpfs. We should look through the mounts and ensure * that the tmpfile we open is on tmpfs so that we get anonymous backed * pages after unlinking. */ fd = g_file_open_tmp (NULL, &name_used, NULL); if (name_used != NULL) { g_unlink (name_used); g_free (name_used); } return fd; #endif }
int S52_utils_initLog(S52_log_cb log_cb) // set print handler // set tmp log file { //_shm_fd = shm_open(_shm_name, O_RDWR | O_CREAT | O_TRUNC, 0644 ); // debug - setup trace log //g_setenv("MALLOC_TRACE", "mem.log", TRUE); if (NULL != log_cb) { log_cb("S52_utils_initLog(): init logging\n"); _log_cb = log_cb; } #ifdef S52_USE_LOGFILE GError *error = NULL; _logFile = g_file_open_tmp("XXXXXX", NULL, &error); if (-1 == _logFile) { PRINTF("WARNING: g_file_open_tmp(): failed\n"); } else { PRINTF("DEBUG: logfile tmp dir:%s\n", g_get_tmp_dir()); } if (NULL != error) { g_printf("WARNING: g_file_open_tmp() failed (%s)\n", error->message); g_error_free(error); } _oldPrintHandler = g_set_print_handler(_S52_printf); #else PRINTF("DEBUG: no LOGFILE, compiler flags 'S52_USE_LOGFILE' not set\n"); #endif // S52_USE_LOGFILE return TRUE; }
static void outputtest_setup(Outputtest *outputtest, G_GNUC_UNUSED gconstpointer test_data) { int fd; fd = g_file_open_tmp(TMP_FILE_PATTERN, &(outputtest->tmp_filename), NULL); close(fd); }
static void _open (int flags) { int fd = g_file_open_tmp ("t_s4-XXXXXX", &name, NULL); g_close (fd, NULL); g_unlink (name); s4 = s4_open (name, NULL, flags); }
static void pgd_action_view_play_rendition (GtkWidget *button, PopplerMedia *media) { GFile *file = NULL; gchar *uri; if (poppler_media_is_embedded (media)) { gint fd; gchar *tmp_filename = NULL; fd = g_file_open_tmp (NULL, &tmp_filename, NULL); if (fd != -1) { if (poppler_media_save_to_callback (media, save_helper, GINT_TO_POINTER (fd), NULL)) { file = g_file_new_for_path (tmp_filename); g_object_set_data_full (G_OBJECT (media), "tmp-file", g_object_ref (file), (GDestroyNotify)free_tmp_file); } else { g_free (tmp_filename); } close (fd); } else if (tmp_filename) { g_free (tmp_filename); } } else { const gchar *filename; filename = poppler_media_get_filename (media); if (g_path_is_absolute (filename)) { file = g_file_new_for_path (filename); } else if (g_strrstr (filename, "://")) { file = g_file_new_for_uri (filename); } else { gchar *cwd; gchar *path; // FIXME: relative to doc uri, not cwd cwd = g_get_current_dir (); path = g_build_filename (cwd, filename, NULL); g_free (cwd); file = g_file_new_for_path (path); g_free (path); } } if (file) { uri = g_file_get_uri (file); g_object_unref (file); if (uri) { gtk_show_uri (gtk_widget_get_screen (button), uri, GDK_CURRENT_TIME, NULL); g_free (uri); } } }
static void _dae_draw(DiagramAsElement *dae, DiaRenderer *renderer) { DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer); Element *elem = &dae->element; if (!dae->data) { /* just draw the box */ Point lower_right = { elem->corner.x + elem->width, elem->corner.y + elem->height }; renderer_ops->draw_rect(renderer,&elem->corner, &lower_right, &dae->border_color); } else { if (FALSE) { /* if the renderer supports transformations ... */ /* temporary messing with it (not enough) */ dae->data->paper.scaling *= dae->scale; data_render (dae->data, DIA_RENDERER (renderer), NULL, NULL, NULL); dae->data->paper.scaling /= dae->scale; } else { /* we have to render to an image and draw that */ if (!dae->image) { /* lazy creation */ gchar *imgfname = NULL; gint fd = g_file_open_tmp ("diagram-as-elementXXXXXX.png", &imgfname, NULL); if (fd != -1) { DiaExportFilter *ef = filter_export_get_by_name ("cairo-alpha-png"); if (!ef) /* prefer cairo with alpha, but don't require it */ ef = filter_guess_export_filter (imgfname); close(fd); if (ef) { DiaContext *ctx = dia_context_new ("Diagram as Object"); dia_context_set_filename (ctx, imgfname); if (ef->export_func (dae->data, ctx, imgfname, dae->filename, ef->user_data)) { DiaImage *tmp_image = dia_image_load (imgfname); /* some extra gymnastics to create an image w/o filename */ if (tmp_image) { dae->image = dia_image_new_from_pixbuf ((GdkPixbuf *)dia_image_pixbuf (tmp_image)); g_object_unref (tmp_image); } /* FIXME: where to put the message in case of an error? */ dia_context_release (ctx); } } /* found a filter */ g_unlink (imgfname); g_free (imgfname); } /* temporary file created*/ } /* only if we have no image yet */ if (dae->image) renderer_ops->draw_image (renderer, &elem->corner, elem->width, elem->height, dae->image); } } }
RESULT test_open_tmp () { GError *error; gint fd; gchar *name = GINT_TO_POINTER (-1); /* * Okay, this works, but creates a .xxx file in /tmp on every run. Disabled. * fd = g_file_open_tmp (NULL, NULL, NULL); * if (fd < 0) * return FAILED ("Default failed."); * close (fd); */ error = NULL; fd = g_file_open_tmp ("invalidtemplate", NULL, &error); if (fd != -1) return FAILED ("The template was invalid and accepted"); if (error == NULL) return FAILED ("No error returned."); g_error_free (error); error = NULL; fd = g_file_open_tmp ("i/nvalidtemplate", &name, &error); if (fd != -1) return FAILED ("The template was invalid and accepted"); if (error == NULL) return FAILED ("No error returned."); if (name == NULL) return FAILED ("'name' is not reset"); g_error_free (error); error = NULL; fd = g_file_open_tmp ("valid-XXXXXX", &name, &error); if (fd == -1) return FAILED ("This should be valid"); if (error != NULL) return FAILED ("No error returned."); if (name == NULL) return FAILED ("No name returned."); close (fd); unlink (name); g_free (name); return OK; }
static void test_open_and_close (void) { ThriftTransport *transport; ThriftTransportClass *klass; GError *error; gint fd; gchar *filename; error = NULL; filename = NULL; fd = g_file_open_tmp (NULL, &filename, &error); g_assert (fd >= 0); transport = THRIFT_TRANSPORT (g_object_new (THRIFT_TYPE_FD_TRANSPORT, "fd", fd, NULL)); klass = THRIFT_TRANSPORT_GET_CLASS (transport); /* open is no-op */ g_assert (klass->is_open (transport)); g_assert (klass->peek (transport, &error)); g_assert (klass->open (transport, &error)); g_assert (klass->is_open (transport)); g_assert (klass->peek (transport, &error)); g_assert (klass->close (transport, &error)); g_assert (! klass->open (transport, &error)); g_assert (! klass->is_open (transport)); g_assert (! klass->peek (transport, &error)); /* already closed */ g_assert (close (fd) != 0); g_assert (errno == EBADF); g_object_unref (transport); g_remove (filename); g_free (filename); /* test bad fd */ transport = THRIFT_TRANSPORT (g_object_new (THRIFT_TYPE_FD_TRANSPORT, "fd", -1, NULL)); klass = THRIFT_TRANSPORT_GET_CLASS (transport); g_assert (! klass->is_open (transport)); error = NULL; g_assert (! klass->peek (transport, &error)); error = NULL; g_assert (! klass->open (transport, &error)); error = NULL; g_assert (! klass->close (transport, &error)); g_object_unref (transport); }
static void _dt_sigsegv_handler(int param) { pid_t pid; gchar *name_used; int fout; gboolean delete_file = FALSE; char datadir[PATH_MAX] = { 0 }; if((fout = g_file_open_tmp("darktable_bt_XXXXXX.txt", &name_used, NULL)) == -1) fout = STDOUT_FILENO; // just print everything to stdout dprintf(fout, "this is %s reporting a segfault:\n\n", PACKAGE_STRING); if(fout != STDOUT_FILENO) close(fout); dt_loc_get_datadir(datadir, sizeof(datadir)); gchar *pid_arg = g_strdup_printf("%d", (int)getpid()); gchar *comm_arg = g_strdup_printf("%s/gdb_commands", datadir); gchar *log_arg = g_strdup_printf("set logging on %s", name_used); if((pid = fork()) != -1) { if(pid) { #ifdef __linux__ // Allow the child to ptrace us prctl(PR_SET_PTRACER, pid, 0, 0, 0); #endif waitpid(pid, NULL, 0); g_printerr("backtrace written to %s\n", name_used); } else { if(execlp("gdb", "gdb", darktable.progname, pid_arg, "-batch", "-ex", log_arg, "-x", comm_arg, NULL)) { delete_file = TRUE; g_printerr("an error occurred while trying to execute gdb. please check if gdb is installed on your " "system.\n"); } } } else { delete_file = TRUE; g_printerr("an error occurred while trying to execute gdb.\n"); } if(delete_file) g_unlink(name_used); g_free(pid_arg); g_free(comm_arg); g_free(log_arg); g_free(name_used); /* pass it further to the old handler*/ _dt_sigsegv_old_handler(param); }
/** * a_babel_convert_from_filter: * @vt: The TRW layer to place data into. Duplicate items will be overwritten. * @babelargs: A string containing gpsbabel command line options. This string * must include the input file type (-i) option. * @from the file name to convert from * @babelfilters: A string containing gpsbabel filter command line options * @cb: Optional callback function. Same usage as in a_babel_convert(). * @user_data: passed along to cb * @not_used: Must use NULL * * Loads data into a trw layer from a file, using gpsbabel. This routine is synchronous; * that is, it will block the calling program until the conversion is done. To avoid blocking, call * this routine from a worker thread. * * Returns: %TRUE on success */ gboolean a_babel_convert_from_filter( VikTrwLayer *vt, const char *babelargs, const char *from, const char *babelfilters, BabelStatusFunc cb, gpointer user_data, gpointer not_used ) { int i,j; int fd_dst; gchar *name_dst = NULL; gboolean ret = FALSE; gchar *args[64]; if ((fd_dst = g_file_open_tmp("tmp-viking.XXXXXX", &name_dst, NULL)) >= 0) { g_debug ("%s: temporary file: %s", __FUNCTION__, name_dst); close(fd_dst); if (gpsbabel_loc ) { gchar **sub_args = g_strsplit(babelargs, " ", 0); gchar **sub_filters = NULL; i = 0; if (unbuffer_loc) args[i++] = unbuffer_loc; args[i++] = gpsbabel_loc; for (j = 0; sub_args[j]; j++) { /* some version of gpsbabel can not take extra blank arg */ if (sub_args[j][0] != '\0') args[i++] = sub_args[j]; } args[i++] = "-f"; args[i++] = (char *)from; if (babelfilters) { sub_filters = g_strsplit(babelfilters, " ", 0); for (j = 0; sub_filters[j]; j++) { /* some version of gpsbabel can not take extra blank arg */ if (sub_filters[j][0] != '\0') args[i++] = sub_filters[j]; } } args[i++] = "-o"; args[i++] = "gpx"; args[i++] = "-F"; args[i++] = name_dst; args[i] = NULL; ret = babel_general_convert_from ( vt, cb, args, name_dst, user_data ); g_strfreev(sub_args); if (sub_filters) g_strfreev(sub_filters); } else g_critical("gpsbabel not found in PATH"); (void)g_remove(name_dst); g_free(name_dst); } return ret; }
static gboolean gnm_glpk_prepare (GnmSolver *sol, WorkbookControl *wbc, GError **err, GnmGlpk *lp) { gboolean ok; int fd; g_return_val_if_fail (sol->status == GNM_SOLVER_STATUS_READY, FALSE); gnm_solver_set_status (sol, GNM_SOLVER_STATUS_PREPARING); ok = write_program (sol, wbc, err); if (!ok) goto fail; fd = g_file_open_tmp ("program-XXXXXX.out", &lp->result_filename, err); if (fd == -1) { g_set_error (err, G_FILE_ERROR, 0, _("Failed to create file for solution")); goto fail; } close (fd); if (sol->params->options.sensitivity_report) { fd = g_file_open_tmp ("program-XXXXXX.ran", &lp->ranges_filename, err); if (fd == -1) { g_set_error (err, G_FILE_ERROR, 0, _("Failed to create file for sensitivity report")); goto fail; } close (fd); } gnm_solver_set_status (sol, GNM_SOLVER_STATUS_PREPARED); return TRUE; fail: gnm_glpk_cleanup (lp); gnm_solver_set_status (sol, GNM_SOLVER_STATUS_ERROR); return FALSE; }
static gchar *write_tmp_trwlayer ( VikTrwLayer *vtl ) { int fd_src; gchar *name_src; FILE *f; g_assert ((fd_src = g_file_open_tmp("tmp-viking.XXXXXX", &name_src, NULL)) >= 0); f = fdopen(fd_src, "w"); a_gpx_write_file(vtl, f); fclose(f); f = NULL; return name_src; }
/* TODO: write with name of old track */ static gchar *write_tmp_track ( VikTrack *track ) { int fd_src; gchar *name_src; FILE *f; g_assert ((fd_src = g_file_open_tmp("tmp-viking.XXXXXX", &name_src, NULL)) >= 0); f = fdopen(fd_src, "w"); a_gpx_write_track_file("track", track, f); /* Thank you Guilhem! Just when I needed this function... -- Evan */ fclose(f); f = NULL; return name_src; }
static void _dt_sigsegv_handler(int param) { FILE *fd; gchar buf[PIPE_BUF]; gchar *name_used; int fout; gboolean delete_file = FALSE; char datadir[DT_MAX_PATH_LEN]; if((fout = g_file_open_tmp("darktable_bt_XXXXXX.txt", &name_used, NULL)) == -1) fout = STDOUT_FILENO; // just print everything to stdout dprintf(fout, "this is %s reporting a segfault:\n\n", PACKAGE_STRING); dt_loc_get_datadir(datadir, DT_MAX_PATH_LEN); gchar *command = g_strdup_printf("gdb %s %d -batch -x %s/gdb_commands", darktable.progname, (int)getpid(), datadir); if((fd = popen(command, "r")) != NULL) { gboolean read_something = FALSE; while((fgets(buf, PIPE_BUF, fd)) != NULL) { read_something = TRUE; dprintf(fout, "%s", buf); } pclose(fd); if(fout != STDOUT_FILENO) { if(read_something) g_printerr("backtrace written to %s\n", name_used); else { delete_file = TRUE; g_printerr("an error occured while trying to execute gdb. please check if gdb is installed on your system.\n"); } } } else { delete_file = TRUE; g_printerr("an error occured while trying to execute gdb.\n"); } if(fout != STDOUT_FILENO) close(fout); if(delete_file) g_unlink(name_used); g_free(command); g_free(name_used); /* pass it further to the old handler*/ _dt_sigsegv_old_handler(param); }
gboolean website_update_games_database(HttpHelper* hh, const gchar* localfile, const gchar* fileurl, MudError** error) { gchar* tmpfile_templ = "mmXXXXXX"; gchar* tmpfile_name = NULL; int tmpfile = 0; int gmfile = 0; int ret = TRUE; GError* gerror = NULL; tmpfile = g_file_open_tmp (tmpfile_templ, &tmpfile_name, &gerror); if (tmpfile == -1) { g_free (tmpfile_name); *error = mud_cnv (gerror); return FALSE; } mdebug (DBG_GAMELIST, 0, "Using temp file: %s\n", tmpfile_name); ret = http_download (fileurl, tmpfile, hh); if( ret != CONNECT_OK ) { *error = mud_error_new (MUD_NETWORK_ERROR, ret, network_errmsg (ret)); ret = FALSE; } else { gmfile = open (localfile, O_WRONLY | O_CREAT | O_TRUNC, MUD_NEW_FILE_MODE); if (gmfile == -1) { *error = mud_error_new (MUD_NETWORK_ERROR, errno, strerror (errno)); close (tmpfile); ret = FALSE; } else { lseek (tmpfile, (off_t) 0, SEEK_SET); mdebug (DBG_GAMELIST, 0, "Uncompressing to %s...\n", localfile); ret = uncompress_file (tmpfile, gmfile, error); } } g_remove (tmpfile_name); // close (tmpfile); // closed in uncompress_file close (gmfile); g_free (tmpfile_name); return ret; }
void test_patterndb_tags_outside_of_rule() { patterndb = pattern_db_new(); messages = NULL; g_file_open_tmp("patterndbXXXXXX.xml", &filename, NULL); g_file_set_contents(filename, tag_outside_of_rule_skeleton, strlen(tag_outside_of_rule_skeleton), NULL); assert_false(pattern_db_reload_ruleset(patterndb, configuration, filename), "successfully loaded an invalid patterndb file"); _destroy_pattern_db(); }
static gchar *create_temp_file(const gchar *tpl) { gchar *name; gint fd; fd = g_file_open_tmp(tpl, &name, NULL); if (fd < 0) name = NULL; else close(fd); return name; }