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

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

View File

@ -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
#endif // MD2_H

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

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

View File

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

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]) {}