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
322 B
C
20 lines
322 B
C
22 years ago
|
#include <stralloc.h>
|
||
|
|
||
|
int stralloc_chomp(stralloc* sa) {
|
||
|
unsigned int 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;
|
||
|
}
|