diff --git a/unjust.c b/unjust.c index b85767220b873543ff1506c10660b919e4c8bbca..3bf8a4f0ff5ea7310a5e52b4c3cb24ed3bdf4223 100644 --- a/unjust.c +++ b/unjust.c @@ -35,6 +35,12 @@ FILE * F; pthread_t writeThread; 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. 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; // Error #11: Applies to both thread methods. Gives object type name rather than variable name. void * readThing(void * aThing) { + printf("Reading from file...\n"); Thing * readThing = (Thing *)aThing; 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); } @@ -82,8 +97,19 @@ void * writeThing(void * aThing) { Thing * writeThing = (Thing *)aThing; lseek(writeThing->fd,1000,SEEK_CUR); -write(writeThing->fd,writeThing,sizeof(Thing)); -// write(writeThing->) +// Error #15: Trying to write entire struct to file. P sure you need to write the individual struct values, +// 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); }