Ignore:
Timestamp:
Aug 2, 2006, 3:12:43 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Fixed libcaca prototypes so that all functions use the errno mechanism and return a value.
Location:
libcaca/trunk/caca
Files:
9 edited

Legend:

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

    r984 r1006  
    2424#   include <stdlib.h>
    2525#   include <string.h>
     26#   if defined(HAVE_ERRNO_H)
     27#       include <errno.h>
     28#   endif
    2629#endif
    2730
     
    3134#include "caca_internals.h"
    3235
    33 static int caca_init_driver(caca_display_t *dp);
     36static int caca_select_driver(caca_display_t *dp);
    3437
    3538/** \brief Attach a caca graphical context to a cucul canvas.
     
    4043 *  then be displayed by the libcaca driver.
    4144 *
     45 *  If an error occurs, NULL is returned and \b errno is set accordingly:
     46 *  - \c ENOMEM Not enough memory.
     47 *  - \c ENODEV Graphical device could not be initialised.
     48 *
    4249 *  \param cv The cucul cavas.
    4350 *  \return The caca graphical context or NULL if an error occurred.
     
    4754    caca_display_t *dp = malloc(sizeof(caca_display_t));
    4855
     56    if(!dp)
     57    {
     58#if defined(HAVE_ERRNO_H)
     59        errno = ENOMEM;
     60#endif
     61        return NULL;
     62    }
     63
    4964    dp->cv = cv;
    5065
    51     if(caca_init_driver(dp))
     66    if(caca_select_driver(dp))
    5267    {
    5368        free(dp);
     69#if defined(HAVE_ERRNO_H)
     70        errno = ENODEV;
     71#endif
    5472        return NULL;
    5573    }
     
    5876    {
    5977        free(dp);
     78#if defined(HAVE_ERRNO_H)
     79        errno = ENODEV;
     80#endif
    6081        return NULL;
    6182    }
     
    100121 *  attached to it afterwards.
    101122 *
     123 *  This function never fails.
     124 *
    102125 *  \param dp The libcaca graphical context.
    103  */
    104 void caca_free_display(caca_display_t *dp)
     126 *  \return This function always returns 0.
     127 */
     128int caca_free_display(caca_display_t *dp)
    105129{
    106130    dp->drv.end_graphics(dp);
    107131    dp->cv->refcount--;
    108132    free(dp);
     133
     134    return 0;
    109135}
    110136
     
    113139 */
    114140
    115 static int caca_init_driver(caca_display_t *dp)
     141static int caca_select_driver(caca_display_t *dp)
    116142{
    117143#if defined(HAVE_GETENV) && defined(HAVE_STRCASECMP)
  • libcaca/trunk/caca/caca.h

    r969 r1006  
    151151 *  @{ */
    152152caca_display_t * caca_create_display(cucul_canvas_t *);
    153 void caca_free_display(caca_display_t *);
    154 void caca_refresh_display(caca_display_t *);
    155 void caca_set_display_time(caca_display_t *, unsigned int);
     153int caca_free_display(caca_display_t *);
     154int caca_refresh_display(caca_display_t *);
     155int caca_set_display_time(caca_display_t *, unsigned int);
    156156unsigned int caca_get_display_time(caca_display_t *);
    157157unsigned int caca_get_display_width(caca_display_t *);
     
    169169unsigned int caca_get_mouse_x(caca_display_t *);
    170170unsigned int caca_get_mouse_y(caca_display_t *);
    171 void caca_set_mouse(caca_display_t *, int);
     171int caca_set_mouse(caca_display_t *, int);
    172172/*  @} */
    173173
  • libcaca/trunk/caca/driver_conio.c

    r979 r1006  
    8080static int conio_set_display_title(caca_display_t *dp, char const *title)
    8181{
    82     return 0;
     82    return -1;
    8383}
    8484
  • libcaca/trunk/caca/driver_ncurses.c

    r986 r1006  
    179179static int ncurses_set_display_title(caca_display_t *dp, char const *title)
    180180{
    181     return 0;
     181    return -1;
    182182}
    183183
  • libcaca/trunk/caca/driver_raw.c

    r859 r1006  
    4040static int raw_set_display_title(caca_display_t *dp, char const *title)
    4141{
    42     return 0;
     42    return -1;
    4343}
    4444
  • libcaca/trunk/caca/driver_slang.c

    r986 r1006  
    184184{
    185185    /* FIXME */
    186     return 0;
     186    return -1;
    187187}
    188188
  • libcaca/trunk/caca/driver_vga.c

    r859 r1006  
    9898{
    9999    /* Unsupported, of course. */
    100     return 0;
     100    return -1;
    101101}
    102102
  • libcaca/trunk/caca/event.c

    r969 r1006  
    4545 *  This function polls the event queue for mouse or keyboard events matching
    4646 *  the event mask and returns the first matching event. Non-matching events
    47  *  are discarded. \c event_mask must have a non-zero value.
     47 *  are discarded. If \c event_mask is zero, the function returns immediately.
    4848 *
    4949 *  The timeout value tells how long this function needs to wait for an
     
    5555 *  received. If null, the function will return but no information about
    5656 *  the event will be sent.
     57 *
     58 *  This function never fails.
    5759 *
    5860 *  \param dp The libcaca graphical context.
     
    118120 *  the mouse is clicked. Other drivers such as X11 work well.
    119121 *
     122 *  This function never fails.
     123 *
    120124 *  \param dp The libcaca graphical context.
    121125 *  \return The X mouse coordinate.
     
    135139 *  drivers are being used, because mouse position is only detected when
    136140 *  the mouse is clicked. Other drivers such as X11 work well.
     141 *
     142 *  This function never fails.
    137143 *
    138144 *  \param dp The libcaca graphical context.
  • libcaca/trunk/caca/graphics.c

    r985 r1006  
    1919#include "common.h"
    2020
     21#if !defined(__KERNEL__)
     22#   if defined(HAVE_ERRNO_H)
     23#       include <errno.h>
     24#   endif
     25#endif
     26
    2127#include "caca.h"
    2228#include "caca_internals.h"
     
    2733 *
    2834 *  If libcaca runs in a window, try to change its title. This works with
    29  *  the X11 and Win32 drivers.
     35 *  the OpenGL, X11 and Win32 drivers.
     36 *
     37 *  If an error occurs, -1 is returned and \b errno is set accordingly:
     38 *  - \c ENOSYS Display driver does not support setting the window title.
    3039 *
    3140 *  \param dp The libcaca display context.
    3241 *  \param title The desired display title.
    33  *  \return 0 upon success, a non-zero value if an error occurs.
     42 *  \return 0 upon success, -1 if an error occurred.
    3443 */
    3544int caca_set_display_title(caca_display_t *dp, char const *title)
    3645{
    37     return dp->drv.set_display_title(dp, title);
     46    int ret = dp->drv.set_display_title(dp, title);
     47
     48#if defined(HAVE_ERRNO_H)
     49    if(ret)
     50        errno = ENOSYS;
     51#endif
     52
     53    return ret;
    3854}
    3955
     
    4561 *  6x10 font is being used. Note that the units are not necessarily pixels.
    4662 *
     63 *  This function never fails.
     64 *
    4765 *  \param dp The libcaca display context.
    4866 *  \return The display width.
     
    6078 *  used. Note that the units are not necessarily pixels.
    6179 *
     80 *  This function never fails.
     81 *
    6282 *  \param dp The libcaca display context.
    6383 *  \return The display height.
     
    7797 *  default behaviour.
    7898 *
     99 *  This function never fails.
     100 *
    79101 *  \param dp The libcaca display context.
    80102 *  \param usec The refresh delay in microseconds.
    81  */
    82 void caca_set_display_time(caca_display_t *dp, unsigned int usec)
     103 *  \return This function always returns 0.
     104 */
     105int caca_set_display_time(caca_display_t *dp, unsigned int usec)
    83106{
    84107    dp->delay = usec;
     108    return 0;
    85109}
    86110
     
    93117 *  delay even if the real rendering time was shorter.
    94118 *
     119 *  This function never fails.
     120 *
    95121 *  \param dp The libcaca display context.
    96122 *  \return The render time in microseconds.
     
    113139 *  the second call will be delayed before performing the screen refresh.
    114140 *
    115  *  \param dp The libcaca display context.
    116  */
    117 void caca_refresh_display(caca_display_t *dp)
     141 *  This function never fails.
     142 *
     143 *  \param dp The libcaca display context.
     144 *  \return This function always returns 0.
     145 */
     146int caca_refresh_display(caca_display_t *dp)
    118147{
    119148#if !defined(_DOXYGEN_SKIP_ME)
     
    148177    if(dp->lastticks > (int)dp->delay)
    149178        dp->lastticks = 0;
     179
     180    return 0;
    150181}
    151182
     
    155186 *  support it.
    156187 *
     188 *  If an error occurs, -1 is returned and \b errno is set accordingly:
     189 *  - \c ENOSYS Display driver does not support hiding the mouse pointer.
     190 *
    157191 *  \param dp The libcaca display context.
    158192 *  \param flag 0 hides the pointer, 1 shows the system's default pointer
    159193 *              (usually an arrow). Other values are reserved for future use.
    160  */
    161 void caca_set_mouse(caca_display_t *dp, int flag)
    162 {
    163     if(dp->drv.set_mouse)
    164         dp->drv.set_mouse(dp, flag);
     194 *  \return 0 upon success, -1 if an error occurred.
     195 */
     196int caca_set_mouse(caca_display_t *dp, int flag)
     197{
     198    if(!dp->drv.set_mouse)
     199    {
     200#if defined(HAVE_ERRNO_H)
     201        errno = ENOSYS;
     202#endif
     203        return -1;
     204    }
     205
     206    dp->drv.set_mouse(dp, flag);
     207    return 0;
    165208}
    166209
Note: See TracChangeset for help on using the changeset viewer.