-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrstr.c
73 lines (57 loc) · 2.43 KB
/
arrstr.c
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
/*
********************************************************************
* USB stack and host controller driver for SGI IRIX 6.5 *
* *
* Programmed by BSDero *
* bsdero at gmail dot com *
* 2011/2012 *
* *
* *
* File: arrstr.c *
* Description: String array basic functions *
********************************************************************
*******************************************************************************************************
* FIXLIST (latest at top) *
*-----------------------------------------------------------------------------------------------------*
* Author MM-DD-YYYY Description *
*-----------------------------------------------------------------------------------------------------*
* BSDero 09-13-2012 -Initial version *
* *
*******************************************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include "arrstr.h"
void arrstr_init( arrstr_t *arr, int max){
memset( (void *) arr, 0, sizeof( arrstr_t));
if( max >= MAX_STRINGS)
max = MAX_STRINGS;
arr->max = max;
}
void arrstr_destroy( arrstr_t *arr){
int i;
for( i = 0; i < arr->max; i++){
if( arr->str[i] != NULL)
free( arr->str[i]);
}
arrstr_init( arr, MAX_STRINGS);
}
void arrstr_add( arrstr_t *arr, char *str){
int i;
if( arr->str[0] != NULL)
free( arr->str[0]);
for( i = 0; i < ( arr->max - 1); i++){
arr->str[i] = arr->str[i + 1];
}
arr->str[i] = strdup( str);
}
void arrstr_dump( arrstr_t *arr){
int i;
printf("DUMP\n");
for( i = 0; i < arr->max; i++){
if( arr->str[i] == NULL)
printf("%d : NULL\n", i);
else
printf("%d : %s\n", i, arr->str[i]);
}
}