/* Make a temporary file name. The format parameter is something like "%s.jpg" * and will be expanded to something like "/tmp/vips-12-34587.jpg". * * You need to free the result. A real file will also be created, though we * delete it for you. */ char * vips__temp_name( const char *format ) { static int serial = 1; char file[FILENAME_MAX]; char file2[FILENAME_MAX]; char *name; int fd; vips_snprintf( file, FILENAME_MAX, "vips-%d-XXXXXX", serial++ ); vips_snprintf( file2, FILENAME_MAX, format, file ); name = g_build_filename( vips__temp_dir(), file2, NULL ); if( (fd = g_mkstemp( name )) == -1 ) { vips_error( "tempfile", _( "unable to make temporary file %s" ), name ); g_free( name ); return( NULL ); } close( fd ); g_unlink( name ); return( name ); }
static int load_svg( producer_pixbuf self, mlt_properties properties, const char *filename ) { int result = 0; // Read xml string if ( strstr( filename, "<svg" ) ) { // Generate a temporary file for the svg char fullname[ 1024 ] = "/tmp/mlt.XXXXXX"; int fd = g_mkstemp( fullname ); if ( fd > -1 ) { // Write the svg into the temp file ssize_t remaining_bytes; const char *xml = filename; // Strip leading crap while ( xml[0] != '<' ) xml++; remaining_bytes = strlen( xml ); while ( remaining_bytes > 0 ) remaining_bytes -= write( fd, xml + strlen( xml ) - remaining_bytes, remaining_bytes ); close( fd ); mlt_properties_set( self->filenames, "0", fullname ); // Teehe - when the producer closes, delete the temp file and the space allo mlt_properties_set_data( properties, "__temporary_file__", fullname, 0, ( mlt_destructor )unlink, NULL ); result = 1; } } return result; }
static char * create_file (const void *data, size_t length) { int f = -1; FILE *F = NULL; char *tmpname; tmpname = g_strdup ("/tmp/epsXXXXXX.eps"); if (!tmpname) goto error; f = g_mkstemp (tmpname); if (f == -1) goto error; F = fdopen (f, "w"); if (F == NULL) goto error; if (fwrite (data, length, 1, F) != 1) goto error; if (fclose (F) != 0) goto error; return tmpname; error: g_free (tmpname); if (F) fclose (F); else if (f != -1) close (f); return NULL; }
static gboolean begin_write_state (GkmMate2Storage *self, GkmTransaction *transaction) { g_assert (GKM_IS_MATE2_STORAGE (self)); g_assert (GKM_IS_TRANSACTION (transaction)); g_return_val_if_fail (!gkm_transaction_get_failed (transaction), FALSE); /* Already in write state for this transaction? */ if (self->transaction != NULL) { g_return_val_if_fail (self->transaction == transaction, FALSE); return TRUE; } /* Lock file for the transaction */ self->read_fd = begin_lock_file (self, transaction); if (self->read_fd == -1) return FALSE; gkm_transaction_add (transaction, self, complete_write_state, NULL); self->transaction = g_object_ref (transaction); /* Open the new file */ g_assert (self->write_fd == -1); self->write_path = g_strdup_printf ("%s.XXXXXX", self->filename); self->write_fd = g_mkstemp (self->write_path); if (self->write_fd == -1) { g_message ("couldn't open new temporary store file: %s: %s", self->write_path, g_strerror (errno)); gkm_transaction_fail (transaction, CKR_FUNCTION_FAILED); return FALSE; } return TRUE; }
static gboolean bod_open(bod_state *state) { if (NULL == state->tempfile) { gint fd; GString *tmpfilename; const char tmpl[] = "lighttpd-buffer-XXXXXX", basedir[] = "/var/tmp"; tmpfilename = g_string_sized_new((sizeof(basedir) - 1) + 1 + (sizeof(tmpl) - 1)); g_string_append_len(tmpfilename, CONST_STR_LEN(basedir)); /* TODO: add config option */ li_path_append_slash(tmpfilename); g_string_append_len(tmpfilename, CONST_STR_LEN(tmpl)); fd = g_mkstemp(tmpfilename->str); if (-1 == fd) { VR_ERROR(state->vr, "g_mkstemp failed: %s", g_strerror(errno)); g_string_free(tmpfilename, TRUE); bod_stop(state); return FALSE; } state->tempfile = li_chunkfile_new(tmpfilename, fd, TRUE); state->write_pos = 0; state->flush_pos = 0; g_string_free(tmpfilename, TRUE); } return TRUE; }
static gchar * create_temporary_file (void) { const gchar *tmpdir; gchar *tmp_fn; gint fd; tmpdir = g_get_tmp_dir (); if (tmpdir == NULL) return NULL; /* this is just silly, but gcc warns if we try to use tpmnam() */ tmp_fn = g_build_filename (tmpdir, "gstreamer-filesink-test-XXXXXX", NULL); fd = g_mkstemp (tmp_fn); if (fd < 0) { GST_ERROR ("can't create temp file %s: %s", tmp_fn, g_strerror (errno)); g_free (tmp_fn); return NULL; } /* don't want the file, just a filename (hence silly, see above) */ g_close (fd, NULL); g_remove (tmp_fn); return tmp_fn; }
char * libre_impuesto_file_tmp_filename (const char *base, const char *extension) { int fd; char *name = g_strdup (base); fd = g_mkstemp (name); if (fd != -1) { unlink (name); close (fd); } else { g_free (name); return NULL; } if (extension) { char *tmp; tmp = g_strconcat (name, ".", extension, NULL); g_free (name); name = tmp; } return name; }
static void write_thumbnail (const char *filename, gconstpointer data, gsize size, int thumb_size) { char *tmp_name; int fd; FILE *file; tmp_name = g_strdup_printf ("%s.XXXXXX", filename); fd = g_mkstemp (tmp_name); if (fd == -1) { perror ("Could not create temporary file"); exit (EXIT_FAILURE); } file = fdopen (fd, "w"); if (!file) { show_error_string_and_exit ("Could not open temporary file for writing"); exit (EXIT_FAILURE); } if (fwrite (data, 1, size, file) != size) { perror ("Could not write data to output file"); exit (EXIT_FAILURE); } if (fclose (file) != 0) { perror ("Could not close oputput file"); exit (EXIT_FAILURE); } call_convert (tmp_name, filename, thumb_size); unlink (tmp_name); }
char * write_temp_file (void * data, int64_t len) { char * temp = filename_build (g_get_tmp_dir (), "audacious-temp-XXXXXX"); SCOPY (name, temp); str_unref (temp); int handle = g_mkstemp (name); if (handle < 0) { fprintf (stderr, "Error creating temporary file: %s\n", strerror (errno)); return NULL; } while (len) { int64_t written = write (handle, data, len); if (written < 0) { fprintf (stderr, "Error writing %s: %s\n", name, strerror (errno)); close (handle); return NULL; } data = (char *) data + written; len -= written; } if (close (handle) < 0) { fprintf (stderr, "Error closing %s: %s\n", name, strerror (errno)); return NULL; } return str_get (name); }
gchar * lsq_archive_request_temp_file ( LSQArchive *archive, const gchar *sfx ) { gchar dirname[256]; gint handle; g_return_val_if_fail( LSQ_IS_ARCHIVE( archive ), NULL ); g_snprintf( dirname, 256, "%s/" PACKAGE "-%s/", g_get_tmp_dir(), g_get_user_name() ); if ( 0 != g_mkdir_with_parents( dirname, 0700 ) ) { return NULL; } g_snprintf( dirname, 256, "%s/" PACKAGE "-%s/file-XXXXXX%s", g_get_tmp_dir(), g_get_user_name(), ( NULL != sfx ) ? sfx : "" ); handle = g_mkstemp( dirname ); if ( -1 == handle ) { return NULL; } close( handle ); return g_strdup( dirname ); }
static gchar* generate_tmpfn(void) { gchar tmpl[] = "mg.XXXXXX"; int fd = g_mkstemp(tmpl); close(fd); return g_strdup(tmpl); }
static BinaryRegistryCache * gst_registry_binary_cache_init (GstRegistry * registry, const char *location) { BinaryRegistryCache *cache = g_slice_new0 (BinaryRegistryCache); cache->location = location; cache->tmp_location = g_strconcat (location, ".tmpXXXXXX", NULL); cache->cache_fd = g_mkstemp (cache->tmp_location); if (cache->cache_fd == -1) { int ret; GStatBuf statbuf; gchar *dir; /* oops, I bet the directory doesn't exist */ dir = g_path_get_dirname (location); g_mkdir_with_parents (dir, 0777); ret = g_stat (dir, &statbuf); if (ret != -1 && (statbuf.st_mode & 0700) != 0700) { g_chmod (dir, 0700); } g_free (dir); /* the previous g_mkstemp call overwrote the XXXXXX placeholder ... */ g_free (cache->tmp_location); cache->tmp_location = g_strconcat (location, ".tmpXXXXXX", NULL); cache->cache_fd = g_mkstemp (cache->tmp_location); if (cache->cache_fd == -1) { GST_DEBUG ("g_mkstemp() failed: %s", g_strerror (errno)); g_free (cache->tmp_location); g_slice_free (BinaryRegistryCache, cache); return NULL; } ret = g_stat (cache->tmp_location, &statbuf); if (ret != -1 && (statbuf.st_mode & 0600) != 0600) { g_chmod (cache->tmp_location, 0600); } } return cache; }
static void test_db (GNCPriceDB* db) { xmlNodePtr test_node; gchar* filename1; int fd; QofBook* book = qof_instance_get_book (QOF_INSTANCE (db)); test_node = gnc_pricedb_dom_tree_create (db); if (!test_node && db) { failure_args ("pricedb_xml", __FILE__, __LINE__, "gnc_pricedb_dom_tree_create returned NULL"); return; } if (!db) return; filename1 = g_strdup_printf ("test_file_XXXXXX"); fd = g_mkstemp (filename1); write_dom_node_to_file (test_node, fd); close (fd); { sixtp *parser; load_counter lc = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; sixtp_gdv2 data = {book, lc, NULL, NULL, FALSE}; parser = sixtp_new (); if (!sixtp_add_some_sub_parsers (parser, TRUE, "gnc:pricedb", gnc_pricedb_sixtp_parser_create (), NULL, NULL)) { failure_args ("sixtp_add_some_sub_parsers failed", __FILE__, __LINE__, "%d", iter); } else if (!gnc_xml_parse_file (parser, filename1, test_add_pricedb, (gpointer)&data, qof_session_get_book (session))) { failure_args ("gnc_xml_parse_file returned FALSE", __FILE__, __LINE__, "%d", iter); } } g_unlink (filename1); g_free (filename1); xmlFreeNode (test_node); }
/** * gimp_config_writer_new_file: * @filename: a filename * @atomic: if %TRUE the file is written atomically * @header: text to include as comment at the top of the file * @error: return location for errors * * Creates a new #GimpConfigWriter and sets it up to write to * @filename. If @atomic is %TRUE, a temporary file is used to avoid * possible race conditions. The temporary file is then moved to * @filename when the writer is closed. * * Return value: a new #GimpConfigWriter or %NULL in case of an error * * Since: GIMP 2.4 **/ GimpConfigWriter * gimp_config_writer_new_file (const gchar *filename, gboolean atomic, const gchar *header, GError **error) { GimpConfigWriter *writer; gchar *tmpname = NULL; gint fd; g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); if (atomic) { tmpname = g_strconcat (filename, "XXXXXX", NULL); fd = g_mkstemp (tmpname); if (fd == -1) { g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE, _("Could not create temporary file for '%s': %s"), gimp_filename_to_utf8 (filename), g_strerror (errno)); g_free (tmpname); return NULL; } } else { fd = g_creat (filename, 0644); if (fd == -1) { g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE, _("Could not open '%s' for writing: %s"), gimp_filename_to_utf8 (filename), g_strerror (errno)); return NULL; } } writer = g_slice_new0 (GimpConfigWriter); writer->fd = fd; writer->filename = g_strdup (filename); writer->tmpname = tmpname; writer->buffer = g_string_new (NULL); if (header) { gimp_config_writer_comment (writer, header); gimp_config_writer_linefeed (writer); } return writer; }
static gboolean katze_http_cookies_update_jar (KatzeHttpCookies* http_cookies) { gint fn = 0; FILE* f = NULL; gchar* temporary_filename = NULL; GSList* cookies; http_cookies->timeout = 0; temporary_filename = g_strconcat (http_cookies->filename, ".XXXXXX", NULL); if ((fn = g_mkstemp (temporary_filename)) == -1) goto failed; if (!((f = fdopen (fn, "wb")))) goto failed; cookies = soup_cookie_jar_all_cookies (http_cookies->jar); for (; cookies != NULL; cookies = g_slist_next (cookies)) { SoupCookie* cookie = cookies->data; if (cookie->expires && !soup_date_is_past (cookie->expires)) write_cookie (f, cookie); soup_cookie_free (cookie); } g_slist_free (cookies); if (fclose (f) != 0) { f = NULL; goto failed; } f = NULL; if (g_rename (temporary_filename, http_cookies->filename) == -1) goto failed; g_free (temporary_filename); if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL) { g_print ("KatzeHttpCookies: %d cookies changed\n", http_cookies->counter); http_cookies->counter = 0; } return FALSE; failed: if (f) fclose (f); g_unlink (temporary_filename); g_free (temporary_filename); if (g_getenv ("MIDORI_COOKIES_DEBUG") != NULL) g_print ("KatzeHttpCookies: Failed to write '%s'\n", http_cookies->filename); return FALSE; }
/* filter idea (and some of the code) was taken from Snownews */ static gchar * update_exec_filter_cmd (gchar *cmd, gchar *data, gchar **errorOutput, size_t *size) { int fd, status; gchar *command; const gchar *tmpdir = g_get_tmp_dir(); char *tmpfilename; char *out = NULL; FILE *file, *p; *errorOutput = NULL; tmpfilename = g_build_filename (tmpdir, "liferea-XXXXXX", NULL); fd = g_mkstemp(tmpfilename); if(fd == -1) { debug1(DEBUG_UPDATE, "Error opening temp file %s to use for filtering!", tmpfilename); *errorOutput = g_strdup_printf(_("Error opening temp file %s to use for filtering!"), tmpfilename); g_free(tmpfilename); return NULL; } file = fdopen(fd, "w"); fwrite(data, strlen(data), 1, file); fclose(file); *size = 0; command = g_strdup_printf("%s < %s", cmd, tmpfilename); p = popen(command, "r"); g_free(command); if(NULL != p) { while(!feof(p) && !ferror(p)) { size_t len; out = g_realloc(out, *size+1025); len = fread(&out[*size], 1, 1024, p); if(len > 0) *size += len; } status = pclose(p); if(!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) { *errorOutput = g_strdup_printf(_("%s exited with status %d"), cmd, WEXITSTATUS(status)); *size = 0; } out[*size] = '\0'; } else { g_warning(_("Error: Could not open pipe \"%s\""), command); *errorOutput = g_strdup_printf(_("Error: Could not open pipe \"%s\""), command); } /* Clean up. */ unlink (tmpfilename); g_free (tmpfilename); return out; }
static GPid start_ssh_agent (void) { GError *error = NULL; GSpawnFlags flags; GPid pid = 0; gint fd = -1; gchar *bind_address = g_strdup_printf ("%s/ssh-agent.XXXXXX", g_get_user_runtime_dir ()); gchar *agent_argv[] = { "ssh-agent", "-a", bind_address, NULL }; fd = g_mkstemp (bind_address); if (fd < 0) { g_warning ("couldn't create temporary socket file: %s", g_strerror (errno)); goto out; } if (g_unlink (bind_address) < 0) { g_warning ("couldn't remove temporary socket file: %s", g_strerror (errno)); goto out; } flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL; g_spawn_async (NULL, agent_argv, NULL, flags, setup_daemon, GINT_TO_POINTER (-1), &pid, &error); if (error != NULL) { if (g_error_matches (error, G_SPAWN_ERROR, G_SPAWN_ERROR_NOENT)) g_debug ("couldn't start %s: %s", agent_argv[0], error->message); else g_warning ("couldn't start %s: %s", agent_argv[0], error->message); pid = 0; goto out; } g_debug ("launched %s", agent_argv[0]); g_setenv ("SSH_AUTH_SOCK", bind_address, TRUE); out: g_clear_error (&error); if (fd >= 0) close (fd); g_free (bind_address); return pid; }
static GstMemory * gst_wl_shm_allocator_alloc (GstAllocator * allocator, gsize size, GstAllocationParams * params) { GstWlShmAllocator *self = GST_WL_SHM_ALLOCATOR (allocator); char filename[1024]; static int init = 0; int fd; GstMemory *mem; GstMapInfo info; /* TODO: make use of the allocation params, if necessary */ /* allocate shm pool */ snprintf (filename, 1024, "%s/%s-%d-%s", g_get_user_runtime_dir (), "wayland-shm", init++, "XXXXXX"); fd = g_mkstemp (filename); if (fd < 0) { GST_ERROR_OBJECT (self, "opening temp file %s failed: %s", filename, strerror (errno)); return NULL; } if (ftruncate (fd, size) < 0) { GST_ERROR_OBJECT (self, "ftruncate failed: %s", strerror (errno)); close (fd); return NULL; } mem = gst_fd_allocator_alloc (allocator, fd, size, GST_FD_MEMORY_FLAG_KEEP_MAPPED); if (G_UNLIKELY (!mem)) { GST_ERROR_OBJECT (self, "GstFdMemory allocation failed"); close (fd); return NULL; } /* we need to map the memory in order to unlink the file without losing it */ if (!gst_memory_map (mem, &info, GST_MAP_READWRITE)) { GST_ERROR_OBJECT (self, "GstFdMemory map failed"); close (fd); return NULL; } /* unmap will not really munmap(), we just * need it to release the miniobject lock */ gst_memory_unmap (mem, &info); unlink (filename); return mem; }
static void soap_sax_startElementNs (gpointer _ctxt, const xmlChar *localname, const xmlChar *prefix, const xmlChar *uri, gint nb_namespaces, const xmlChar **namespaces, gint nb_attributes, gint nb_defaulted, const xmlChar **attributes) { xmlParserCtxt *ctxt = _ctxt; ESoapMessagePrivate *priv = ctxt->_private; gchar *fname; xmlSAX2StartElementNs (ctxt, localname, prefix, uri, nb_namespaces, namespaces, nb_attributes, nb_defaulted, attributes); /* steal_node can contain multiple node name separated by " " */ if (priv->steal_node && *priv->steal_node) { gchar **prop = g_strsplit (priv->steal_node, " ", 0); gint i = 0; gboolean isnode = FALSE; while (prop[i]) { if (strcmp ((const gchar *) localname, prop[i]) == 0) { isnode = TRUE; break; } i++; } g_strfreev (prop); if (!isnode) return; } else return; fname = g_build_filename (priv->steal_dir, "XXXXXX", NULL); priv->steal_fd = g_mkstemp (fname); if (priv->steal_fd != -1) { if (priv->steal_base64) { gchar *enc = g_base64_encode ((guchar *) fname, strlen (fname)); xmlSAX2Characters (ctxt, (xmlChar *) enc, strlen (enc)); g_free (enc); } else xmlSAX2Characters (ctxt, (xmlChar *) fname, strlen (fname)); } g_free (fname); }
static int open_tmp_file (BlockBackend *bend, const char *basename, char **path) { FsPriv *priv = bend->be_priv; int fd; *path = g_strdup_printf ("%s/%s.XXXXXX", priv->tmp_dir, basename); fd = g_mkstemp (*path); if (fd < 0) g_free (*path); return fd; }
static GstMemory * gst_wl_shm_allocator_alloc (GstAllocator * allocator, gsize size, GstAllocationParams * params) { GstWlShmAllocator *self = GST_WL_SHM_ALLOCATOR (allocator); char filename[1024]; static int init = 0; int fd; gpointer data; GstWlShmMemory *mem; /* TODO: make use of the allocation params, if necessary */ /* allocate shm pool */ snprintf (filename, 1024, "%s/%s-%d-%s", g_get_user_runtime_dir (), "wayland-shm", init++, "XXXXXX"); fd = g_mkstemp (filename); if (fd < 0) { GST_ERROR_OBJECT (self, "opening temp file %s failed: %s", filename, strerror (errno)); return NULL; } if (ftruncate (fd, size) < 0) { GST_ERROR_OBJECT (self, "ftruncate failed: %s", strerror (errno)); close (fd); return NULL; } data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (data == MAP_FAILED) { GST_ERROR_OBJECT (self, "mmap failed: %s", strerror (errno)); close (fd); return NULL; } unlink (filename); mem = g_slice_new0 (GstWlShmMemory); gst_memory_init ((GstMemory *) mem, GST_MEMORY_FLAG_NO_SHARE, allocator, NULL, size, 0, 0, size); mem->data = data; mem->fd = fd; return (GstMemory *) mem; }
} END_TEST START_TEST(test_cc_oci_state_file_delete) { struct stat st; struct cc_oci_config config = { { 0 } }; gint fd = 0; g_snprintf(config.state.state_file_path, PATH_MAX, "/tmp/.fileXXXXXX"); fd = g_mkstemp(config.state.state_file_path); ck_assert(fd != -1); ck_assert(close(fd) != -1); ck_assert(cc_oci_state_file_delete(&config)); ck_assert(stat(config.state.state_file_path, &st)); } END_TEST
static GFile * create_snapshot_file (EMsgComposer *composer, GError **error) { GFile *snapshot_file; const gchar *user_data_dir; gchar *path; gint fd; snapshot_file = e_composer_get_snapshot_file (composer); if (G_IS_FILE (snapshot_file)) return snapshot_file; user_data_dir = e_get_user_data_dir (); path = g_build_filename (user_data_dir, SNAPSHOT_FILE_SEED, NULL); /* g_mkstemp() modifies the XXXXXX part of the * template string to form the actual filename. */ errno = 0; fd = g_mkstemp (path); if (fd == -1) { g_set_error ( error, G_FILE_ERROR, g_file_error_from_errno (errno), "%s", g_strerror (errno)); g_free (path); return NULL; } close (fd); snapshot_file = g_file_new_for_path (path); /* Save the GFile for subsequent snapshots. */ g_object_set_data_full ( G_OBJECT (composer), SNAPSHOT_FILE_KEY, snapshot_file, (GDestroyNotify) delete_snapshot_file); g_free (path); return snapshot_file; }
static gint _create_temporary_file (gint size) { gchar *path; gint fd; path = g_build_filename (g_get_tmp_dir (), "mechane-buffer-XXXXXX", NULL); fd = g_mkstemp (path); g_unlink (path); g_free (path); if (ftruncate (fd, size) < 0) { g_critical ("Truncating temporary file failed: %m"); close(fd); return -1; } return fd; }
static int open_temp_file (RecvFSM *fsm) { GString *temp_file = g_string_new (NULL); g_string_printf (temp_file, "%s/%sXXXXXX", seaf->http_temp_dir, get_basename(fsm->file_name)); fsm->fd = g_mkstemp (temp_file->str); if (fsm->fd < 0) { g_string_free (temp_file, TRUE); return -1; } fsm->tmp_file = g_string_free (temp_file, FALSE); /* For clean up later. */ fsm->tmp_files = g_list_prepend (fsm->tmp_files, g_strdup(fsm->tmp_file)); return 0; }
void save_thumbnail_to_disk(ThumbnailTask* task, GdkPixbuf* pix, const char* path) { /* save the generated thumbnail to disk */ char* tmpfile = g_strconcat(path, ".XXXXXX", NULL); gint fd; fd = g_mkstemp(tmpfile); /* save to a temp file first */ if(fd != -1) { char mtime_str[100]; g_snprintf( mtime_str, 100, "%lu", task->fi->mtime ); chmod( tmpfile, 0600 ); /* only the owner can read it. */ gdk_pixbuf_save( pix, tmpfile, "png", NULL, "tEXt::Thumb::URI", task->uri, "tEXt::Thumb::MTime", mtime_str, NULL ); close(fd); g_rename(tmpfile, path); g_free(tmpfile); } DEBUG("generator: save to %s", path); }
/** * mate_vfs_create_temp: * @prefix: Prefix for the name of the temporary file * @name_return: Pointer to a pointer that, on return, will point to * the dynamically allocated name for the new temporary file created. * @handle_return: Pointer to a variable that will hold a file handle for * the new temporary file on return. * * Create a temporary file whose name is prefixed with @prefix, and return an * open file handle for it in @*handle_return. * * Return value: An integer value representing the result of the operation **/ MateVFSResult mate_vfs_create_temp (const gchar *prefix, gchar **name_return, MateVFSHandle **handle_return) { MateVFSHandle *handle; MateVFSResult result; gchar *name; gint fd; while (1) { name = g_strdup_printf("%sXXXXXX", prefix); fd = g_mkstemp (name); if (fd < 0) return MATE_VFS_ERROR_INTERNAL; #ifdef HAVE_FCHMOD fchmod (fd, 0600); #endif close (fd); result = mate_vfs_open (&handle, name, MATE_VFS_OPEN_WRITE | MATE_VFS_OPEN_READ); if (result == MATE_VFS_OK) { *name_return = name; *handle_return = handle; return MATE_VFS_OK; } if (result != MATE_VFS_ERROR_FILE_EXISTS) { *name_return = NULL; *handle_return = NULL; g_free (name); return result; } } }
void HttpRequest::SendAsync () { char *templ; VERIFY_MAIN_THREAD; LOG_DOWNLOADER ("HttpRequest::SendAsync () is_aborted: %i is_completed: %i\n", is_aborted, is_completed); if (is_aborted || is_completed) return; /* create tmp file */ if ((options & DisableFileStorage) == 0) { const char *dir = handler->GetDownloadDir (); if (dir == NULL) { Failed ("Could not create temporary download directory"); return; } templ = g_build_filename (dir, "XXXXXX", NULL); tmpfile_fd = g_mkstemp (templ); if (tmpfile_fd == -1) { char *msg = g_strdup_printf ("Could not create temporary download file %s for url %s\n", templ, GetUri ()); Failed (msg); g_free (msg); g_free (templ); return; } tmpfile = templ; LOG_DOWNLOADER ("HttpRequest::Send () uri %s is being saved to %s\n", GetUri (), tmpfile); } else { LOG_DOWNLOADER ("HttpRequest::Send () uri %s is not being saved to disk\n", GetUri ()); } #if DEBUG GetDeployment ()->AddSource (GetOriginalUri (), tmpfile == NULL ? "Not stored on disk" : tmpfile); #endif SendImpl (); }
void set_user_icon_data (ActUser *user, GdkPixbuf *pixbuf) { gchar *path; gint fd; GOutputStream *stream; GError *error; path = g_build_filename (g_get_tmp_dir (), "gnome-control-center-user-icon-XXXXXX", NULL); fd = g_mkstemp (path); if (fd == -1) { g_warning ("failed to create temporary file for image data"); g_free (path); return; } stream = g_unix_output_stream_new (fd, TRUE); error = NULL; if (!gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, &error, NULL)) { g_warning ("failed to save image: %s", error->message); g_error_free (error); g_object_unref (stream); return; } g_object_unref (stream); act_user_set_icon_file (user, path); /* if we ever make the dbus call async, the g_remove call needs * to wait for its completion */ g_remove (path); g_free (path); }
static void impl_webkit_show_data( GncHtml* self, const gchar* data, int datalen ) { GncHtmlWebkitPrivate* priv; #if HAVE(WEBKIT_WEB_VIEW_LOAD_URI) #define TEMPLATE_REPORT_FILE_NAME "gnc-report-XXXXXX.html" int fd; gchar* uri; gchar *filename; #endif g_return_if_fail( self != NULL ); g_return_if_fail( GNC_IS_HTML_WEBKIT(self) ); ENTER( "datalen %d, data %20.20s", datalen, data ); priv = GNC_HTML_WEBKIT_GET_PRIVATE(self); #if HAVE(WEBKIT_WEB_VIEW_LOAD_URI) /* Export the HTML to a file and load the file URI. On Linux, this seems to get around some security problems (otherwise, it can complain that embedded images aren't permitted to be viewed because they are local resources). On Windows, this allows the embedded images to be viewed (maybe for the same reason as on Linux, but I haven't found where it puts those messages. */ filename = g_build_filename(g_get_tmp_dir(), TEMPLATE_REPORT_FILE_NAME, (gchar *)NULL); fd = g_mkstemp( filename ); impl_webkit_export_to_file( self, filename ); close( fd ); uri = g_strdup_printf( "file:///%s", filename ); g_free(filename); DEBUG("Loading uri '%s'", uri); webkit_web_view_load_uri( priv->web_view, uri ); g_free( uri ); #else webkit_web_view_load_html_string( priv->web_view, data, BASE_URI_NAME ); #endif LEAVE(""); }