Exemple #1
0
static void *
direntname(telf_dir_hdl *dir_hdl,
           char **namep)
{
        char *name = NULL;
        telf_obj *entry = NULL;
        static char *dots[] = { ".", ".." };

        switch (dir_hdl->cursor) {
        case 0: /* handle "." */
                entry = dir_hdl->obj;
                name = dots[dir_hdl->cursor];
                break;
        case 1: /* handle ".." */
                entry = dir_hdl->obj->parent;
                name = dots[dir_hdl->cursor];
                break;
        default: /* handle ordinary entry... */
                entry = list_get_nth(dir_hdl->obj->entries, dir_hdl->cursor - 2);
                if (! entry)
                        goto end;

                name = entry->name;
        }

  end:
        if (namep)
                *namep = name;

        return entry;
}
Exemple #2
0
telf_status
libfs_readlink(void *obj_hdl,
               char **bufp,
               size_t *buf_lenp)
{
        telf_obj *obj = obj_hdl;
        telf_status ret;
        Elf64_Shdr *shdr = NULL;
        char path[PATH_MAX];
        char *buf = NULL;
        size_t buf_len = 0;
        int i;

        elf_obj_lock(obj);

        for (i = 0; i < list_get_size(obj->ctx->libpath); i++) {
                char *lp = list_get_nth(obj->ctx->libpath, i);
                char path[PATH_MAX] = "";

                snprintf(path, sizeof path, "%s/%s", lp, obj->name);

                if (-1 == access(path, R_OK)) {
                        if (ENOENT != errno)
                                ERR("access: %s", strerror(errno));

                        continue;
                }

                buf = strdup(path);
                if (! buf) {
                        ERR("malloc: %s", strerror(errno));
                        ret = ELF_ENOMEM;
                        goto end;
                }

                buf_len = strlen(buf);
                break;
        }

        ret = ELF_SUCCESS;
  end:

        elf_obj_unlock(obj);

        if (bufp)
                *bufp = buf;
        else
                free(buf);

        if (buf_lenp)
                *buf_lenp = buf_len;

        return ret;
}
Exemple #3
0
int main(int argc,char **argv) {
	char *zero, *one, *two, *three, *minusone;
	zero = strdup("Zero");
	one  = strdup("One");
	two  = strdup("Two");
	three = strdup("Three");
	minusone = strdup("-1");
	List *list = list_append(NULL,zero);
	list_append(list,one);
	list_append(list,two);
	list_append(list,three);
	list_remove_at(list,1);
	one = strdup("One");
	list_insert_at(list,1,one);
	list = list_prepend(list,minusone);
	int i;
	for(i = 0;i <= 2; i++) {
		printf("%s\n",(char *)list_get_nth(list,i)->data);
	}
	printf("\n%d\n",list_index_of(list,two));
	return 0;
}