Skip to content

Commit 94ced41

Browse files
committed
refactor: standardize include structures
Standardize and clean up #include directives across all headers, source implementation files, and unit test suites. - Break circular dependency chains between key modules (cache, link, memcache, sonic, and network) using forward struct declarations instead of direct header inclusions. - Group and sort system library and project-specific includes alphabetically at the top of each file. - Remove redundant includes and unused forward declarations. - Explicitly declare direct header dependencies in implementation files.
1 parent 7eea0ea commit 94ced41

18 files changed

Lines changed: 68 additions & 66 deletions

src/cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cache.h"
22

33
#include "config.h"
4+
#include "link.h"
45
#include "log.h"
56
#include "memcache.h"
67
#include "util.h"

src/cache.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
#ifndef CACHE_H
22
#define CACHE_H
3-
#include <sys/types.h>
4-
#include <stdio.h>
5-
#include <stdint.h>
63
#include <pthread.h>
74
#include <semaphore.h>
8-
9-
/**
10-
* \file cache.h
11-
* \brief cache related structures and functions
12-
* \details
13-
* - We store the metadata and the actual data separately in two
14-
* separate folders.
15-
*/
16-
17-
typedef struct Cache Cache;
18-
19-
#include "link.h"
20-
#include "network.h"
5+
#include <stdint.h>
6+
#include <stdio.h>
7+
#include <sys/types.h>
218

229
#include "util.h"
2310

11+
typedef struct Cache Cache;
12+
typedef struct Link Link;
2413
struct TransferStruct;
2514

15+
2616
typedef struct ActiveDownload {
2717
off_t offset;
2818
struct TransferStruct *ts;

src/fuse_local.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "fuse_local.h"
22

3+
#include "cache.h"
34
#include "link.h"
45
#include "log.h"
56

src/link.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#include "link.h"
22

3+
#include "cache.h"
4+
#include "config.h"
35
#include "log.h"
46
#include "memcache.h"
7+
#include "network.h"
58
#include "util.h"
69

7-
#include <gumbo.h>
8-
910
#include <assert.h>
1011
#include <ctype.h>
1112
#include <errno.h>
13+
#include <gumbo.h>
1214
#include <stdlib.h>
1315
#include <string.h>
14-
#include <unistd.h>
1516
#include <sys/param.h>
17+
#include <unistd.h>
1618

1719
#define STATUS_LEN 64
1820

src/link.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
* \brief link related structures and functions
77
*/
88

9-
typedef struct Link Link;
10-
typedef struct LinkTable LinkTable;
9+
#include <curl/curl.h>
10+
#include <limits.h>
11+
#include <sys/types.h>
1112

12-
#include "cache.h"
13-
#include "config.h"
14-
#include "network.h"
13+
#include "memcache.h"
1514
#include "sonic.h"
1615

17-
#include <curl/curl.h>
16+
typedef struct Cache Cache;
17+
typedef struct Link Link;
18+
typedef struct LinkTable LinkTable;
19+
1820

1921
/**
2022
* \brief the link type

src/log.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef LOG_H
22
#define LOG_H
33

4-
#include "util.h"
54

65
/**
76
* \brief Log types

src/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
#include "cache.h"
2+
#include "config.h"
13
#include "fuse_local.h"
24
#include "link.h"
35
#include "log.h"
6+
#include "network.h"
47
#include "util.h"
58

69
#include <ctype.h>
710
#include <errno.h>
8-
#include <unistd.h>
9-
#include <sys/stat.h>
1011
#include <getopt.h>
1112
#include <stdlib.h>
1213
#include <string.h>
14+
#include <sys/stat.h>
15+
#include <unistd.h>
1316

1417
void add_arg(char ***fuse_argv_ptr, int *fuse_argc, char *opt_string);
1518
static void print_help(char *program_name, int long_help);

src/memcache.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef MEMCACHE_H
22
#define MEMCACHE_H
3-
#include "link.h"
3+
4+
#include <stddef.h>
5+
6+
typedef struct Link Link;
7+
typedef struct Cache Cache;
8+
49

510
/**
611
* \brief specify the type of data transfer
@@ -10,7 +15,7 @@ typedef enum { FILESTAT = 's', DATA = 'd' } TransferType;
1015
/**
1116
* \brief For storing transfer data and metadata
1217
*/
13-
struct TransferStruct {
18+
typedef struct TransferStruct {
1419
/** \brief The array to store the data */
1520
char *data;
1621
/** \brief The current size of the array */
@@ -25,7 +30,7 @@ struct TransferStruct {
2530
Cache *cache_ptr;
2631
/** \brief The ActiveDownload structure associated with the transfer */
2732
struct ActiveDownload *ad_ptr;
28-
};
33+
} TransferStruct;
2934

3035
/**
3136
* \brief Callback function for file transfer

src/network.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#include "network.h"
22

3+
#include "config.h"
4+
#include "link.h"
35
#include "log.h"
46
#include "memcache.h"
57
#include "util.h"
68

7-
#include <openssl/crypto.h>
8-
99
#include <errno.h>
10-
#include <string.h>
10+
#include <openssl/crypto.h>
1111
#include <stdio.h>
12+
#include <string.h>
1213
#include <unistd.h>
1314

1415
/*

src/network.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
* \brief network related functions
77
*/
88

9-
typedef struct TransferStruct TransferStruct;
10-
11-
#include "link.h"
12-
139
#include <curl/curl.h>
1410

1511
/** \brief HTTP response codes */

0 commit comments

Comments
 (0)