summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 72b3890ef0..027d33a486 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -93,7 +93,7 @@ struct memory_handle {
93 size_t data; /* Start index of the handle's data buffer */ 93 size_t data; /* Start index of the handle's data buffer */
94 size_t ridx; /* Read pointer, relative to the main buffer */ 94 size_t ridx; /* Read pointer, relative to the main buffer */
95 size_t widx; /* Write pointer, relative to the main buffer */ 95 size_t widx; /* Write pointer, relative to the main buffer */
96 ssize_t filesize; /* File total length */ 96 off_t filesize; /* File total length (possibly trimmed at tail) */
97 off_t start; /* Offset at which we started reading the file */ 97 off_t start; /* Offset at which we started reading the file */
98 off_t pos; /* Read position in file */ 98 off_t pos; /* Read position in file */
99 off_t volatile end; /* Offset at which we stopped reading the file */ 99 off_t volatile end; /* Offset at which we stopped reading the file */
@@ -917,7 +917,7 @@ management functions for all the actual handle management work.
917 return value: <0 if the file cannot be opened, or one file already 917 return value: <0 if the file cannot be opened, or one file already
918 queued to be opened, otherwise the handle for the file in the buffer 918 queued to be opened, otherwise the handle for the file in the buffer
919*/ 919*/
920int bufopen(const char *file, size_t offset, enum data_type type, 920int bufopen(const char *file, off_t offset, enum data_type type,
921 void *user_data) 921 void *user_data)
922{ 922{
923 int handle_id = ERR_BUFFER_FULL; 923 int handle_id = ERR_BUFFER_FULL;
@@ -1508,31 +1508,36 @@ These functions are exported, to allow interaction with the buffer.
1508They take care of the content of the structs, and rely on the linked list 1508They take care of the content of the structs, and rely on the linked list
1509management functions for all the actual handle management work. 1509management functions for all the actual handle management work.
1510*/ 1510*/
1511bool buf_is_handle(int handle_id)
1512{
1513 return find_handle(handle_id) != NULL;
1514}
1511 1515
1512ssize_t buf_handle_offset(int handle_id) 1516int buf_handle_data_type(int handle_id)
1513{ 1517{
1514 const struct memory_handle *h = find_handle(handle_id); 1518 const struct memory_handle *h = find_handle(handle_id);
1515 if (!h) 1519 if (!h)
1516 return ERR_HANDLE_NOT_FOUND; 1520 return ERR_HANDLE_NOT_FOUND;
1517 return h->start; 1521 return h->type;
1518} 1522}
1519 1523
1520void buf_set_base_handle(int handle_id) 1524off_t buf_filesize(int handle_id)
1521{ 1525{
1522 mutex_lock(&llist_mutex); 1526 const struct memory_handle *h = find_handle(handle_id);
1523 base_handle_id = handle_id; 1527 if (!h)
1524 mutex_unlock(&llist_mutex); 1528 return ERR_HANDLE_NOT_FOUND;
1529 return h->filesize;
1525} 1530}
1526 1531
1527enum data_type buf_handle_data_type(int handle_id) 1532off_t buf_handle_offset(int handle_id)
1528{ 1533{
1529 const struct memory_handle *h = find_handle(handle_id); 1534 const struct memory_handle *h = find_handle(handle_id);
1530 if (!h) 1535 if (!h)
1531 return TYPE_UNKNOWN; 1536 return ERR_HANDLE_NOT_FOUND;
1532 return h->type; 1537 return h->start;
1533} 1538}
1534 1539
1535ssize_t buf_handle_remaining(int handle_id) 1540off_t buf_handle_remaining(int handle_id)
1536{ 1541{
1537 const struct memory_handle *h = find_handle(handle_id); 1542 const struct memory_handle *h = find_handle(handle_id);
1538 if (!h) 1543 if (!h)
@@ -1540,11 +1545,6 @@ ssize_t buf_handle_remaining(int handle_id)
1540 return h->filesize - h->end; 1545 return h->filesize - h->end;
1541} 1546}
1542 1547
1543bool buf_is_handle(int handle_id)
1544{
1545 return find_handle(handle_id) != NULL;
1546}
1547
1548bool buf_pin_handle(int handle_id, bool pin) 1548bool buf_pin_handle(int handle_id, bool pin)
1549{ 1549{
1550 struct memory_handle *h = find_handle(handle_id); 1550 struct memory_handle *h = find_handle(handle_id);
@@ -1576,6 +1576,14 @@ size_t buf_length(void)
1576 return buffer_len; 1576 return buffer_len;
1577} 1577}
1578 1578
1579/* Set the handle from which useful data is counted */
1580void buf_set_base_handle(int handle_id)
1581{
1582 mutex_lock(&llist_mutex);
1583 base_handle_id = handle_id;
1584 mutex_unlock(&llist_mutex);
1585}
1586
1579/* Return the amount of buffer space used */ 1587/* Return the amount of buffer space used */
1580size_t buf_used(void) 1588size_t buf_used(void)
1581{ 1589{