diff --git a/.vscode/settings.json b/.vscode/settings.json index 1bc88b6..bd546be 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "files.associations": { "functional": "c", "helper.h": "c" - } + }, + "editor.formatOnSave": true } \ No newline at end of file diff --git a/Implementierung/lib/io.h b/Implementierung/lib/io.h index 6082117..2ed8134 100644 --- a/Implementierung/lib/io.h +++ b/Implementierung/lib/io.h @@ -9,7 +9,7 @@ /** * @brief reads a file at a path - * + * * @param path the filepath * @param size a pointer where the size of the result should be stored * @return the raw data diff --git a/Implementierung/lib/md2.h b/Implementierung/lib/md2.h index 356980f..3880bb7 100644 --- a/Implementierung/lib/md2.h +++ b/Implementierung/lib/md2.h @@ -6,7 +6,7 @@ /** * @brief Calculates checksum of buf and stores it in out - * + * * @param len Length of the data at buf * @param buf Location of the data * @param out Destination array of for the checksum @@ -15,10 +15,11 @@ void md2_hash(size_t len, const uint8_t buf[], uint8_t out[16]); /** * @brief Calculates checksum of buf and appends it to buf - * + * * @param len Length of data which the checksum should be calculated of - * @param buf Location of the data. Make sure to reserve 16 bytes more so the chechsum fits! + * @param buf Location of the data. Make sure to reserve 16 bytes more so the + * chechsum fits! */ void md2_checksum(size_t len, uint8_t* buf); -#endif // MD2_H \ No newline at end of file +#endif // MD2_H \ No newline at end of file diff --git a/Implementierung/src/helper.c b/Implementierung/src/helper.c index 2c9a519..fa3043b 100644 --- a/Implementierung/src/helper.c +++ b/Implementierung/src/helper.c @@ -24,8 +24,9 @@ void help(char *progname) { progname); } -enum argumentParseResult parseArguments(int argc, char **argv, struct configuration* c) { - if(c == NULL) { +enum argumentParseResult parseArguments(int argc, char **argv, + struct configuration *c) { + if (c == NULL) { return RESULT_EXIT_FAILURE; } diff --git a/Implementierung/src/io.c b/Implementierung/src/io.c index 1d0dcfe..ee415ce 100644 --- a/Implementierung/src/io.c +++ b/Implementierung/src/io.c @@ -1,41 +1,42 @@ #include "io.h" static uint8_t* read_file(const char* path, size_t* size) { - // Read the contents of the file specified by path into a heap-allocated - // buffer and return a pointer to that buffer. - FILE* f = fopen(path, "r"); - if(f == NULL) { - printf("Fopen error: %d\n", errno); - fclose(f); - return NULL; - } - - struct stat statOfFile; - int status = fstat(fileno(f), &statOfFile); - if(status == -1) { - printf("Fstat error: %d\n", errno); - fclose(f); - return NULL; - }; - - if((statOfFile.st_mode & S_IFMT) != S_IFREG){ - printf("File is not a regular file!\n"); - fclose(f); - return NULL; - } - - uint8_t* data = malloc(statOfFile.st_size); - - size_t bytesRead = fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f); - // Or: size_t bytesRead = fread(data, sizeof(char), statOfFile.st_size, f); - if(bytesRead != 0 && !feof(f)) { - printf("Error reading file!\n"); - fclose(f); - return NULL; - } - + // Read the contents of the file specified by path into a heap-allocated + // buffer and return a pointer to that buffer. + FILE* f = fopen(path, "r"); + if (f == NULL) { + printf("Fopen error: %d\n", errno); fclose(f); + return NULL; + } - (*size) = bytesRead; - return data; + struct stat statOfFile; + int status = fstat(fileno(f), &statOfFile); + if (status == -1) { + printf("Fstat error: %d\n", errno); + fclose(f); + return NULL; + }; + + if ((statOfFile.st_mode & S_IFMT) != S_IFREG) { + printf("File is not a regular file!\n"); + fclose(f); + return NULL; + } + + uint8_t* data = malloc(statOfFile.st_size); + + size_t bytesRead = + fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f); + // Or: size_t bytesRead = fread(data, sizeof(char), statOfFile.st_size, f); + if (bytesRead != 0 && !feof(f)) { + printf("Error reading file!\n"); + fclose(f); + return NULL; + } + + fclose(f); + + (*size) = bytesRead; + return data; } \ No newline at end of file diff --git a/Implementierung/src/main.c b/Implementierung/src/main.c index 5aae3df..db1527a 100644 --- a/Implementierung/src/main.c +++ b/Implementierung/src/main.c @@ -3,21 +3,22 @@ #include "md2.h" int main(int argc, char** argv) { - - struct configuration c; - enum argumentParseResult result = parseArguments(argc, argv, &c); + struct configuration c; + enum argumentParseResult result = parseArguments(argc, argv, &c); - switch (result) - { + switch (result) { case RESULT_EXIT_SUCCESS: - return EXIT_SUCCESS; + return EXIT_SUCCESS; case RESULT_EXIT_FAILURE: - return EXIT_FAILURE; + return EXIT_FAILURE; default: - break; - } + break; + } - printf("Hashing file: %s\nUsing implementation: %d, doing benchmark: %d, benchmark cycles: %d\n", c.filename, c.implementationToUse, c.doBenchmark, c.benchmarkingCycles); + printf( + "Hashing file: %s\nUsing implementation: %d, doing benchmark: %d, " + "benchmark cycles: %d\n", + c.filename, c.implementationToUse, c.doBenchmark, c.benchmarkingCycles); - return 0; + return 0; } diff --git a/Implementierung/src/md2.c b/Implementierung/src/md2.c index 25c73cc..1f30e8d 100644 --- a/Implementierung/src/md2.c +++ b/Implementierung/src/md2.c @@ -1,11 +1,8 @@ #include "io.h" -// The file "testfile" should lead to this hash: fc982e558db259f298b43cd4c1241c66 +// The file "testfile" should lead to this hash: +// fc982e558db259f298b43cd4c1241c66 -void md2_checksum(size_t len, uint8_t* buf) { +void md2_checksum(size_t len, uint8_t* buf) {} -} - -void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) { - -} \ No newline at end of file +void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) {} \ No newline at end of file