コード例 #1
0
ファイル: files.c プロジェクト: jgraef/meinOS
static struct filelist_item *filebyfh(int fh) {
  if (fh>=0) {
    int idx = lidxbyfh(fh);
    if (idx>=0) return llist_get(filelist,idx);
  }
  return NULL;
}
コード例 #2
0
ファイル: obligation.c プロジェクト: dvandok/argus-pep-api-c
xacml_attributeassignment_t * xacml_obligation_getattributeassignment(const xacml_obligation_t * obligation,int i) {
    if (obligation == NULL) {
        log_error("xacml_obligation_getattributeassignment: NULL obligation.");
        return NULL;
    }
    return llist_get(obligation->assignments,i);
}
コード例 #3
0
ファイル: response.c プロジェクト: dvandok/argus-pep-api-c
xacml_result_t * xacml_response_getresult(const xacml_response_t * response, int index) {
    if (response == NULL) {
        log_error("xacml_response_getresult: NULL response.");
        return NULL;
    }
    return llist_get(response->results,index);
}
コード例 #4
0
ファイル: files.c プロジェクト: jgraef/meinOS
struct fslist_item *fsbyid(id_t fsid) {
  struct fslist_item *fs;
  size_t i;
  for (i=0;(fs = llist_get(fslist,i));i++) {
    if (fs->id==fsid) return fs;
  }
  return NULL;
}
コード例 #5
0
ファイル: files.c プロジェクト: jgraef/meinOS
/**
 * Gets list index by filehandle
 *  @param fh filehandle
 *  @return List index
 */
static int lidxbyfh(int fh) {
  struct filelist_item *file;
  int i;
  for (i=0;(file = llist_get(filelist,i));i++) {
    if (file->fh==fh) return i;
  }
  return -1;
}
コード例 #6
0
ファイル: files.c プロジェクト: jgraef/meinOS
/**
 * Pack filehandles
 *  @param buf Buffer
 *  @return If buf is NULL return needed size
 */
size_t _fs_pack_filehandles(pack_t buf) {
  struct filelist_item *file;
  struct fslist_item *fs;
  size_t i;

  if (buf==NULL) {
    // Prepare filesystems
    size_t size = sizeof(size_t)+llist_size(fslist)*sizeof(int)*2; // id, pid
    for (i=0;(fs = llist_get(fslist,i));i++) size += strlen(fs->mountpoint_str)+1; // mountpoint

    // Prepare files
    size += sizeof(size_t)+llist_size(filelist)*sizeof(int)*8; // fh, fs_fh, stfl, fdfl, shmid, type, mode
    for (i=0;(file = llist_get(filelist,i));i++) size += strlen(file->path)+1; // path

    return size;
  }
  else {
    // Pack filesystems
    packi(buf,llist_size(fslist));
    for (i=0;(fs = llist_get(fslist,i));i++) {
      packi(buf,fs->id);
      packi(buf,fs->pid);
      packstr(buf,fs->mountpoint_str);
    }

    // Pack files
    packi(buf,llist_size(filelist));
    for (i=0;(file = llist_get(filelist,i));i++) {
      if (file->type!=FL_DIR && !FLAG_ISSET(file->fdfl,FD_CLOEXEC)) {
        packi(buf,file->fh);
        packi(buf,file->fs_fh);
        packi(buf,file->shmid);
        packi(buf,file->type);
        packi(buf,file->mode);
        packi(buf,file->stfl);
        packi(buf,file->fdfl);
        packi(buf,file->fs->id);
        packstr(buf,file->path);
      }
    }

    return 0;
  }
}
コード例 #7
0
ファイル: files.c プロジェクト: jgraef/meinOS
/**
 * Match mountpoint
 *  @param file Path to file
 *  @param parent If FS of parent directory of file is needed
 *  @return FS List item
 */
static struct fslist_item *mp_match(char *file,int parent) {
  size_t i,curcmp;
  size_t maxcmp = 0;
  struct fslist_item *fs;
  struct fslist_item *maxfs = NULL;
  path_t *path = path_parse(file);

  if (parent) path_parent(path);

  for (i=0;(fs = llist_get(fslist,i));i++) {
    curcmp = path_compare(path,fs->mountpoint);
    if (curcmp>maxcmp) {
      maxcmp = curcmp;
      maxfs = fs;
    }
  }

  if (maxfs!=NULL) memmove(file,file+strlen(maxfs->mountpoint_str),strlen(file)-strlen(maxfs->mountpoint_str)+1);
  if (file[0]==0) strcpy(file,"/");

  return maxfs;
}
コード例 #8
0
ファイル: linkedlist.c プロジェクト: dvandok/argus-pep-api-c
int llist_delete_elements(linkedlist_t * list, delete_element_func deletef) {
    size_t list_l;
    void ** unique_elts;
    void * elt, * unique_elt;
    int unique_elts_l, i, j, duplicated;
    if (list == NULL) {
        log_error("llist_delete_elements: NULL pointer list.");
        return LLIST_ERROR;
    }
    /* WARN: the list can contains many times the same element (same memory address) */
    list_l= llist_length(list);
    unique_elts= calloc(list_l,sizeof(void *));
    unique_elts_l= 0, i= 0, j= 0;
    for (i=0; i<list_l; i++) {
        elt= llist_get(list,i);
        /* add elt to elts list if not already included */
        duplicated= 0;
        for(j= 0; j<unique_elts_l; j++) {
            if (elt == unique_elts[j]) {
                duplicated= 1;
            }
        }
        if (!duplicated) {
            /* add at end */
            unique_elts[unique_elts_l++]= elt;
        }
    }
    /* apply delete func on unique element */
    for(i= 0; i<unique_elts_l; i++) {
        unique_elt= unique_elts[i];
        if (deletef) {
            deletef(unique_elt);
        }
    }
    free(unique_elts);
    return LLIST_OK;
}
コード例 #9
0
ファイル: driver.c プロジェクト: carl-ellis/c_refresher
int main(int argc, char* argv[])
{
	int i;
	node * m;

	/* obligatory */
	printf("Hello, World\r\n");
	printf("\r\n---\r\n");

	/* Node stuff */

	printf("Creating and destroying 10000 nodes\r\n");
	for (i = 0; i < 10000 ; i++)
	{
		int data = i;
		node * n = build_node(&data);
		destroy_node(n);
	}
	printf("Done\r\n");

	printf("\r\n---\r\n");

	printf("Building a queue, adding 10000 nodes. Printing out every 1000\r\n");
	queue * q = build_queue();

	for (i = 0; i < 10000 ; i++)
	{
		int data = i;
		node * n = build_node(&data);
		queue_push(q, n);
	}
	printf("Queue has the size %d\r\n", q->size);

	for (i = 0; i < 10000 ; i++)
	{
		node * n = queue_pop(q);
		if((i%1000)==0)
		{
			printf("Node has the data %d\r\n", *(int*)n->data);
		}
		destroy_node(n);
	}
	printf("Queue has the size %d\r\n", q->size);

	destroy_queue(q);
	printf("\r\n---\r\n");

	printf("Building a stack, adding 10000 nodes. Printing out every 1000\r\n");
	stack * s = build_stack();

	for (i = 0; i < 10000 ; i++)
	{
		int data = i;
		node * n = build_node(&data);
		stack_push(s, n);
	}
	printf("Stack has the size %d\r\n", s->size);

	for (i = 0; i < 10000 ; i++)
	{
		node * n = stack_pop(s);
		if((i%1000)==0)
		{
			printf("Node has the data %d\r\n", *(int*)n->data);
		}
		destroy_node(n);
	}
	printf("Stack has the size %d\r\n", s->size);

	destroy_stack(s);
	printf("\r\n---\r\n");
	
	printf("Building a linked list, adding 10000 nodes. Printing out every 1000\r\n");
	llist * l = build_llist();

	for (i = 0; i < 10000 ; i++)
	{
		int data = i;
		node * n = build_node(&data);
		llist_add(l, n);
	}
	printf("llist has the size %d\r\n", l->size);
	
	printf("Testing arbitrary access...\r\n");
	m = llist_get(l, 87);
  printf("Node has the data %d\r\n", *(int*)m->data);
  m = llist_get(l, 3487);
  printf("Node has the data %d\r\n", *(int*)m->data);
  m = llist_get(l, 287);
  printf("Node has the data %d\r\n", *(int*)m->data);
  
  printf("Testing arbitrary delete...\r\n");
  
  m = llist_get(l, 299);
  printf("Node has the data %d\r\n", *(int*)m->data);
  llist_delete(l, 299);
  m = llist_get(l, 299);
  printf("Node has the data %d\r\n", *(int*)m->data);

	printf("Testing mass delete...\r\n");
	destroy_llist(l);
	
	printf("\r\n---\r\n");
	
	printf("Creating and destroying 10000 single trees\r\n");
	for (i = 0; i < 10000 ; i++)
	{
		int data = i;
		tree * n = build_tree(&data);
		destroy_tree(n);
	}
	printf("Done\r\n");

	printf("\r\n---\r\n");
	
	printf("Testing add/delete for trees\r\n");
	int data = 2;
	tree * root = build_tree(&data);
	
	//for (i = 0; i < 3 ; i++)
//	{
//		int data = i;
//		tree * n = build_tree(&data);
//		destroy_tree(n);
//		add_leaf(&root, n, &tree_int_comp);
//	}
	
	data = 1;
	tree * leaf1 = build_tree(&data);
	add_leaf(&root, leaf1, &tree_int_comp);
	
	data = 0;
	tree * leaf2 = build_tree(&data);
	add_leaf(&root, leaf2, &tree_int_comp);
	
	printf("Root node has value %d before deletion\r\n", *(int*)root->data);
	delete_node(&(root));
	printf("Root node has value %d after deletion\r\n", *(int*)root->data);
	
	destroy_tree(leaf1);
	destroy_tree(leaf2);
	
	printf("Done\r\n");

	return 0;
}