snd_data *free_snd_data(snd_data *sd) { if (sd) { if (!(sd->inuse)) { /* assume the inuse cases will eventually be freed the GC. * this can happen if a sampler is created, and forgotten, * and the associated sound is closed. The closing runs through * the snd_data (sounds) list freeing the descriptors, but the * forgotten sampler is still idle somewhere thinking it * might someday find a use for itself... */ if (sd->temporary == ALREADY_DELETED) return(NULL); if (sd->temporary == MULTICHANNEL_DELETION) forget_temp(sd->filename, sd->chan); if ((sd->type == SND_DATA_BUFFER) && (sd->buffered_data)) free(sd->buffered_data); sd->buffered_data = NULL; if ((!(sd->copy)) && (sd->hdr)) free_file_info(sd->hdr); sd->hdr = NULL; if (sd->io) { int i, chans; if (sd->open == FD_OPEN) mus_file_close(sd->io->fd); /* free the IO buffers as well as the descriptor buffer */ chans = sd->io->chans; for (i = 0; i < chans; i++) if (sd->io->arrays[i]) free(sd->io->arrays[i]); free(sd->io->arrays); free(sd->io); sd->io = NULL; if (sd->temporary == DELETE_ME) snd_remove(sd->filename, REMOVE_FROM_CACHE); } if (sd->filename) free(sd->filename); sd->filename = NULL; sd->temporary = ALREADY_DELETED; sd->copy = false; sd->type = SND_DATA_NO_DATA; free(sd); } else { sd->free_me = true; } } return(NULL); }
// Sends the requested files to the Hooli file transfer server // @param hftpd a pointer to the server information // @param client a pointer to the client information // @return -1 if there was an error, 1 otherwise int hooli_file_sync(server_info *hftpd, client_info *client) { int sockfd; // The socket for communication with the server int seq = 0; // The sequence number int count = 0; file_info *file; host server; // Server address sockfd = create_udp_client_socket(hftpd->server, hftpd->port, &server); csv_record *p = client->response_list; // Loop through all the requested files while (p != NULL) { count++; file = create_file(); initialize_file(file, client, p); send_initialize(sockfd, &server, &seq, file, client, hftpd, p, count); // Keep sending data messages until a file is transferred while (!file->file_transferred) { manage_file_buffer(file); send_data(sockfd, &server, &seq, file); update_progress(file); } //end while final_progress_update(file); free_file_info(file); p = p->next; } //end while send_termination(sockfd, &server, &seq, p, client); // Close the socket close(sockfd); return 1; } //end hooli_file_sync
static gboolean step_expand_uris (FilesCtx *ctx, GError **err) { GFileEnumerator *enumerator; gboolean ret = TRUE; FileInfo *finfo; GList *l; g_assert (err && !*err); for (l = ctx->finfos; l; l = g_list_next (l)) { if (!seahorse_tool_progress_check ()) { ret = FALSE; break; } finfo = (FileInfo*)(l->data); if (!finfo || !finfo->uri) continue; if (g_file_info_get_file_type (finfo->info) == G_FILE_TYPE_DIRECTORY) { enumerator = g_file_enumerate_children (finfo->file, FILE_ATTRIBUTES, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, err); if (!enumerator) return FALSE; if (!visit_enumerator (ctx, finfo->file, enumerator, err)) return FALSE; /* We don't actually do operations on the dirs */ free_file_info (finfo, NULL); l->data = NULL; } } return ret; }
FILELIST * filelist_pop_front( FILELIST * list ) { FILEITEM * item; if ( filelist_empty( list ) ) return list; item = list->head; if ( item ) { if ( item->value ) free_file_info( item->value, 0 ); list->head = item->next; list->size--; if ( !list->size ) list->tail = list->head; #ifdef BJAM_NO_MEM_CACHE BJAM_FREE( item ); #endif } return list; }
// Sends an intialize message to the server // @param sockfd the socket file descriptor // @param server the server being sent to // @param seq the sequence number of the message // @param file a pointer to the file variable // @param client a pointer to the client variable // @param hftpd a pointer to the server information // @param p a pointer to the filename // @param count the position in the list of files static void send_initialize(int sockfd, host *server, int *seq, file_info *file, client_info *client, server_info *hftpd, csv_record *p, int count) { hftp_control_message *control = (hftp_control_message*)create_control_message(INITIALIZE, *seq, p, client->token, file->file_length); syslog(LOG_INFO, "Transferring '%s' (%d of %d)", p->filename, count, get_list_length(client->response_list)); syslog(LOG_DEBUG, "Type: Initialization, Sequence: %d, Filename length: %d", control->sequence, ntohs(control->filename_length)); // Transmit a control request if (transmit(sockfd, (message**)&control, server, seq) == -1) { syslog(LOG_INFO, "Authentication with Hooli file transfer server failed"); free_file_info(file); close(sockfd); free_server_info(hftpd); free_client_info(client); exit(EXIT_FAILURE); } //end if } //end send_control
void merge_vcf(int n_vcf, char **vcf_filenames) { FileInfo *f_info; int n_done, n_chrom, i, *is_lowest, *lowest, n_lowest; int ret, use_geno_probs, use_haplotypes; Chromosome *chrom_tab; f_info = init_file_info(n_vcf, vcf_filenames); /* find chromosomes that are present in ALL VCFs */ chrom_tab = chrom_table_intersect(f_info, n_vcf, &n_chrom); n_done = 0; is_lowest = my_malloc(sizeof(int) * n_vcf); lowest = my_malloc(sizeof(int) * n_vcf); /* only use genotypes and haplotypes if they are present in ALL files */ use_geno_probs = TRUE; use_haplotypes = TRUE; /* read first SNP from all files */ for(i = 0; i < n_vcf; i++) { ret = vcf_read_line(f_info[i].gzf, f_info[i].vcf, &f_info[i].cur_snp); if(ret == -1) { /* file is over */ n_done += 1; f_info[i].is_done = TRUE; my_warn("file %s contains no SNPs\n", vcf_filenames[i]); f_info[i].cur_chrom = NULL; } else { set_cur_chrom(&f_info[i], chrom_tab, n_chrom); if(!f_info[i].cur_snp.has_geno_probs) { if(use_geno_probs) { fprintf(stderr, "Not using genotype likelihoods (GL) because " "not present in file %s\n", vcf_filenames[i]); } use_geno_probs = FALSE; } if(!f_info[i].cur_snp.has_haplotypes) { if(use_haplotypes) { fprintf(stderr, "Not using genotypes (GT) because " "not present in file %s\n", vcf_filenames[i]); } use_haplotypes = FALSE; } } } fprintf(stderr, "parsing files\n"); while(n_done < n_vcf) { /* find SNP(s) with lowest (chrom, pos) */ find_lowest(f_info, n_vcf, is_lowest, lowest, &n_lowest); /* merge counts and write line for these SNPs */ write_output(stdout, f_info, n_vcf, is_lowest, lowest, use_geno_probs, use_haplotypes); /* advance files with lowest SNPs */ for(i = 0; i < n_vcf; i++) { if(!f_info[i].is_done && is_lowest[i]) { if(vcf_read_line(f_info[i].gzf, f_info[i].vcf, &f_info[i].cur_snp) == -1) { /* have reached end of this file */ n_done += 1; f_info[i].is_done = TRUE; } } } } fprintf(stderr, "done!\n"); free_file_info(f_info, n_vcf); for(i = 0; i < n_chrom; i++) { my_free(chrom_tab[i].name); my_free(chrom_tab[i].assembly); } my_free(chrom_tab); my_free(is_lowest); }