Chore: Format all files
This commit is contained in:
parent
6401660479
commit
e03915aa8d
7 changed files with 63 additions and 61 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -3,5 +3,6 @@
|
|||
"files.associations": {
|
||||
"functional": "c",
|
||||
"helper.h": "c"
|
||||
}
|
||||
},
|
||||
"editor.formatOnSave": true
|
||||
}
|
|
@ -17,8 +17,9 @@ 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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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]) {}
|
Loading…
Reference in a new issue