Skip to content

Commit 6f60568

Browse files
author
Damien Churchill
committed
remove the need for common.c
1 parent b882fe8 commit 6f60568

File tree

3 files changed

+31
-65
lines changed

3 files changed

+31
-65
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ endif
1717

1818
all: $(TARGETS)
1919

20-
blksync: action.o chunk.o common.o worker.o writer.o
20+
blksync: action.o chunk.o worker.o writer.o
2121

2222
testAction: action.o
2323

common.c

-61
This file was deleted.

common.h

+30-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
*
1919
*/
2020

21+
#include <errno.h>
22+
#include <stdio.h>
2123
#include <mqueue.h>
24+
#include <pthread.h>
2225

2326
#ifndef BS_COMMON_H
2427
#define BS_COMMON_H
@@ -42,15 +45,39 @@ typedef struct {
4245

4346
#ifdef USE_OPENSSL
4447
#include <openssl/sha.h>
48+
static inline void bs_sha1(void *hash, const void *message, size_t length) {
49+
SHA1(message, length, hash);
50+
}
4551
#elif USE_GCRYPT
4652
#include <gcrypt.h>
53+
static inline void bs_sha1(void *hash, const void *message, size_t length) {
54+
gcry_md_hash_buffer(GCRY_MD_SHA1, hash, message, length);
55+
}
4756
#else
4857
#error No cryptographic library specififed.
4958
#endif
5059

51-
void bs_sha1(void *hash, const void *message, size_t length);
60+
/**
61+
* Print out a sha1 hash
62+
*/
63+
static inline void bs_print_hash(unsigned char *hash, int length) {
64+
int i;
65+
for (i = 0; i < length; i++) {
66+
printf("%02x", hash[i]);
67+
}
68+
}
5269

53-
void bs_print_hash(unsigned char *hash, int length);
70+
/**
71+
* Safely open a file for read/write if it does not exist, without wiping
72+
* the contents of the file.
73+
*/
74+
static inline FILE *bs_open_rw(char *path) {
75+
FILE *fp;
5476

55-
FILE *bs_open_rw(char *path);
77+
fp = fopen(path, "r+");
78+
if (fp == NULL && errno == ENOENT) {
79+
fp = fopen(path, "w+");
80+
}
81+
return fp;
82+
}
5683
#endif

0 commit comments

Comments
 (0)