summaryrefslogtreecommitdiff
path: root/libgphoto2_port/libgphoto2_port
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2014-07-22 21:00:32 +0000
committerMarcus Meissner <marcus@jet.franken.de>2014-07-22 21:00:32 +0000
commitb06e5d1216b775d0f6cdee97d82d30fcd46912e9 (patch)
tree0d2191886a72f7c23016c52efddc1b556fae0c04 /libgphoto2_port/libgphoto2_port
parent6c5db352a61dff5506e154d0bfbf82a8b7542d0e (diff)
downloadlibgphoto2-b06e5d1216b775d0f6cdee97d82d30fcd46912e9.tar.gz
From: Axel Waggershauser <awagger@web.de>
1) introduce C_PARAMS and C_PARAMS_MSG along the lines of C_MEM 2) replace CHECK_NULL with C_PARAMS 3) replace the pattern if ( something ) return GP_ERROR_BAD_PARAMETERS; with C_PARAMS ( !something ); I went over the whole patch again to check that each 'something' condition is really inverted, so I dare to suggest you don't have to do that again ;). 4) replaced CHECK_LIST and CHECK_INDEX_RANGE with simple one-line C_PARAMS(...) expressions 5) a couple of hunks look like this - if (!inet_aton (buffer, &inp)) { - fprintf(stderr,"failed to scan for addr in %s\n", buffer); - return GP_ERROR_BAD_PARAMETERS; - } + C_PARAMS_MSG (inet_aton (buffer, &inp), so some 'lost' error messages get now properly piped into the gp_log mechanism. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@15103 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'libgphoto2_port/libgphoto2_port')
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c23
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port-log.c6
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port.c70
3 files changed, 46 insertions, 53 deletions
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
index adf09686b..425de0c24 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
@@ -75,7 +75,6 @@ struct _GPPortInfoList {
unsigned int iolib_count;
};
-#define CHECK_NULL(x) {if (!(x)) return (GP_ERROR_BAD_PARAMETERS);}
#define CR(x) {int r=(x);if (r<0) return (r);}
@@ -109,7 +108,7 @@ gp_port_message_codeset (const char *codeset) {
int
gp_port_info_list_new (GPPortInfoList **list)
{
- CHECK_NULL (list);
+ C_PARAMS (list);
/*
* We put this in here because everybody needs to call this function
@@ -133,7 +132,7 @@ gp_port_info_list_new (GPPortInfoList **list)
int
gp_port_info_list_free (GPPortInfoList *list)
{
- CHECK_NULL (list);
+ C_PARAMS (list);
if (list->info) {
unsigned int i;
@@ -174,7 +173,7 @@ gp_port_info_list_free (GPPortInfoList *list)
int
gp_port_info_list_append (GPPortInfoList *list, GPPortInfo info)
{
- CHECK_NULL (list);
+ C_PARAMS (list);
C_MEM (list->info = realloc (list->info, sizeof (GPPortInfo) * (list->count + 1)));
list->count++;
@@ -269,7 +268,7 @@ gp_port_info_list_load (GPPortInfoList *list)
const char *iolibs = (iolibs_env != NULL)?iolibs_env:IOLIBS;
int result;
- CHECK_NULL (list);
+ C_PARAMS (list);
GP_LOG_D ("Using ltdl to load io-drivers from '%s'...", iolibs);
lt_dlinit ();
@@ -298,7 +297,7 @@ gp_port_info_list_count (GPPortInfoList *list)
{
unsigned int count, i;
- CHECK_NULL (list);
+ C_PARAMS (list);
GP_LOG_D ("Counting entries (%i available)...", list->count);
@@ -338,7 +337,7 @@ gp_port_info_list_lookup_path (GPPortInfoList *list, const char *path)
#endif
#endif
- CHECK_NULL (list && path);
+ C_PARAMS (list && path);
GP_LOG_D ("Looking for path '%s' (%i entries available)...", path, list->count);
@@ -424,7 +423,7 @@ gp_port_info_list_lookup_name (GPPortInfoList *list, const char *name)
{
unsigned int i, generic;
- CHECK_NULL (list && name);
+ C_PARAMS (list && name);
GP_LOG_D ("Looking up entry '%s'...", name);
@@ -453,19 +452,17 @@ gp_port_info_list_get_info (GPPortInfoList *list, int n, GPPortInfo *info)
{
int i;
- CHECK_NULL (list && info);
+ C_PARAMS (list && info);
GP_LOG_D ("Getting info of entry %i (%i available)...", n, list->count);
- if (n < 0 || n >= list->count)
- return GP_ERROR_BAD_PARAMETERS;
+ C_PARAMS (n >= 0 && n < list->count);
/* Ignore generic entries */
for (i = 0; i <= n; i++)
if (!strlen (list->info[i]->name)) {
n++;
- if (n >= list->count)
- return GP_ERROR_BAD_PARAMETERS;
+ C_PARAMS (n < list->count);
}
*info = list->info[n];
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
index a70d0a323..540eecf91 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-log.c
@@ -81,8 +81,7 @@ static unsigned int log_funcs_count = 0;
int
gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data)
{
- if (!func)
- return (GP_ERROR_BAD_PARAMETERS);
+ C_PARAMS (func);
C_MEM (log_funcs = realloc (log_funcs, sizeof (LogFunc) *
(log_funcs_count + 1)));
@@ -107,8 +106,7 @@ gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data)
int
gp_log_remove_func (int id)
{
- if (id < 1 || id > log_funcs_count)
- return (GP_ERROR_BAD_PARAMETERS);
+ C_PARAMS (id > 0 && id <= log_funcs_count);
memmove (log_funcs + id - 1, log_funcs + id, log_funcs_count - id);
log_funcs_count--;
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port.c b/libgphoto2_port/libgphoto2_port/gphoto2-port.c
index 2ff5ac3bb..26b6c0f81 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port.c
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port.c
@@ -56,7 +56,6 @@
#endif
#define CHECK_RESULT(result) {int r=(result); if (r<0) return (r);}
-#define CHECK_NULL(m) {if (!(m)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK_SUPP(p,t,o) {if (!(o)) {gp_port_set_error ((p), _("The operation '%s' is not supported by this device"), (t)); return (GP_ERROR_NOT_SUPPORTED);}}
#define CHECK_INIT(p) {if (!(p)->pc->ops) {gp_port_set_error ((p), _("The port has not yet been initialized")); return (GP_ERROR_BAD_PARAMETERS);}}
@@ -87,7 +86,7 @@ struct _GPPortPrivateCore {
int
gp_port_new (GPPort **port)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
GP_LOG_D ("Creating new device...");
@@ -105,7 +104,7 @@ gp_port_new (GPPort **port)
static int
gp_port_init (GPPort *port)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
if (port->pc->ops->init)
@@ -117,7 +116,7 @@ gp_port_init (GPPort *port)
static int
gp_port_exit (GPPort *port)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
if (port->pc->ops->exit)
@@ -144,7 +143,7 @@ gp_port_set_info (GPPort *port, GPPortInfo info)
{
GPPortLibraryOperations ops_func;
- CHECK_NULL (port);
+ C_PARAMS (port);
free (port->pc->info.name);
C_MEM (port->pc->info.name = strdup (info->name));
@@ -223,7 +222,7 @@ gp_port_set_info (GPPort *port, GPPortInfo info)
/* Nothing in here */
break;
}
- gp_port_set_settings (port, port->settings);
+ CHECK_RESULT (gp_port_set_settings (port, port->settings));
return (GP_OK);
}
@@ -240,7 +239,7 @@ gp_port_set_info (GPPort *port, GPPortInfo info)
int
gp_port_get_info (GPPort *port, GPPortInfo *info)
{
- CHECK_NULL (port && info);
+ C_PARAMS (port && info);
*info = &port->pc->info;
return (GP_OK);
@@ -258,7 +257,7 @@ gp_port_get_info (GPPort *port, GPPortInfo *info)
int
gp_port_open (GPPort *port)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
GP_LOG_D ("Opening %s port...",
@@ -284,7 +283,7 @@ gp_port_close (GPPort *port)
{
GP_LOG_D ("Closing port...");
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "close", port->pc->ops->close);
@@ -306,7 +305,7 @@ gp_port_reset (GPPort *port)
{
GP_LOG_D ("Resetting port...");
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "reset", port->pc->ops->reset);
@@ -328,7 +327,7 @@ gp_port_free (GPPort *port)
{
GP_LOG_D ("Freeing port...");
- CHECK_NULL (port);
+ C_PARAMS (port);
if (port->pc) {
if (port->pc->ops) {
@@ -381,7 +380,7 @@ gp_port_write (GPPort *port, const char *data, int size)
GP_LOG_D ("Writing %i=0x%x byte(s) to port...", size, size);
- CHECK_NULL (port && data);
+ C_PARAMS (port && data);
CHECK_INIT (port);
GP_LOG_DATA (data, size);
@@ -415,7 +414,7 @@ gp_port_read (GPPort *port, char *data, int size)
GP_LOG_D ("Reading %i=0x%x bytes from port...", size, size);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
/* Check if we read as many bytes as expected */
@@ -450,7 +449,7 @@ gp_port_check_int (GPPort *port, char *data, int size)
GP_LOG_D ("Reading %i=0x%x bytes from interrupt endpoint...", size, size);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
/* Check if we read as many bytes as expected */
@@ -484,7 +483,7 @@ gp_port_check_int_fast (GPPort *port, char *data, int size)
{
int retval;
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
/* Check if we read as many bytes as expected */
@@ -529,7 +528,7 @@ gp_port_check_int_fast (GPPort *port, char *data, int size)
int
gp_port_set_timeout (GPPort *port, int timeout)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
GP_LOG_D ("Setting port timeout to %i milliseconds.", timeout);
port->timeout = timeout;
@@ -563,7 +562,7 @@ int gp_port_timeout_get (GPPort *port, int *timeout)
int
gp_port_get_timeout (GPPort *port, int *timeout)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
GP_LOG_D ("Current port timeout is %i milliseconds.", port->timeout);
*timeout = port->timeout;
@@ -587,7 +586,7 @@ gp_port_set_settings (GPPort *port, GPPortSettings settings)
{
GP_LOG_D ("Setting settings...");
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
/*
@@ -627,7 +626,7 @@ int gp_port_settings_set (GPPort *port, GPPortSettings settings)
int
gp_port_get_settings (GPPort *port, GPPortSettings *settings)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
memcpy (settings, &(port->settings), sizeof (gp_port_settings));
@@ -648,7 +647,7 @@ gp_port_get_pin (GPPort *port, GPPin pin, GPLevel *level)
{
GP_LOG_D ("Getting level of pin %i...", pin);
- CHECK_NULL (port && level);
+ C_PARAMS (port && level);
CHECK_INIT (port);
CHECK_SUPP (port, "get_pin", port->pc->ops->get_pin);
@@ -710,7 +709,7 @@ gp_port_set_pin (GPPort *port, GPPin pin, GPLevel level)
PinTable[i].number, PinTable[i].description_short,
PinTable[i].description_long, _(LevelTable[j].description));
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "set_pin", port->pc->ops->set_pin);
@@ -734,7 +733,7 @@ gp_port_send_break (GPPort *port, int duration)
{
GP_LOG_D ("Sending break (%i milliseconds)...", duration);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "send_break", port->pc->ops->send_break);
@@ -759,7 +758,7 @@ gp_port_flush (GPPort *port, int direction)
{
GP_LOG_D ("Flushing port...");
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_SUPP (port, "flush", port->pc->ops->flush);
CHECK_RESULT (port->pc->ops->flush (port, direction));
@@ -785,7 +784,7 @@ gp_port_flush (GPPort *port, int direction)
int
gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "find_device", port->pc->ops->find_device);
@@ -809,7 +808,7 @@ gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct)
int
gp_port_usb_find_device_by_class (GPPort *port, int mainclass, int subclass, int protocol)
{
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "find_device_by_class", port->pc->ops->find_device_by_class);
@@ -833,7 +832,7 @@ gp_port_usb_clear_halt (GPPort *port, int ep)
{
GP_LOG_D ("Clear USB halt...");
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "clear_halt", port->pc->ops->clear_halt);
@@ -866,7 +865,7 @@ gp_port_usb_msg_write (GPPort *port, int request, int value, int index,
request, value, index, size, size);
GP_LOG_DATA (bytes, size);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_write", port->pc->ops->msg_write);
@@ -899,7 +898,7 @@ gp_port_usb_msg_read (GPPort *port, int request, int value, int index,
GP_LOG_D ("Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
request, value, index, size, size);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_read", port->pc->ops->msg_read);
@@ -941,7 +940,7 @@ gp_port_usb_msg_interface_write (GPPort *port, int request,
request, value, index, size, size);
GP_LOG_DATA (bytes, size);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_build", port->pc->ops->msg_interface_write);
@@ -976,7 +975,7 @@ gp_port_usb_msg_interface_read (GPPort *port, int request, int value, int index,
GP_LOG_D ("Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
request, value, index, size, size);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_read", port->pc->ops->msg_interface_read);
@@ -1022,7 +1021,7 @@ gp_port_usb_msg_class_write (GPPort *port, int request,
request, value, index, size, size);
GP_LOG_DATA (bytes, size);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_build", port->pc->ops->msg_class_write);
@@ -1057,7 +1056,7 @@ gp_port_usb_msg_class_read (GPPort *port, int request, int value, int index,
GP_LOG_D ("Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
request, value, index, size, size);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_read", port->pc->ops->msg_class_read);
@@ -1091,7 +1090,7 @@ gp_port_seek (GPPort *port, int offset, int whence)
GP_LOG_D ("Seeking to: %d whence: %d", offset, whence);
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "seek", port->pc->ops->seek);
@@ -1133,7 +1132,7 @@ int gp_port_send_scsi_cmd (GPPort *port, int to_dev,
GP_LOG_DATA (data, data_size);
}
- CHECK_NULL (port);
+ C_PARAMS (port);
CHECK_INIT (port);
memset (sense, 0, sense_size);
@@ -1191,8 +1190,7 @@ gp_port_set_error (GPPort *port, const char *format, ...)
{
va_list args;
- if (!port)
- return (GP_ERROR_BAD_PARAMETERS);
+ C_PARAMS (port);
if (format) {
va_start (args, format);