summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar/subst.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tar/subst.c')
-rw-r--r--usr.bin/tar/subst.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/usr.bin/tar/subst.c b/usr.bin/tar/subst.c
index 13464cd..44fd87b 100644
--- a/usr.bin/tar/subst.c
+++ b/usr.bin/tar/subst.c
@@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$");
#if HAVE_REGEX_H
#include "bsdtar.h"
+#include "err.h"
#include <errno.h>
#include <regex.h>
@@ -56,7 +57,7 @@ init_substitution(struct bsdtar *bsdtar)
bsdtar->substitution = subst = malloc(sizeof(*subst));
if (subst == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_errc(1, errno, "Out of memory");
subst->first_rule = subst->last_rule = NULL;
}
@@ -76,7 +77,7 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
rule = malloc(sizeof(*rule));
if (rule == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_errc(1, errno, "Out of memory");
rule->next = NULL;
if (subst->last_rule == NULL)
@@ -86,32 +87,32 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
subst->last_rule = rule;
if (*rule_text == '\0')
- bsdtar_errc(bsdtar, 1, 0, "Empty replacement string");
+ bsdtar_errc(1, 0, "Empty replacement string");
end_pattern = strchr(rule_text + 1, *rule_text);
if (end_pattern == NULL)
- bsdtar_errc(bsdtar, 1, 0, "Invalid replacement string");
+ bsdtar_errc(1, 0, "Invalid replacement string");
pattern = malloc(end_pattern - rule_text);
if (pattern == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_errc(1, errno, "Out of memory");
memcpy(pattern, rule_text + 1, end_pattern - rule_text - 1);
pattern[end_pattern - rule_text - 1] = '\0';
if ((r = regcomp(&rule->re, pattern, REG_BASIC)) != 0) {
char buf[80];
regerror(r, &rule->re, buf, sizeof(buf));
- bsdtar_errc(bsdtar, 1, 0, "Invalid regular expression: %s", buf);
+ bsdtar_errc(1, 0, "Invalid regular expression: %s", buf);
}
free(pattern);
start_subst = end_pattern + 1;
end_pattern = strchr(start_subst, *rule_text);
if (end_pattern == NULL)
- bsdtar_errc(bsdtar, 1, 0, "Invalid replacement string");
+ bsdtar_errc(1, 0, "Invalid replacement string");
rule->result = malloc(end_pattern - start_subst + 1);
if (rule->result == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_errc(1, errno, "Out of memory");
memcpy(rule->result, start_subst, end_pattern - start_subst);
rule->result[end_pattern - start_subst] = '\0';
@@ -134,13 +135,13 @@ add_substitution(struct bsdtar *bsdtar, const char *rule_text)
rule->symlink = 1;
break;
default:
- bsdtar_errc(bsdtar, 1, 0, "Invalid replacement flag %c", *end_pattern);
+ bsdtar_errc(1, 0, "Invalid replacement flag %c", *end_pattern);
}
}
}
static void
-realloc_strncat(struct bsdtar *bsdtar, char **str, const char *append, size_t len)
+realloc_strncat(char **str, const char *append, size_t len)
{
char *new_str;
size_t old_len;
@@ -152,7 +153,7 @@ realloc_strncat(struct bsdtar *bsdtar, char **str, const char *append, size_t le
new_str = malloc(old_len + len + 1);
if (new_str == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_errc(1, errno, "Out of memory");
memcpy(new_str, *str, old_len);
memcpy(new_str + old_len, append, len);
new_str[old_len + len] = '\0';
@@ -161,7 +162,7 @@ realloc_strncat(struct bsdtar *bsdtar, char **str, const char *append, size_t le
}
static void
-realloc_strcat(struct bsdtar *bsdtar, char **str, const char *append)
+realloc_strcat(char **str, const char *append)
{
char *new_str;
size_t old_len;
@@ -173,7 +174,7 @@ realloc_strcat(struct bsdtar *bsdtar, char **str, const char *append)
new_str = malloc(old_len + strlen(append) + 1);
if (new_str == NULL)
- bsdtar_errc(bsdtar, 1, errno, "Out of memory");
+ bsdtar_errc(1, errno, "Out of memory");
memcpy(new_str, *str, old_len);
strcpy(new_str + old_len, append);
free(*str);
@@ -206,12 +207,12 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
got_match = 1;
print_match |= rule->print;
- realloc_strncat(bsdtar, result, name, matches[0].rm_so);
+ realloc_strncat(result, name, matches[0].rm_so);
for (i = 0, j = 0; rule->result[i] != '\0'; ++i) {
if (rule->result[i] == '~') {
- realloc_strncat(bsdtar, result, rule->result + j, i - j);
- realloc_strncat(bsdtar, result, name, matches[0].rm_eo);
+ realloc_strncat(result, rule->result + j, i - j);
+ realloc_strncat(result, name, matches[0].rm_eo);
j = i + 1;
continue;
}
@@ -223,7 +224,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
switch (c) {
case '~':
case '\\':
- realloc_strncat(bsdtar, result, rule->result + j, i - j - 1);
+ realloc_strncat(result, rule->result + j, i - j - 1);
j = i;
break;
case '1':
@@ -235,13 +236,13 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
case '7':
case '8':
case '9':
- realloc_strncat(bsdtar, result, rule->result + j, i - j - 1);
+ realloc_strncat(result, rule->result + j, i - j - 1);
if ((size_t)(c - '0') > (size_t)(rule->re.re_nsub)) {
free(*result);
*result = NULL;
return -1;
}
- realloc_strncat(bsdtar, result, name + matches[c - '0'].rm_so, matches[c - '0'].rm_eo - matches[c - '0'].rm_so);
+ realloc_strncat(result, name + matches[c - '0'].rm_so, matches[c - '0'].rm_eo - matches[c - '0'].rm_so);
j = i + 1;
break;
default:
@@ -251,7 +252,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
}
- realloc_strcat(bsdtar, result, rule->result + j);
+ realloc_strcat(result, rule->result + j);
name += matches[0].rm_eo;
@@ -260,7 +261,7 @@ apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int s
}
if (got_match)
- realloc_strcat(bsdtar, result, name);
+ realloc_strcat(result, name);
if (print_match)
fprintf(stderr, "%s >> %s\n", path, *result);
OpenPOWER on IntegriCloud