made error codes negative

Tue, 26 Aug 2008 19:14:23 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Tue, 26 Aug 2008 19:14:23 +0100
changeset 4
81d49d42ad6a
parent 3
93f5d26366ad
child 5
2fc2b426ace9

made error codes negative
tweaked lpfk_read to return an error constant instead of a magic number

include/liblpfk.h file | annotate | diff | revisions
src/liblpfk.c file | annotate | diff | revisions
     1.1 --- a/include/liblpfk.h	Tue Aug 26 18:45:45 2008 +0100
     1.2 +++ b/include/liblpfk.h	Tue Aug 26 19:14:23 2008 +0100
     1.3 @@ -66,11 +66,12 @@
     1.4   */
     1.5  enum {
     1.6  	LPFK_E_OK = 0,				///< No error, success.
     1.7 -	LPFK_E_PORT_OPEN,			///< Could not open comm port.
     1.8 -	LPFK_E_NOT_PRESENT,			///< LPFK not present on specified port.
     1.9 -	LPFK_E_COMMS,				///< Communication error.
    1.10 -	LPFK_E_PARAM,				///< Invalid function parameter.
    1.11 -LPFK_E_NOT_ENABLED			///< Attempt to read key when LPFK disabled
    1.12 +	LPFK_E_NO_KEYS = -1,		///< No keys in input buffer
    1.13 +	LPFK_E_PORT_OPEN = -2,		///< Could not open comm port.
    1.14 +	LPFK_E_NOT_PRESENT = -3,	///< LPFK not present on specified port.
    1.15 +	LPFK_E_COMMS = -4,			///< Communication error.
    1.16 +	LPFK_E_PARAM = -5,			///< Invalid function parameter.
    1.17 +	LPFK_E_NOT_ENABLED = -6		///< Attempt to read key when LPFK disabled
    1.18  };
    1.19  
    1.20  /**
    1.21 @@ -159,7 +160,7 @@
    1.22  /**
    1.23   * @brief	Read a key from the LPFK
    1.24   * @param	ctx		Pointer to an LPFK_CTX struct initialised by lpfk_open().
    1.25 - * @return	-1 if no keys in buffer, 0-31 for key 1-32 down.
    1.26 + * @return	LPFK_E_NO_KEYS if no keys in buffer, 0-31 for key 1-32 down.
    1.27   */
    1.28  int lpfk_read(LPFK_CTX *ctx);
    1.29  
     2.1 --- a/src/liblpfk.c	Tue Aug 26 18:45:45 2008 +0100
     2.2 +++ b/src/liblpfk.c	Tue Aug 26 19:14:23 2008 +0100
     2.3 @@ -361,7 +361,7 @@
     2.4  
     2.5  	if ((nbytes < 1) || (key > 31)) {
     2.6  		// no keys buffered, or keycode invalid.
     2.7 -		return -1;
     2.8 +		return LPFK_E_NO_KEYS;
     2.9  	} else {
    2.10  		// key buffered, pass it along.
    2.11  		return key;