Skip to content

Commit

Permalink
utils: Add sanitize_ascii()
Browse files Browse the repository at this point in the history
This can be used to ensure all characters on an ascii array are
printable.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
  • Loading branch information
Timo Kokkonen committed May 5, 2011
1 parent 3b1882a commit 1e0eeb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ void print_ascii(const unsigned char *data, int len)

printf("\n");
}

void sanitize_ascii(unsigned char *data, int len)
{
int i;

for (i = 0; i < len; i++)
data[i] = is_printable(data[i]) ? data[i] : '.';
data[i] = 0;
}
1 change: 1 addition & 0 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ extern int trace_level;
int datalen(const unsigned char *data);
void print_hex(const unsigned char *data, int len);
void print_ascii(const unsigned char *data, int len);
void sanitize_ascii(unsigned char *data, int len);

#endif

0 comments on commit 1e0eeb1

Please sign in to comment.