-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_info.c
More file actions
88 lines (82 loc) · 1.97 KB
/
format_info.c
File metadata and controls
88 lines (82 loc) · 1.97 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
#include <stdlib.h>
#include "main.h"
/**
* init_format_info - initializes a format info struct
* @spec: The format info to initialize.
* @spec: The format info to initialize.
*/
void init_format_info(fmt_info_t *spec)
{
if (spec)
{
spec->prec = 1;
spec->width = 0;
spec->spec = FALSE;
spec->is_long_double = FALSE;
spec->is_long_long = FALSE;
spec->is_long = FALSE;
spec->is_short = FALSE;
spec->is_char = FALSE;
spec->is_precision_set = FALSE;
spec->is_width_set = FALSE;
spec->alt = FALSE;
spec->space = FALSE;
spec->left = FALSE;
spec->show_sign = FALSE;
spec->group = FALSE;
spec->pad = ' ';
}
}
/**
* new_format_info - Creates a new format info structure and initializes it
*
* Return: The pointer to the newly created format info structure or NULL
*/
fmt_info_t *new_format_info()
{
fmt_info_t *spec;
spec = malloc(sizeof(fmt_info_t));
if (spec)
init_format_info(spec);
return (spec);
}
/**
* new_float_info - Creates a new float_info struct
* @exponent_size: The number of bits in the exponent
* @mantissa_size: The number of bits in the mantissa
*
* Return: The pointer to the newly created struct, otherwise NULL
*/
float_info_t *new_float_info(ushort_t exponent_size, ushort_t mantissa_size)
{
float_info_t *float_info;
float_info = malloc(sizeof(float_info_t));
if (float_info != NULL)
{
float_info->exponent = malloc(sizeof(char) * (exponent_size + 1));
if (float_info->exponent == NULL)
free(float_info);
float_info->mantissa = malloc(sizeof(char) * (mantissa_size + 1));
if (float_info->mantissa == NULL)
{
free(float_info->exponent);
free(float_info);
}
}
return (float_info);
}
/**
* free_float_info - Frees the memory allocated to the given pointer
* @flt_info: The pointer to free
*/
void free_float_info(float_info_t *flt_info)
{
if (flt_info != NULL)
{
if (flt_info->exponent != NULL)
free(flt_info->exponent);
if (flt_info->mantissa != NULL)
free(flt_info->mantissa);
free(flt_info);
}
}