Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
New utils: free_outside() and zero_nth_char()
  • Loading branch information
BjarniRunar committed Sep 15, 2016
1 parent d92fbf4 commit 2c64b3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libpagekite/pkutils.c
Expand Up @@ -59,6 +59,22 @@ int zero_first_whitespace(int length, char* data)
return 0;
}

int zero_nth_char(int n, char c, int length, char* data)
{
int i;
for (i = 0; i < length; i++)
{
if (data[i] == c)
{
if (--n < 1) {
data[i] = '\0';
return i+1;
}
}
}
return 0;
}

char *skip_http_header(int length, const char* data)
{
int i, lfs;
Expand Down
2 changes: 2 additions & 0 deletions libpagekite/pkutils.h
Expand Up @@ -19,9 +19,11 @@ Note: For alternate license terms, see the file COPYING.md.
******************************************************************************/

#define strncpyz(dest, src, len) { strncpy(dest, src, len); dest[len] = '\0'; }
#define free_outside(ptr, buf, len) { if ((ptr < buf) || (ptr >= buf+len)) free(ptr); }

int zero_first_crlf(int, char*);
int zero_first_whitespace(int, char*);
int zero_nth_char(int, char, int, char*);
char* skip_http_header(int, const char*);
char* collapse_whitespace(char*);
int dbg_write(int, char *, int);
Expand Down

0 comments on commit 2c64b3f

Please sign in to comment.