#include <stdlib.h>
#include <string.h>
#include "buf.h"
Include dependency graph for buf.c:
Go to the source code of this file.
Defines | |
#define | MINSIZE 10 |
Minimum size buffer allocated. | |
Functions | |
int | allocsize (int n) |
Returns the size of buffer to allocate, given the requested size. | |
ABuf * | buf_new (unsigned int len) |
Allocate a new buffer. | |
ABuf * | buf_free (ABuf *buf) |
Free a buffer_handle_type. | |
ABuf * | buf_check (ABuf *buf, unsigned int len) |
Check that the buffer is at least 'len' bytes. | |
ABuf * | buf_strcat (ABuf *buf, char *s) |
append the string 's' to the buffer. | |
ABuf * | buf_strcpy (ABuf *buf, char *s) |
Copy the string 's' into the buffer, replacing whatever's there. | |
ABuf * | buf_str_shrinkbyone (ABuf *buf) |
Shrinks the char string in the buffer by one character. | |
ABuf * | buf_terminate (ABuf *buf) |
Ensure that the last char in the buffer contains '\0'. |
Here, 'buffer's value after the call will be different to the 'buffer's value before the call, because the buffer is reallocated to fit in the new contents. So for any function call that can cause the buffer to grow, always save the return value into the buffer.
Functions are all NULL-safe. If a null buffer is passed in, a new buffer will be allocated and returned. So instead of the above, could just say:
ABuf *buffer = buf_cpy(NULL, "123456");
When finished with the buffer, call buf_free on it. buf_free always returns a NULL
buffer pointer. This is to let you do:
buffer = buf_free(buffer);
Definition in file buf.c.
|
Minimum size buffer allocated.
Any buffer allocation will return a buffer that is at least this size, even Definition at line 58 of file buf.c. Referenced by allocsize(). |
|
Returns the size of buffer to allocate, given the requested size.
Definition at line 63 of file buf.c. References MINSIZE. Referenced by buf_new(). |
|
Check that the buffer is at least 'len' bytes. If it is not at least 'len' bytes long, a new buffer is allocated. Returns a pointer to either the original or the new buffer. Always use: buf = buf_check(buf, len);
Definition at line 112 of file buf.c. References _a_buf::b_dat, _a_buf::b_len, buf_free(), and buf_new(). Referenced by buf_strcat(), buf_strcpy(), export_html_dialog_show(), my_DBform_to_url(), pg_DBform_to_url(), send_callback(), xp_DBform_to_url(), and xp_DBget_field_value_attrib(). |
|
Free a buffer_handle_type.
Definition at line 90 of file buf.c. References _a_buf::b_dat. Referenced by buf_check(), db_connect_dialog_reconnect(), disconnect_first(), export_as_html(), export_as_text(), export_text_dialog_create(), frm_save_file(), gui_load_query_from_file(), gui_send_query(), on_databaseDisconnect_activate(), on_queryImportDlgOkBtn_clicked(), query_add(), query_import_dialog_create(), query_save_dialog_create(), result_export(), send_callback(), and ws_save_file(). |
|
Allocate a new buffer. allocsize() is used to calculate the buffer size, so the returned buffer may be larger than the requested size.
Definition at line 74 of file buf.c. References allocsize(), _a_buf::b_dat, and _a_buf::b_len. Referenced by buf_check(), buf_strcat(), buf_strcpy(), db_connect_dialog_reconnect(), disconnect_first(), export_as_html(), export_as_text(), frm_save_file(), gui_load_query_from_file(), gui_send_query(), on_databaseDisconnect_activate(), on_queryImportDlgOkBtn_clicked(), query_add(), query_import_dialog_create(), result_export(), send_callback(), and ws_save_file(). |
|
Shrinks the char string in the buffer by one character.
Definition at line 187 of file buf.c. References _a_buf::b_dat. Referenced by frm_check_fields(). |
|
append the string 's' to the buffer. The buffer is reallocated if necessary. buf = buf_strcat(buf, "Hello");
Definition at line 134 of file buf.c. References _a_buf::b_dat, _a_buf::b_len, buf_check(), buf_new(), and buf_terminate(). Referenced by cfg_get_default_wsname(), db_connect_dialog_reconnect(), frm_check_fields(), frm_save_file(), get_rcname(), my_DBform_to_url(), pg_DBform_to_url(), query_import_dialog_create(), query_save_dialog_create(), send_callback(), ws_save_file(), xp_DBform_to_url(), xp_DBget_field_value_attrib(), and xp_DBget_field_value_content(). |
|
Copy the string 's' into the buffer, replacing whatever's there. The buffer is reallocated if required. buf = buf_strcpy(buf, "Hello");
Definition at line 158 of file buf.c. References _a_buf::b_dat, _a_buf::b_len, buf_check(), buf_new(), and buf_terminate(). Referenced by cfg_get_default_wsname(), db_connect_dialog_reconnect(), frm_save_file(), my_DBform_to_url(), pg_DBform_to_url(), query_import_dialog_create(), query_save_dialog_create(), ws_save_file(), xp_DBget_field_value_attrib(), and xp_DBget_field_value_content(). |
|
Ensure that the last char in the buffer contains '\0'.
Definition at line 199 of file buf.c. References _a_buf::b_dat, and _a_buf::b_len. Referenced by buf_strcat(), and buf_strcpy(). |