Commit e366c8fe authored by Mart Lubbers's avatar Mart Lubbers

update, clean up

parent d6152aae
...@@ -2,3 +2,4 @@ Clean System Files/[^.]* ...@@ -2,3 +2,4 @@ Clean System Files/[^.]*
TTY TTY
sapl sapl
TTY.prj TTY.prj
test
...@@ -43,11 +43,10 @@ static void remTermios(int fd) ...@@ -43,11 +43,10 @@ static void remTermios(int fd)
struct termioslist *it = head; struct termioslist *it = head;
while(it != NULL){ while(it != NULL){
if(it->fd == fd){ if(it->fd == fd){
if(beforeit == NULL){ if(beforeit == NULL)
head = it->next; head = it->next;
} else { else
beforeit->next = it->next; beforeit->next = it->next;
}
free(it); free(it);
break; break;
} }
...@@ -150,18 +149,20 @@ void ttyreadline(int fd, CleanString *result, int *fdo) ...@@ -150,18 +149,20 @@ void ttyreadline(int fd, CleanString *result, int *fdo)
{ {
size_t bufsize = INITIAL_BUFFERSIZE; size_t bufsize = INITIAL_BUFFERSIZE;
char *buf = NULL; char *buf = NULL;
ssize_t charsread = 0; ssize_t cr, charsread = 0;
while(buf == NULL || buf[charsread-1] != '\n'){ while(buf == NULL || buf[charsread-1] != '\n'){
if((buf = realloc(buf, (bufsize*=2)+1)) == NULL) if((buf = realloc(buf, (bufsize*=2)+1)) == NULL)
die("realloc"); die("realloc");
charsread += read(fd, buf+charsread, bufsize-charsread); if((cr = read(fd, buf+charsread, bufsize-charsread)) < 0)
die("read");
charsread += cr;
} }
buf[charsread] = '\0'; buf[charsread] = '\0';
CleanStringVariable(cleanOutput, charsread+1); CleanStringVariable(cleanOutput, charsread);
*result = (CleanString) cleanOutput; *result = (CleanString) cleanOutput;
memcpy(CleanStringCharacters(cleanOutput), buf, charsread+1); memcpy(CleanStringCharacters(cleanOutput), buf, charsread);
CleanStringLength(cleanOutput) = charsread+1; CleanStringLength(cleanOutput) = charsread;
*fdo = fd; *fdo = fd;
free(buf); free(buf);
...@@ -181,5 +182,5 @@ int ttyclose(int fd) ...@@ -181,5 +182,5 @@ int ttyclose(int fd)
remTermios(fd); remTermios(fd);
int ret = close(fd); int ret = close(fd);
error = strerror(errno); error = strerror(errno);
return ret+1; return ret + 1;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment