static int gio_ftruncate (VFSFile * file, int64_t length) { FileData * data = vfs_get_handle (file); GError * error = 0; g_seekable_truncate (data->seekable, length, NULL, & error); CHECK_ERROR ("truncate", vfs_get_filename (file)); return 0; FAILED: return -1; }
static VALUE rg_truncate(int argc, VALUE *argv, VALUE self) { VALUE offset, cancellable; GError *error = NULL; rb_scan_args(argc, argv, "11", &offset, &cancellable); if (!g_seekable_truncate(_SELF(self), RVAL2GOFFSET(offset), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_error(error); return self; }
static inline GeglBufferTile * gegl_tile_backend_file_file_entry_new (GeglTileBackendFile *self) { GeglBufferTile *entry = gegl_tile_entry_new (0,0,0); GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "Creating new entry"); gegl_tile_backend_file_ensure_exist (self); if (self->free_list) { /* XXX: losing precision ? */ gint offset = GPOINTER_TO_INT (self->free_list->data); entry->offset = offset; self->free_list = g_slist_remove (self->free_list, self->free_list->data); GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, " set offset %i from free list", ((gint)entry->offset)); } else { gint tile_size = gegl_tile_backend_get_tile_size (GEGL_TILE_BACKEND (self)); entry->offset = self->next_pre_alloc; GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, " set offset %i (next allocation)", (gint)entry->offset); self->next_pre_alloc += tile_size; if (self->next_pre_alloc >= self->total) { self->total = self->total + 32 * tile_size; GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "growing file to %i bytes", (gint)self->total); #if HAVE_GIO g_assert (g_seekable_truncate (G_SEEKABLE (self->o), self->total, NULL,NULL)); #else g_assert (ftruncate (self->o, self->total) == 0); #endif } } gegl_tile_backend_file_dbg_alloc (gegl_tile_backend_get_tile_size (GEGL_TILE_BACKEND (self))); return entry; }
static void ekg_gnutls_flush(struct ekg_connection *c) { struct ekg_gnutls_connection *gc = c->master->priv_data; GMemoryOutputStream *dos = gc->outstream; ssize_t ret; gconstpointer bufp; gsize bufleft; /* GMemoryOutputStream is not supposed to fail */ g_assert(g_output_stream_flush( G_OUTPUT_STREAM(c->outstream), NULL, NULL)); /* now pass the written data to gnutls */ bufp = g_memory_output_stream_get_data(dos); bufleft = g_memory_output_stream_get_data_size(dos); do { ret = gnutls_record_send(gc->session, bufp, bufleft); if (ret > 0) { g_assert(ret <= bufleft); bufp += ret; bufleft -= ret; } else if (ret != GNUTLS_E_INTERRUPTED && ret != GNUTLS_E_AGAIN) { debug_error("gnutls_flush(), write failed: %s\n", gnutls_strerror(ret)); /* XXX */ failed_write(c); } } while (bufleft > 0); { GSeekable *sos = G_SEEKABLE(dos); g_assert(g_seekable_seek(sos, 0, G_SEEK_SET, NULL, NULL)); g_assert(g_seekable_truncate(sos, 0, NULL, NULL)); } }
bool verify_and_strip_signatures() { g_debug( "CHECKING SIGNATURE(S)" ); Signature::Info::List signatures; gsize signature_length = 0; // This means that the signatures are invalid or we had a problem // dealing with them. If there are no signatures, this will return // true and give us an empty list. if ( ! Signature::get_signatures( info.source_file.c_str(), signatures, &signature_length ) ) { return false; } unsigned int found = 0; if ( signatures.empty() ) { g_debug( " NOT SIGNED" ); } else { for ( Signature::Info::List::const_iterator it = signatures.begin(); it != signatures.end(); ++it ) { info.fingerprints.insert( it->fingerprint ); } // Now, see how many of the required ones are found in the signatures for ( StringSet::const_iterator it = info.required_fingerprints.begin(); it != info.required_fingerprints.end(); ++it ) { found += info.fingerprints.count( *it ); } } if ( found != info.required_fingerprints.size() ) { // Signature(s) missing g_warning( "APP IS MISSING AT LEAST ONE REQUIRED SIGNATURE" ); return false; } // If there were no signatures, we are done if ( signatures.empty() ) { return true; } // Otherwise, we need to strip the signature block from the file bool result = false; GFile * file = g_file_new_for_path( info.source_file.c_str() ); if ( file ) { GFileIOStream * stream = g_file_open_readwrite( file, NULL, NULL ); if ( stream ) { GSeekable * seekable = G_SEEKABLE( stream ); if ( g_seekable_can_seek( seekable ) && g_seekable_can_truncate( seekable ) ) { if ( g_seekable_seek( seekable, 0, G_SEEK_END, NULL, NULL ) ) { goffset file_size = g_seekable_tell( seekable ); file_size -= signature_length; if ( g_seekable_truncate( seekable, file_size, NULL, NULL ) ) { g_debug( "TRUNCATING FILE TO %" G_GOFFSET_FORMAT " BYTES", file_size ); result = true; } } } g_io_stream_close( G_IO_STREAM( stream ), NULL, NULL ); g_object_unref( G_OBJECT( stream ) ); } g_object_unref( G_OBJECT( file ) ); } if ( ! result ) { g_warning( "FAILED TO STRIP SIGNATURE(S)" ); } return result; }