New functions by Michael Walle for resizing registers on the fly

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1851 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Mike Frysinger 14 years ago
parent 91bd7afa7f
commit 4763d8162a

@ -15,6 +15,12 @@
* include/urjtag/bitops.h: New generic bit operations by Michael Walle.
* include/urjtag/Makefile.am (pkginclude_HEADERS): Add bitops.h
* include/urjtag/data_register.h, src/part/data_register.c
(urj_part_data_register_realloc): New func by Michael Walle for resizing
registers on the fly.
* include/urjtag/tap_register.h, src/tap/register.c
(urj_tap_register_realloc): Likewise.
2010-08-30 Mike Frysinger <vapier@gentoo.org>
* configure.ac: Clean up libusb detection to prefer 1.0 over 0.1, and accept

@ -40,6 +40,13 @@ struct URJ_DATA_REGISTER
urj_data_register_t *urj_part_data_register_alloc (const char *name, int len);
void urj_part_data_register_free (urj_data_register_t *dr);
/**
* change the length of a data_register while preserving its contents
*
* @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error
*/
int urj_part_data_register_realloc (urj_data_register_t *dr, int len);
/**
* allocate a data register and initialize the relevant <code>part</code> parts
*

@ -36,6 +36,7 @@ struct URJ_TAP_REGISTER
};
urj_tap_register_t *urj_tap_register_alloc (int len);
urj_tap_register_t *urj_tap_register_realloc (urj_tap_register_t *tr, int new_len);
urj_tap_register_t *urj_tap_register_duplicate (const urj_tap_register_t *tr);
void urj_tap_register_free (urj_tap_register_t *tr);
urj_tap_register_t *urj_tap_register_fill (urj_tap_register_t *tr, int val);

@ -133,3 +133,14 @@ urj_part_data_register_define (urj_part_t *part, const char *name, int len)
return URJ_STATUS_OK;
}
int
urj_part_data_register_realloc (urj_data_register_t *dr, int new_len)
{
if (urj_tap_register_realloc (dr->in, new_len) == NULL)
return URJ_STATUS_FAIL;
if (urj_tap_register_realloc (dr->out, new_len) == NULL)
return URJ_STATUS_FAIL;
return URJ_STATUS_OK;
}

@ -78,6 +78,35 @@ urj_tap_register_alloc (int len)
return tr;
}
urj_tap_register_t *
urj_tap_register_realloc (urj_tap_register_t *tr, int new_len)
{
if (!tr)
return urj_tap_register_alloc (new_len);
if (new_len < 1)
{
urj_error_set (URJ_ERROR_INVALID, "new_len < 1");
return NULL;
}
tr->data = realloc (tr->data, new_len);
if (!tr->data)
{
urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "realloc(%d) fails",
new_len);
return NULL;
}
if (tr->len < new_len)
memset (tr->data + tr->len, 0, (new_len - tr->len));
tr->len = new_len;
return tr;
}
urj_tap_register_t *
urj_tap_register_duplicate (const urj_tap_register_t *tr)
{

Loading…
Cancel
Save