write check wrong, write returns number of bytes written, hence always larger than 0. Thanks to @mwalker33 for the fix

This commit is contained in:
iceman1001 2024-07-21 11:37:47 +02:00
parent 5effb4f886
commit 791d9e09ac

View file

@ -430,7 +430,7 @@ static void *sorttable(void *dd) {
printf("cannot create outfile %s\n", outfile); printf("cannot create outfile %s\n", outfile);
exit(1); exit(1);
} }
if (write(fdout, table, numentries * DATASIZE)) { if (write(fdout, table, numentries * DATASIZE) != (numentries * DATASIZE)) {
printf("writetable cannot write all of the data\n"); printf("writetable cannot write all of the data\n");
exit(1); exit(1);
} }
@ -454,7 +454,7 @@ int main(int argc, char *argv[]) {
// make the table of tables // make the table of tables
t = (struct table *)calloc(sizeof(struct table) * 65536, sizeof(uint8_t)); t = (struct table *)calloc(sizeof(struct table) * 65536, sizeof(uint8_t));
if (!t) { if (!t) {
printf("malloc failed\n"); printf("calloc failed\n");
exit(1); exit(1);
} }
@ -503,11 +503,8 @@ int main(int argc, char *argv[]) {
free_tables(t); free_tables(t);
free(t); free(t);
// now for the sorting // now for the sorting
// start the threads // start the threads
for (long i = 0; i < NUM_SORT_THREADS; i++) { for (long i = 0; i < NUM_SORT_THREADS; i++) {
int ret = pthread_create(&(threads[i]), NULL, sorttable, (void *)(i)); int ret = pthread_create(&(threads[i]), NULL, sorttable, (void *)(i));