Ignore:
Timestamp:
Apr 19, 2008, 9:25:52 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • Remove all unsigned ints from exported functions. Signed arithmetic is far better for error checking.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/cucul.c

    r2300 r2305  
    3434#include "cucul_internals.h"
    3535
    36 static int cucul_resize(cucul_canvas_t *, unsigned int, unsigned int);
     36static int cucul_resize(cucul_canvas_t *, int, int);
    3737
    3838/** \brief Initialise a \e libcucul canvas.
     
    4747 *
    4848 *  If an error occurs, NULL is returned and \b errno is set accordingly:
     49 *  - \c EINVAL Specified width or height is invalid.
    4950 *  - \c ENOMEM Not enough memory for the requested canvas size.
    5051 *
     
    5354 *  \return A libcucul canvas handle upon success, NULL if an error occurred.
    5455 */
    55 cucul_canvas_t * cucul_create_canvas(unsigned int width, unsigned int height)
    56 {
    57     cucul_canvas_t *cv = malloc(sizeof(cucul_canvas_t));
     56cucul_canvas_t * cucul_create_canvas(int width, int height)
     57{
     58    cucul_canvas_t *cv;
     59
     60    if(width < 0 || height < 0)
     61    {
     62        seterrno(EINVAL);
     63        return NULL;
     64    }
     65
     66    cv = malloc(sizeof(cucul_canvas_t));
    5867
    5968    if(!cv)
     
    191200 *
    192201 *  If an error occurs, -1 is returned and \b errno is set accordingly:
     202 *  - \c EINVAL Specified width or height is invalid.
    193203 *  - \c EBUSY The canvas is in use by a display driver and cannot be resized.
    194204 *  - \c ENOMEM Not enough memory for the requested canvas size. If this
     
    200210 *  \return 0 in case of success, -1 if an error occurred.
    201211 */
    202 int cucul_set_canvas_size(cucul_canvas_t *cv, unsigned int width,
    203                                               unsigned int height)
    204 {
     212int cucul_set_canvas_size(cucul_canvas_t *cv, int width, int height)
     213{
     214    if(width < 0 || height < 0)
     215    {
     216        seterrno(EINVAL);
     217        return -1;
     218    }
     219
    205220    if(cv->refcount && cv->resize_callback
    206221        && !cv->resize_callback(cv->resize_data))
     
    222237 *  \return The canvas width.
    223238 */
    224 unsigned int cucul_get_canvas_width(cucul_canvas_t const *cv)
     239int cucul_get_canvas_width(cucul_canvas_t const *cv)
    225240{
    226241    return cv->width;
     
    236251 *  \return The canvas height.
    237252 */
    238 unsigned int cucul_get_canvas_height(cucul_canvas_t const *cv)
     253int cucul_get_canvas_height(cucul_canvas_t const *cv)
    239254{
    240255    return cv->height;
     
    293308int cucul_free_canvas(cucul_canvas_t *cv)
    294309{
    295     unsigned int f;
     310    int f;
    296311
    297312    if(cv->refcount)
     
    357372 */
    358373
    359 int cucul_resize(cucul_canvas_t *cv, unsigned int width, unsigned int height)
    360 {
    361     unsigned int x, y, f, old_width, old_height, new_size, old_size;
     374int cucul_resize(cucul_canvas_t *cv, int width, int height)
     375{
     376    int x, y, f, old_width, old_height, new_size, old_size;
    362377
    363378    old_width = cv->width;
     
    427442        /* New width is smaller. Copy as many lines as possible. Ignore
    428443         * the first line, it is already in place. */
    429         unsigned int lines = height < old_height ? height : old_height;
     444        int lines = height < old_height ? height : old_height;
    430445
    431446        for(f = 0; f < cv->framecount; f++)
Note: See TracChangeset for help on using the changeset viewer.