Chore: Format all files

This commit is contained in:
Dorian Zedler 2022-06-29 11:12:35 +02:00
parent 6401660479
commit e03915aa8d
Signed by: dorian
GPG key ID: 989DE36109AFA354
7 changed files with 63 additions and 61 deletions

View file

@ -3,5 +3,6 @@
"files.associations": {
"functional": "c",
"helper.h": "c"
}
},
"editor.formatOnSave": true
}

View file

@ -17,7 +17,8 @@ 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);

View file

@ -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;
}

View file

@ -4,7 +4,7 @@ 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) {
if (f == NULL) {
printf("Fopen error: %d\n", errno);
fclose(f);
return NULL;
@ -12,13 +12,13 @@ static uint8_t* read_file(const char* path, size_t* size) {
struct stat statOfFile;
int status = fstat(fileno(f), &statOfFile);
if(status == -1) {
if (status == -1) {
printf("Fstat error: %d\n", errno);
fclose(f);
return NULL;
};
if((statOfFile.st_mode & S_IFMT) != S_IFREG){
if ((statOfFile.st_mode & S_IFMT) != S_IFREG) {
printf("File is not a regular file!\n");
fclose(f);
return NULL;
@ -26,9 +26,10 @@ static uint8_t* read_file(const char* path, size_t* size) {
uint8_t* data = malloc(statOfFile.st_size);
size_t bytesRead = fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f);
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)) {
if (bytesRead != 0 && !feof(f)) {
printf("Error reading file!\n");
fclose(f);
return NULL;

View file

@ -3,12 +3,10 @@
#include "md2.h"
int main(int argc, char** argv) {
struct configuration c;
enum argumentParseResult result = parseArguments(argc, argv, &c);
switch (result)
{
switch (result) {
case RESULT_EXIT_SUCCESS:
return EXIT_SUCCESS;
case RESULT_EXIT_FAILURE:
@ -17,7 +15,10 @@ int main(int argc, char** argv) {
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;
}

View file

@ -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]) {
}
void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) {}