Skip to content

Commit

Permalink
ansi fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rootTHC committed Feb 23, 2021
1 parent 1d87ee6 commit 95c6e89
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 198 deletions.
3 changes: 2 additions & 1 deletion include/gsocket/buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ typedef struct
void GS_BUF_init(GS_BUF *gsb, size_t sz_min_free);
void GS_BUF_free(GS_BUF *gsb);
int GS_BUF_resize(GS_BUF *gsb, size_t sz_new);
int GS_BUF_add(GS_BUF *gsb, size_t len);
int GS_BUF_add_length(GS_BUF *gsb, size_t len);
int GS_BUF_add_data(GS_BUF *gsb, void *data, size_t len);
int GS_BUF_del(GS_BUF *gsb, size_t len);
int GS_BUF_memmove(GS_BUF *gsb, void *data, size_t len);

#define GS_BUF_empty(gsb) (gsb)->sz_used = 0;
#define GS_BUF_DATA(gsb) (gsb)->data
Expand Down
13 changes: 12 additions & 1 deletion lib/buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GS_BUF_resize(GS_BUF *gsb, size_t sz_new)
}

int
GS_BUF_add(GS_BUF *gsb, size_t len)
GS_BUF_add_length(GS_BUF *gsb, size_t len)
{
// Bail. There is sz_max_add space available but looks like caller wrote
// more ata...
Expand All @@ -65,6 +65,17 @@ GS_BUF_add_data(GS_BUF *gsb, void *data, size_t len)
return 0;
}

int
GS_BUF_memmove(GS_BUF *gsb, void *data, size_t len)
{
GS_BUF_resize(gsb, len);
memmove((uint8_t *)gsb->data + gsb->sz_used, data, len);

gsb->sz_used += len;

return 0;
}

/*
* Consume data from beginning.
*/
Expand Down
2 changes: 1 addition & 1 deletion tools/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ extern struct _g_debug_ctx g_dbg_ctx; // declared in utils.c
#ifdef DEBUG
# define HEXDUMP(a, _len) do { \
size_t _n = 0; \
xfprintf(gopt.err_fp, "%s:%d HEX ", __FILE__, __LINE__); \
xfprintf(gopt.err_fp, "%s:%d HEX[%zd] ", __FILE__, __LINE__, _len); \
while (_n < (_len)) xfprintf(gopt.err_fp, "%2.2x", ((unsigned char *)a)[_n++]); \
xfprintf(gopt.err_fp, "\n"); \
} while (0)
Expand Down
Loading

0 comments on commit 95c6e89

Please sign in to comment.