void __attribute__((destructor)) __ibprof_exit(void) { IBPROF_ERROR status = IBPROF_ERR_NONE; UNREFERENCED_PARAMETER(status); /* check if it has been activated */ if (ibprof_obj) { IBPROF_MODULE_OBJECT *temp_module_obj = NULL; int i = 0; ibprof_obj->task_obj->wall_time = ibprof_task_wall_time(ibprof_obj->task_obj->t_start); /* Dump all gathered information */ ibprof_dump(); temp_module_obj = ibprof_obj->module_array[0]; while (temp_module_obj) { if (temp_module_obj->id != IBPROF_MODULE_INVALID) { if (temp_module_obj->exit) status = temp_module_obj->exit(temp_module_obj); } temp_module_obj = ibprof_obj->module_array[++i]; } ibprof_hash_destroy(ibprof_obj->hash_obj); ibprof_task_destroy(ibprof_obj->task_obj); DELETE_CRITICAL(&(ibprof_obj->lock)); sys_free(ibprof_obj); ibprof_obj = NULL; } if (ibprof_dump_file && ibprof_dump_file != stdout && ibprof_dump_file != stderr) { struct stat statbuf; char fd_path[255]; char *filename = sys_malloc(255); size_t ret = 0; sys_sprintf(fd_path, "/proc/self/fd/%d", fileno(ibprof_dump_file)); ret = readlink(fd_path, filename, 255); if (ret > 0) { sys_fflush(ibprof_dump_file); sys_fclose(ibprof_dump_file); if (!sys_fstat(filename, &statbuf)) if (!statbuf.st_size) ret = sys_fremove(filename); } sys_free(filename); } return ; }
static void binfile_write(t_binfile *x, t_symbol *path) /* open the file for writing and write the entire buffer to it, then close it */ { size_t bytes_written = 0L; if (0==(x->x_fP = binfile_open_path(x, path->s_name, "wb"))) error("binfile: Unable to open %s for writing", path->s_name); bytes_written = fwrite(x->x_buf, 1L, x->x_length, x->x_fP); if (bytes_written != x->x_length) post("binfile: %ld bytes written != %ld", bytes_written, x->x_length); else post("binfile: wrote %ld bytes to %s", bytes_written, path->s_name); sys_fclose(x->x_fP); x->x_fP = NULL; }
static void binfile_read(t_binfile *x, t_symbol *path, t_float max_bytes) /* open the file for reading and load it into the buffer, then close it */ /* if max_bytes > 0 read only max_bytes into the buffer */ { size_t file_length = 0L; size_t bytes_read = 0L; if (0==(x->x_fP = binfile_open_path(x, path->s_name, "rb"))) { error("binfile: Unable to open %s for reading", path->s_name); return; } /* get length of file up to max_bytes */ if (max_bytes > 0) while ((EOF != getc(x->x_fP))&&(file_length < max_bytes)) ++file_length; else while (EOF != getc(x->x_fP)) ++file_length; if (file_length == 0L) return; /* get storage for file contents */ if (0 != x->x_buf) freebytes(x->x_buf, x->x_buf_length); x->x_buf = getbytes(file_length); if (NULL == x->x_buf) { x->x_buf_length = 0L; error ("binfile: unable to allocate %ld bytes for %s", file_length, path->s_name); return; } x->x_rd_offset = 0L; /* read file into buf */ rewind(x->x_fP); bytes_read = fread(x->x_buf, 1L, file_length, x->x_fP); x->x_buf_length = bytes_read; x->x_wr_offset = x->x_buf_length; /* write new data at end of file */ x->x_length = x->x_buf_length; /* file length is same as buffer size 7*/ x->x_rd_offset = 0L; /* read from start of file */ sys_fclose (x->x_fP); x->x_fP = NULL; if (bytes_read != file_length) post("binfile length %ld not equal to bytes read (%ld)", file_length, bytes_read); else post("binfile: read %ld bytes from %s", bytes_read, path->s_name); }
void close_trace() { sys_fclose(__trace); }
/** * syscall_fclose: fclose(ebx); **/ int syscall_fclose(FILE *f) { return sys_fclose(f); }