-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
120 lines (101 loc) · 3.36 KB
/
Copy pathutils.h
File metadata and controls
120 lines (101 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// File: utils.h
// Created April 7, 2014
// Michael Baptist - mbaptist@ucsc.edu
#ifndef __UTILS_H__
#define __UTILS_H__
//#define NDEBUG NoDebug
/**
* @file client_utils.h
* My utitlies header file for checking errors for system and api function calls.
*/
/**
* A boolean data type created by an enum.
*/
typedef enum {FALSE = 0, TRUE = 1} bool;
/**
* Checks the return value of the socket(3) networking api call for any errors and prints messages and sets the exit status accordingly.
*
* @param fd The file descriptor returned by the socket(3) call.
*/
void check_socket(int fd);
/**
* Checks the return value of the connect(3) networking api call for any errors and prints messages and sets the exit status accordingly.
*
* @param val The return value from the connect(3) call.
*/
void check_connection(int val);
/**
* Checks the current directory for the file filename. If file name is found retrieve_file will attepmt to open the file using fopen. If not an error message will be returned. fclose(3) must be called or memory leak will occur.
*
* @param filename The file to be searched for and opened.
* @param mode The mode in which the file will be opened.
*
* @return The file descriptor for the file if fopen succeeds. Otherwise NULL is returned if filename is not found, or if fopen fails.
*/
FILE *retrieve_file(const char *restrict filename, const char *restrict mode);
/**
* Takes a file and gives back the size of the file.
*
* @param filename The file in which you want the size of.
*
* @return The size of the file filename, or -1 if an error occurs. Errno will be set to the proper error.
*/
int get_file_size(FILE *restrict filename);
/**
* Serializes an int into a unsigned char
*
* @param buffer The array to insert the data.
* @param val The value to serialize.
*
* @return A pointer to the next free space in the buffer.
*/
unsigned char *serialize_int(unsigned char *buffer, unsigned int val);
/**
* Serializes an char array into a unsigned char array
*
* @param buffer The array to insert the data.
* @param buf The value to serialize.
* @param len Then length of buf.
*
* @return A pointer to the next free space in the buffer.
*/
unsigned char *serialize_data(unsigned char *buffer, char buf[], int len);
/**
* Deserializes an int into a unsigned char
*
* @param buffer The array to get the data out of.
* @param val The value to save the data.
*
* @return A pointer to the next free space in the buffer.
*/
unsigned char *deserialize_int(unsigned char *buffer, unsigned int *val);
/**
* Deserializes an char array into a unsigned char array
*
* @param buffer The array to get the data from.
* @param buf The buffer to save it.
* @param len Then length of buf.
*
* @return A pointer to the next free space in the buffer.
*/
unsigned char *deserialize_data(unsigned char *buffer, char buf[], int len);
/**
* Points each element to null in the array.
*
* @param array The array to null out.
* @param len The length of the array.
*
*/
void null_array(char *array[], int len);
/**
* Allows for debugging print statements to be made and easily turned off for release build
*
* @param format The format string to format the print statement.
*/
#ifdef NDEBUG
#define DEBUGF(...) // DEBUG (__VA_ARGS__)
#else
#define DEBUGF(...) debugprintf (__VA_ARGS__)
void debugprintf (char *format, ...);
#endif
#endif