forked from dale48/levawc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
73 lines (63 loc) · 1.35 KB
/
utils.h
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
/*
* _____
* ANSI / ___/
* / /__
* \___/
*
* Filename: utils.h
* Author : Dan Levin
* Date : Fri Mar 22 12:40:45 GMT 2013
* Version : 0.40
* ---
* Description: Description: Miscellanenous utility functions
*
*/
/**
* @file utils.h
**/
#include <stdio.h>
#include <stdlib.h>
/* SOME USEFUL MACROS */
/* Check if memory allocation failed - Usage: MALCHK(string); */
/**
* Macro for handling dynamic memory allocation failure
*
**/
#define MALCHK(x) if(!x){puts("Out of memory"); exit(EXIT_FAILURE);}
/* Check if a file was opened properly - Usage: FILCHK(fp); */
/**
* Macro for handling file opening failure
*
**/
#define FILCHK(x) if(!x){printf("Cannot open file %s\n", x); exit(EXIT_FAILURE);}
/* FUNCTION DECLARATIONS */
/**
* Generate random integer values in an interval
*
**/
int randint(int low, int high);
/**
* Set both a lower and upper bounds for an integer value - i.e. force it into a given interval
*
**/
int dn_up_lim(int minval, int maxval, int val);
/**
* Set a lower bound for an integer value
*
**/
int dn_lim(int minval, int val);
/**
* Set an upper bound for an integer value
*
**/
int up_lim(int maxval, int val);
/**
* Return the largest of two integer values
*
**/
int maxval(int val1, int val2);
/**
* Return the smallest of two integer values
*
**/
int minval(int val1, int val2);