void test_klist_append () { TASSERT(l1 != NULL); klist_append(l1, (void *)item2); klist_append(l1, (void *)item3); klist_prepend(l1, (void *)item1); TASSERT(l1->length == 3); }
int open(const unsigned char *path, int modeflags) { unsigned char path2[MAX_PATH]; FSInterface *fs=NULL; BlockDeviceIF *device=NULL; prepare_path(path, (unsigned char*)path2, sizeof(path2)); fs_vfs_get((char*) path2, &fs, &device); FSFile *file = kmalloc(sizeof(FSFile)); memset(file, 0, sizeof(*file)); _fs_file_init(file); file->fs = fs; file->device = device; file->access = modeflags; file->internalfd = file->fs->open(file->fs, file->device, path2, strlen(path2), modeflags); if (file->internalfd < 0) { kfree(file); return -1; } LinkNode *node = kmalloc(sizeof(LinkNode)); node->data = file; Process *p = process_get_current(0); klist_append(&p->open_files, node); return (int)file; }
void test_klist_iterator() { int i=0; int d1 = 1; int d2 = 2; int *d; klist_reset(l1); klist_append(l1, &d1); klist_append(l1, &d2); struct klist_iter iter; klist_iter_init(&iter, l1); kiter_next(&iter, NULL); while (kiter_remove(&iter, &d) == 0) { i++; TASSERT(*d == i); } TASSERT(i == 2); }
void klist_init_klist(klist *self, klist *init_list) { struct klist_iter list_iter; kiter *iter = (kiter *)&list_iter; void *data; klist_init(self); klist_iter_init(&list_iter, init_list); while (kiter_next(iter, &data)) klist_append(self, data); }