Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 4/4] attr: Use descriptive variables for argv and allow setting values with embedded nuls
- X-seq: zsh-workers 27341
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: [PATCH 4/4] attr: Use descriptive variables for argv and allow setting values with embedded nuls
- Date: Tue, 3 Nov 2009 19:57:39 +0100 (CET)
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :in-reply-to:message-id:references:user-agent:mime-version :content-type; bh=NZ+tnCv2DWiBW/ApNaly+cwQ3kcx8XI+Yw9O1v/DfCI=; b=iaeVW+EIA3iCXmSnYFNVxXPJNtUoJswwlCau/p/M2CqofGzGWM2jOLqzZ/7QRRJWk3 vpv4fm6mJo75ZGzFXlRDDw2sMglgP+yhTLeugv13+tPjldQ6BPQsve0yNTn1aOv3Mc7G 2aafZrKSeWDpUmHkDIQKp76thil7rsawKnt6k=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:in-reply-to:message-id:references:user-agent :mime-version:content-type; b=xfxHnfNm/w603+wf7TszY2Ofmc/7Xf3JOeOaZOJUASC3DnepYpAUL5IIkrw2VAgI0k CIy3qy758vye9TIAUEBz7zSqXT6NwG5WEAskmG3UdDl/ud2Q1C77yln+u5gHLQPbuO1b yqu5LqQOT9JTD9B8xBam0MYU5ezU5DmyO5Fr4=
- In-reply-to: <alpine.LNX.2.00.0911031951480.3519@localhost>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <alpine.LNX.2.00.0902262245590.27571@localhost> <20090303121253.61f5e2ec@news01> <alpine.LNX.2.00.0903031455360.10365@localhost> <20090303163526.533995be@news01> <237967ef0903030851gc26620ficfc908628a4b3be2@xxxxxxxxxxxxxx> <alpine.LNX.2.00.0911031951480.3519@localhost>
---
Src/Modules/attr.c | 63 ++++++++++++++++++++++++++-------------------------
1 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/Src/Modules/attr.c b/Src/Modules/attr.c
index bb30ebb..88ebb16 100644
--- a/Src/Modules/attr.c
+++ b/Src/Modules/attr.c
@@ -99,26 +99,26 @@ bin_getattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
int ret = 0;
int list_len, val_len, attr_len, slen;
- char *value;
+ char *value, *file = argv[0], *attr = argv[1], *param = argv[2];
int symlink = OPT_ISSET(ops, 'h');
- unmetafy(*argv, &slen);
- unmetafy(*(argv+1), NULL);
- list_len = xlistxattr(*argv, NULL, 0, symlink);
+ unmetafy(file, &slen);
+ unmetafy(attr, NULL);
+ list_len = xlistxattr(file, NULL, 0, symlink);
if (list_len > 0) {
- val_len = xgetxattr(*argv, *(argv+1), NULL, 0, symlink);
+ val_len = xgetxattr(file, attr, NULL, 0, symlink);
if (val_len == 0) {
- if (*(argv+2))
- unsetparam(*(argv+2));
+ if (param)
+ unsetparam(param);
return 0;
}
if (val_len > 0) {
value = (char *)zalloc(val_len+1);
- attr_len = xgetxattr(*argv, *(argv+1), value, val_len, symlink);
+ attr_len = xgetxattr(file, attr, value, val_len, symlink);
if (attr_len > 0 && attr_len <= val_len) {
value[attr_len] = '\0';
- if (*(argv+2))
- setsparam(*(argv+2), metafy(value, attr_len, META_DUP));
+ if (param)
+ setsparam(param, metafy(value, attr_len, META_DUP));
else
printf("%s\n", value);
}
@@ -126,7 +126,7 @@ bin_getattr(char *nam, char **argv, Options ops, UNUSED(int func))
}
}
if (list_len < 0 || val_len < 0 || attr_len < 0) {
- zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno);
+ zwarnnam(nam, "%s: %e", metafy(file, slen, META_NOALLOC), errno);
ret = 1 + (attr_len > val_len);
}
return ret;
@@ -135,14 +135,15 @@ bin_getattr(char *nam, char **argv, Options ops, UNUSED(int func))
static int
bin_setattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
- int ret = 0, slen;
+ int ret = 0, slen, vlen;
int symlink = OPT_ISSET(ops, 'h');
+ char *file = argv[0], *attr = argv[1], *value = argv[2];
- unmetafy(*argv, &slen);
- unmetafy(*(argv+1), NULL);
- unmetafy(*(argv+2), NULL);
- if (xsetxattr(*argv, *(argv+1), *(argv+2), strlen(*(argv+2)), 0, symlink)) {
- zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno);
+ unmetafy(file, &slen);
+ unmetafy(attr, NULL);
+ unmetafy(value, &vlen);
+ if (xsetxattr(file, attr, value, vlen, 0, symlink)) {
+ zwarnnam(nam, "%s: %e", metafy(file, slen, META_NOALLOC), errno);
ret = 1;
}
return ret;
@@ -153,12 +154,12 @@ bin_delattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
int ret = 0, slen;
int symlink = OPT_ISSET(ops, 'h');
- char *file = *argv;
+ char *file = argv[0], **attr = &argv[1];
unmetafy(file, &slen);
- while (*++argv) {
- unmetafy(*argv, NULL);
- if (xremovexattr(file, *argv, symlink)) {
+ while (*++attr) {
+ unmetafy(*attr, NULL);
+ if (xremovexattr(file, *attr, symlink)) {
zwarnnam(nam, "%s: %e", metafy(file, slen, META_NOALLOC), errno);
ret = 1;
break;
@@ -172,24 +173,24 @@ bin_listattr(char *nam, char **argv, Options ops, UNUSED(int func))
{
int ret = 0;
int val_len, list_len, slen;
- char *value;
+ char *value, *file = argv[0], *param = argv[1];
int symlink = OPT_ISSET(ops, 'h');
- unmetafy(*argv, &slen);
- val_len = xlistxattr(*argv, NULL, 0, symlink);
+ unmetafy(file, &slen);
+ val_len = xlistxattr(file, NULL, 0, symlink);
if (val_len == 0) {
- if (*(argv+1))
- unsetparam(*(argv+1));
+ if (param)
+ unsetparam(param);
return 0;
}
if (val_len > 0) {
value = (char *)zalloc(val_len+1);
- list_len = xlistxattr(*argv, value, val_len, symlink);
+ list_len = xlistxattr(file, value, val_len, symlink);
if (list_len > 0 && list_len <= val_len) {
char *p = value;
- if (*(argv+1)) {
+ if (param) {
if (strlen(value) + 1 == list_len)
- setsparam(*(argv+1), metafy(value, list_len-1, META_DUP));
+ setsparam(param, metafy(value, list_len-1, META_DUP));
else {
int arrlen = 0;
char **array = NULL, **arrptr = NULL;
@@ -204,7 +205,7 @@ bin_listattr(char *nam, char **argv, Options ops, UNUSED(int func))
*arrptr++ = metafy(p, -1, META_DUP);
p += strlen(p) + 1;
}
- setaparam(*(argv+1), array);
+ setaparam(param, array);
}
} else while (p < &value[list_len]) {
printf("%s\n", p);
@@ -214,7 +215,7 @@ bin_listattr(char *nam, char **argv, Options ops, UNUSED(int func))
zfree(value, val_len+1);
}
if (val_len < 0 || list_len < 0) {
- zwarnnam(nam, "%s: %e", metafy(*argv, slen, META_NOALLOC), errno);
+ zwarnnam(nam, "%s: %e", metafy(file, slen, META_NOALLOC), errno);
ret = 1 + (list_len > val_len);
}
return ret;
--
1.6.5
Messages sorted by:
Reverse Date,
Date,
Thread,
Author