You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
316 B
C

#include "stralloc.h"
int stralloc_chomp(stralloc* sa) {
size_t max=sa->len;
if (max>0) {
register char x;
--max;
x=sa->s[max];
if (x=='\n' || x=='\r') {
if (x=='\n' && max>1 && sa->s[max-1]=='\r') {
sa->len-=2;
return 2;
}
--sa->len;
return 1;
}
}
return 0;
}