+void add_file(struct processtop *proc, struct files *file, int fd)
+{
+ if (proc->process_files_table->len <= fd) {
+ g_ptr_array_set_size(proc->process_files_table, fd);
+ g_ptr_array_add(proc->process_files_table, file);
+ } else {
+ g_ptr_array_index(proc->process_files_table, fd) = file;
+ }
+ file->fd = fd;
+}
+
+
+void insert_file(struct processtop *proc, int fd)
+{
+ struct files *tmp;
+
+ if (fd >= proc->process_files_table->len) {
+ tmp = g_new0(struct files, 1);
+ tmp->name = "Unknown";
+ add_file(proc, tmp, fd);
+ } else {
+
+ tmp = g_ptr_array_index(proc->process_files_table, fd);
+ if (tmp == NULL) {
+ tmp = g_new0(struct files, 1);
+ tmp->name = "Unknown";
+ tmp->read = 0;
+ tmp->write = 0;
+ tmp->fd = fd;
+ add_file(proc, tmp, fd);
+ }
+ }
+}
+
+void close_file(struct processtop *proc, int fd)
+{
+ int len;
+
+ len = proc->process_files_table->len;
+
+ /*
+ * It is possible that a file was open before taking the trace
+ * and its fd could be greater than all of the others fd
+ * used by the process
+ */
+ if (fd < len) {
+ g_ptr_array_remove_index_fast(proc->process_files_table, fd);
+ g_ptr_array_set_size(proc->process_files_table, len + 1);
+ }
+}
+
+struct files *get_file(struct processtop *proc, int fd)
+{
+ struct files *tmp;
+ tmp = g_ptr_array_index(proc->process_files_table, fd);
+ return tmp;
+}
+
+void show_table(GPtrArray *tab)
+{
+ int i;
+ struct files *file;
+
+ for (i = 0 ; i < tab->len; i++) {
+ file = g_ptr_array_index(tab, i);
+ if (file == NULL)
+ fprintf(stderr, "NULL, ");
+ else
+ fprintf(stderr, "%s, ", file->name);
+ }
+ fprintf(stderr, "]\n\n");
+}