Skip to content
Snippets Groups Projects
Commit 913fa4c8 authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Final attempt at fixing errors. Not enough time to finish

parent bdfa1595
Branches
No related merge requests found
...@@ -35,6 +35,12 @@ FILE * F; ...@@ -35,6 +35,12 @@ FILE * F;
pthread_t writeThread; pthread_t writeThread;
pthread_t readThread; pthread_t readThread;
// Error #14: Handling for argv not being present.
if (argc < 2) {
printf("Arv args required.\n");
exit(1);
}
T2=malloc(sizeof(Thing)); // Error #5: Should malloc the size of the object, not a pointer. T2=malloc(sizeof(Thing)); // Error #5: Should malloc the size of the object, not a pointer.
umask(0000); // everybody gets everything ? // Error #4: To set 777, umask should be set to 0. This will deny all permisions (I think). umask(0000); // everybody gets everything ? // Error #4: To set 777, umask should be set to 0. This will deny all permisions (I think).
...@@ -72,9 +78,18 @@ return 0; ...@@ -72,9 +78,18 @@ return 0;
// Error #11: Applies to both thread methods. Gives object type name rather than variable name. // Error #11: Applies to both thread methods. Gives object type name rather than variable name.
void * readThing(void * aThing) void * readThing(void * aThing)
{ {
printf("Reading from file...\n");
Thing * readThing = (Thing *)aThing; Thing * readThing = (Thing *)aThing;
fseek(readThing->file,1000,SEEK_SET); fseek(readThing->file,1000,SEEK_SET);
fread(readThing,sizeof(Thing),1,readThing->file); // fread(readThing,sizeof(Thing),1,readThing->file);
fread(&readThing->Field1, sizeof(int), 1, readThing->file);
fread(readThing->Field2, sizeof(struct Thing*), 1, readThing->file);
fread(&readThing->fd, sizeof(int), 1, readThing->file);
fread(readThing->file, sizeof(FILE*), 1, readThing->file);
printf("READ-IN FIELD1: %d\n", readThing->Field1);
printf("READ-IN FIELD2: %p\n", (void*)readThing->Field2);
printf("READ-IN FD: %d\n", readThing->fd);
// printf("READ-IN FILE: %d\n", *readThing->file);
pthread_exit(NULL); pthread_exit(NULL);
} }
...@@ -82,8 +97,19 @@ void * writeThing(void * aThing) ...@@ -82,8 +97,19 @@ void * writeThing(void * aThing)
{ {
Thing * writeThing = (Thing *)aThing; Thing * writeThing = (Thing *)aThing;
lseek(writeThing->fd,1000,SEEK_CUR); lseek(writeThing->fd,1000,SEEK_CUR);
write(writeThing->fd,writeThing,sizeof(Thing)); // Error #15: Trying to write entire struct to file. P sure you need to write the individual struct values,
// write(writeThing->) // or else it's just a memory address which does nothing upon read in.
// write(writeThing->fd,writeThing,sizeof(Thing));
write(writeThing->fd, &writeThing->Field1, sizeof(writeThing->Field1));
write(writeThing->fd, &writeThing->Field2, sizeof(writeThing->Field2));
write(writeThing->fd, &writeThing->fd, sizeof(writeThing->fd));
write(writeThing->fd, &writeThing->file, sizeof(writeThing->file));
printf("WRITE-OUT FIELD1: %d\n", writeThing->Field1);
printf("WRITE-OUT FIELD2: %p\n", (void*)writeThing->Field2);
printf("WRITE-OUT FD: %d\n", writeThing->fd);
// printf("WRITE-OUT FILE: %d\n", *writeThing->file);
pthread_exit(NULL); pthread_exit(NULL);
} }
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