Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 76b732c3c7da3519a1ce9339b9f8dacfa5c5a352
  • master par défaut protégée
  • rust-playlist-sync
  • rust
  • fix-qt-deprecated-qvariant-type
  • fix-mpris-qtwindow-race-condition
  • rust-appimage-wayland
  • windows-build-rebased
  • v2.5 protégée
  • v2.4 protégée
  • v2.3-1 protégée
  • v2.3 protégée
  • v2.2 protégée
  • v2.1 protégée
  • v2.0 protégée
  • v1.8-3 protégée
  • v1.8-2 protégée
  • v1.8-1 protégée
  • v1.8 protégée
  • v1.7 protégée
  • v1.6 protégée
  • v1.5 protégée
  • v1.4 protégée
  • v1.3 protégée
  • v1.2 protégée
  • v1.1 protégée
  • v1.0 protégée
27 résultats

stack.c

Blame
  • stack.c 1,41 Kio
    #define _POSIX_C_SOURCE 200809L
    #include <common/stack.h>
    #include <common/common.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    int
    stack_new(struct stack *ret)
    {
        if (!ret)
            return 1;
    
        struct stack _ret = {
            .contents = malloc(LKT_DEFAULT_LIST_SIZE * sizeof(void *)),
            .size = LKT_DEFAULT_LIST_SIZE,
            .len = 0,
        };
    
        if (_ret.contents == NULL)
            return 1;
    
        *ret = _ret;
        return 0;
    }
    
    void
    stack_free(struct stack *lst)
    {
        if (!lst)
            return;
    
        if (lst->contents)
            free(lst->contents);
    
        lst->size = 0;
        lst->len  = 0;
    }
    
    int
    stack_empty(struct stack *lst)
    {
        if (!lst || !lst->contents || !lst->len)
            return 1;
        return 0;
    }
    
    int
    stack_push(struct stack *lst, void *item)
    {
        if (!lst)
            return 1;
    
        if (lst->size == lst->len) {
            volatile void **new = realloc(lst->contents,
                                          lst->size * 2 * sizeof(void *));
    
            if (NULL == new)
                return 1;
    
            lst->contents = new;
            lst->size *= 2;
        }
    
        lst->contents[(lst->len)++] = item;
        return 0;
    }
    
    int
    stack_pop(struct stack *lst, void **item)
    {
        if (!lst || !lst->len)
            return 1;
    
        *item = (void *) lst->contents[--(lst->len)];
        return 0;
    }
    
    int
    stack_head(struct stack *lst, void **item)
    {
        if (!lst || !lst->len)
            return 1;
    
        *item = (void *) lst->contents[lst->len - 1];
        return 0;
    }