Created
October 23, 2015 11:15
-
-
Save luistelmocosta/87b7b099e80e4ae0c1b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int byteStuffing(char **buf, int length){ | |
int newlength = length; | |
int i; | |
for (i = 1; i < length - 1; i++) | |
if ((*buf)[i] == FLAG || (*buf)[i] == ESCAPE) | |
newlength++; | |
*buf = (unsigned char*) realloc(*buf, newlength); | |
for(i= 1 ; i <length; i++) | |
if ((*buf)[i] == FLAG || (*buf)[i] == ESCAPE){ | |
memmove(*buf + i + 1, *buf + i, length - i); /*void *memmove(void *str1, const void *str2, size_t n) */ | |
length++; | |
(*buf)[i] = ESCAPE; | |
(*buf)[i + 1] ^= 0x20; | |
} | |
} | |
return newlength; | |
} | |
int byteDeStuffing(unsigned char** buf, int length) { | |
int i; | |
for (i = 1; i < length - 1; ++i) { | |
if ((*buf)[i] == ESCAPE) { | |
memmove(*buf + i, *buf + i + 1, length - i - 1); | |
length--; | |
(*buf)[i] ^= 0x20; | |
} | |
} | |
*buf = (unsigned char*) realloc(*buf, length); | |
return length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment