Welcome to little lamb

Code » limb » master » tree

[master] / src / include / err.h

/* This file is part of limb                           https://lila.oss/limb
 * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LIMB_ERR_H
#define LIMB_ERR_H

/* return values common to most functions in limb.*/
enum {
    ERR_OK          =  0, /* success */
    ERR_MEM         = -1,
    ERR_IO          = -2,
    ERR_DATA        = -3, /* invalid data */
    /* constructor-specific */
    ERR_CB_PREINODE = -20,
    ERR_CB_INODE    = -21,
    ERR_CB_DATA     = -22,
    ERR_CB_ROOT     = -23,
    /* for general/uncategorized errors */
    ERR_MISC        = -254,
    /* something weird, should never happen. used for e.g. as init of ret */
    ERR_UNKNOWN     = -255
};


/* merge a user return code r which *MUST BE* < 0 with an error code which *MUST
 * BE* < 0 and > -256 into a single int (negative) value, from which both codes
 * can then be extracted. */
#define SET_ERR(err,r)  -(-r << 8 | -err)
/* get the/our error code from the previous merging */
#define GET_ERR(r)      -(-r & 0xFF)
/* get the user code from the previous merging */
#define GET_USER_ERR(r) -(-r >> 8)

#endif /* LIMB_ERR_H */