Skip to content

Commit

Permalink
Have to close file descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
Babkock committed May 30, 2023
1 parent 1292c72 commit f2df265
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Some programs utilize command-line arguments. Remember, if you ever see =int mai
- [[https://github.com/Babkock/learning/blob/master/time.c][Time calculator]]
- [[https://github.com/Babkock/learning/blob/master/sys/shell.c][Simple shell]]
- [[https://github.com/Babkock/learning/-/blob/master/sys/symlink.c][Symbolic links]]
- [[https://github.com/Babkock/learning/-/blob/master/bits.c][Bitwise operations]]
- [[https://github.com/Babkock/learning/-/blob/master/point/bitfield.c][Bit field]]
- [[https://github.com/Babkock/learning/blob/master/bits.c][Bitwise operations]]
- [[https://github.com/Babkock/learning/blob/master/point/bitfield.c][Bit field]]

Thanks for checking these out.
7 changes: 6 additions & 1 deletion network/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ int main(int argc, char **argv) {
if ((n = write(sockfd, buffer, strlen(buffer))) < 0) {
fprintf(stderr, "Error writing to socket\n");
return 4;
} else {
printf("Wrote %d bytes\n", n);
}

/* now read server response */
bzero(buffer, BUF);
if ((n = read(sockfd, buffer, BUF-1)) < 0) {
fprintf(stderr, "Error reading from socket\n");
return 5;
return 4;
} else {
printf("Read %d bytes\n", n);
}

close(sockfd);
printf("Your message: %s", buffer);
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions network/multiserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ int main(int argc, char *argv[]) {
}
} /* while (1) */

close(sockfd);
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions sys/speak.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int main(void) {
printf("Speak: Wrote %d bytes\n", num);
}

close(fd);
return 0;
}

1 change: 1 addition & 0 deletions sys/tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ int main(void) {
} while (num > 1);
putchar('\n');

close(fd);
return 0;
}

0 comments on commit f2df265

Please sign in to comment.