示例#1
0
文件: main.c 项目: floklein/42
char	*ft_get_first_line(int fd, t_map *map_info)
{
	t_list	*root;
	t_list	*node;
	int		deep;

	root = NULL;
	deep = 0;
	ft_list_push_back(&root);
	node = root;
	while (read(fd, &(node->c), 1) > 0)
	{
		deep++;
		if (node->c == '\n')
			return ((deep == 1) ? NULL : ft_list_to_tab(root, deep));
		if (map_info)
			if (ft_strf(node->c, map_info->charset))
			{
				ft_destroy(root);
				return (NULL);
			}
		ft_list_push_back(&node);
		node = node->next;
	}
	return (NULL);
}
示例#2
0
indigo_error_t
ind_core_finish(void)
{
    LOG_TRACE("OF state mgr finish called");

    /* Indicate core is shutting down */
    if (ind_core_module_enabled) {
        LOG_VERBOSE("Finish is calling disable");
        ind_core_enable_set(0);
    }

    ft_destroy(ind_core_ft);

    ind_core_init_done = 0;

    return INDIGO_ERROR_NONE;
}
示例#3
0
/*
 * ft_create()
 * Creates a file table that is attached to the thread library.
 * 
 */
struct filetable *ft_create() {
    //Allocate memory for the filetable structures
    struct filetable *ft = kmalloc(sizeof (struct filetable));
    if (ft == NULL) {
        return NULL;
    }
    ft->size = 0;
    //Allocate memory for the array of file descriptors
    ft->filedescriptor = array_create();
    if (ft->filedescriptor == NULL) {
        ft_destroy(ft);
        return NULL;
    }
    //preallocate the array to 20 files
    array_preallocate(ft->filedescriptor, 20);
    //Reserve the first three file descriptors for in out err.
    array_add(ft->filedescriptor, NULL);
    array_add(ft->filedescriptor, NULL);
    array_add(ft->filedescriptor, NULL);
    //Return the file table
    return ft;
}
示例#4
0
void			ft_list_clear(t_list **begin_list)
{
	ft_destroy(*begin_list);
	*begin_list = NULL;
}
示例#5
0
static void		ft_destroy(t_list *list)
{
	if (list->next != NULL)
		ft_destroy(list->next);
	free(list);
}
示例#6
0
/*
 * ft_attachstds()
 * Attach the standard in, out, err to the file table, this can't be located the
 * ft_create function because that the device "con:" etc are not attached to the
 * list of device when the os is the boot sequence.
 */
int ft_attachstds(struct filetable *ft) {
    char *console = NULL;
    int mode;
    int result = 0;
    //STDIN
    struct vnode *vn_stdin;
    mode = O_RDONLY;
    struct filedescriptor *fd_stdin = NULL;
    fd_stdin = (struct filedescriptor *) kmalloc(sizeof ( struct filedescriptor));
    if (fd_stdin == NULL) {
        ft_destroy(ft);
        return 0;
    }
    console = kstrdup("con:");
    result = vfs_open(console, mode, &vn_stdin);
    if (result) {
        vfs_close(vn_stdin);
        ft_destroy(ft);
        return 0;
    }
    kfree(console);
    fd_stdin->mode = mode;
    fd_stdin->offset = 0;
    fd_stdin->fdvnode = vn_stdin;
    fd_stdin->numOwners = 1;
    ft_set(ft, fd_stdin, STDIN_FILENO);
    //STDOUT
    struct vnode *vn_stdout;
    mode = O_WRONLY;
    struct filedescriptor *fd_stdout = NULL;
    fd_stdout = (struct filedescriptor *) kmalloc(sizeof (struct filedescriptor));
    if (fd_stdout == NULL) {
        ft_destroy(ft);
        return 0;
    }
    console = kstrdup("con:");
    result = vfs_open(console, mode, &vn_stdout);
    if (result) {
        vfs_close(vn_stdout);
        ft_destroy(ft);
        return 0;
    }
    kfree(console);
    fd_stdout->mode = mode;
    fd_stdout->offset = 0;
    fd_stdout->fdvnode = vn_stdout;
    fd_stdout->numOwners = 1;
    ft_set(ft, fd_stdout, STDOUT_FILENO);
    //STDERR
    struct vnode *vn_stderr;
    mode = O_WRONLY;
    struct filedescriptor *fd_stderr = NULL;
    fd_stderr = (struct filedescriptor *) kmalloc(sizeof (struct filedescriptor));
    if (fd_stderr == NULL) {
        ft_destroy(ft);
        return 0;
    }
    console = kstrdup("con:");
    result = vfs_open(console, mode, &vn_stderr);
    if (result) {
        vfs_close(vn_stderr);
        ft_destroy(ft);
        return 0;
    }
    kfree(console);
    fd_stderr->mode = mode;
    fd_stderr->offset = 0;
    fd_stderr->fdvnode = vn_stderr;
    fd_stderr->numOwners = 1;
    ft_set(ft, fd_stderr, STDERR_FILENO);
    return 1;
}
示例#7
0
文件: ft.c 项目: kenchiang/indigo
ft_instance_t
ft_create(ft_config_t *config)
{
    ft_instance_t ft;
    int bytes;
    int idx;

    if (config->max_entries <= 0) {
        LOG_ERROR("Hash flow table only supports fixed number of buckets");
        return NULL;
    }

    /* Allocate the flow table itself */
    ft = INDIGO_MEM_ALLOC(sizeof(*ft));
    if (ft == NULL) {
        LOG_ERROR("ERROR: Flow table (hash) creation failed");
        return NULL;
    }
    INDIGO_MEM_SET(ft, 0, sizeof(*ft));
    INDIGO_MEM_COPY(&ft->config,  config, sizeof(ft_config_t));

    list_init(&ft->free_list);
    list_init(&ft->all_list);

    /* Allocate and init the flow entries */
    bytes = sizeof(ft_entry_t) * config->max_entries;
    ft->flow_entries = INDIGO_MEM_ALLOC(bytes);
    if (ft->flow_entries == NULL) {
        LOG_ERROR("ERROR: Flow table (hash) creation failed");
        INDIGO_MEM_FREE(ft);
        return NULL;
    }
    INDIGO_MEM_SET(ft->flow_entries, 0, bytes);

    /* Put the flow entries on the free list */
    for (idx = 0; idx < config->max_entries; idx++) {
        list_push(&ft->free_list, &ft->flow_entries[idx].table_links);
    }

    /* Allocate and init buckets for each search type */
    bytes = sizeof(list_head_t) * config->prio_bucket_count;
    ft->prio_buckets = INDIGO_MEM_ALLOC(bytes);
    if (ft->prio_buckets == NULL) {
        LOG_ERROR("ERROR: Flow table, prio bucket alloc failed");
        ft_destroy(ft);
        return NULL;
    }
    INDIGO_MEM_SET(ft->prio_buckets, 0, bytes);
    for (idx = 0; idx < config->prio_bucket_count; idx++) {
        list_init(&ft->prio_buckets[idx]);
    }

    bytes = sizeof(list_head_t) * config->match_bucket_count;
    ft->match_buckets = INDIGO_MEM_ALLOC(bytes);
    if (ft->match_buckets == NULL) {
        LOG_ERROR("ERROR: Flow table, match bucket alloc failed");
        ft_destroy(ft);
        return NULL;
    }
    INDIGO_MEM_SET(ft->match_buckets, 0, bytes);
    for (idx = 0; idx < config->match_bucket_count; idx++) {
        list_init(&ft->match_buckets[idx]);
    }

    bytes = sizeof(list_head_t) * config->flow_id_bucket_count;
    ft->flow_id_buckets = INDIGO_MEM_ALLOC(bytes);
    if (ft->flow_id_buckets == NULL) {
        LOG_ERROR("ERROR: Flow table, flow id bucket alloc failed");
        ft_destroy(ft);
        return NULL;
    }
    INDIGO_MEM_SET(ft->flow_id_buckets, 0, bytes);
    for (idx = 0; idx < config->flow_id_bucket_count; idx++) {
        list_init(&ft->flow_id_buckets[idx]);
    }

    return ft;
}