diff options
Diffstat (limited to 'libbb/auto_string.c')
-rw-r--r-- | libbb/auto_string.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libbb/auto_string.c b/libbb/auto_string.c new file mode 100644 index 000000000..ae940069a --- /dev/null +++ b/libbb/auto_string.c | |||
@@ -0,0 +1,23 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) 2015 Denys Vlasenko | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
8 | */ | ||
9 | //kbuild:lib-y += auto_string.o | ||
10 | |||
11 | #include "libbb.h" | ||
12 | |||
13 | char* FAST_FUNC auto_string(char *str) | ||
14 | { | ||
15 | static char *saved[4]; | ||
16 | static uint8_t cur_saved; /* = 0 */ | ||
17 | |||
18 | free(saved[cur_saved]); | ||
19 | saved[cur_saved] = str; | ||
20 | cur_saved = (cur_saved + 1) & (ARRAY_SIZE(saved)-1); | ||
21 | |||
22 | return str; | ||
23 | } | ||