Minor fixes to previous change introducing switch -H, as per comments

on -arch.

Reviewed by:	gleb
This commit is contained in:
Thomas Quinot 2014-05-11 18:49:18 +00:00
parent e2fc1af45e
commit 55298f0397
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=265893
2 changed files with 22 additions and 16 deletions

View File

@ -130,6 +130,7 @@ and use
.Xr fhstat 2 .Xr fhstat 2
instead of instead of
.Xr lstat 2 . .Xr lstat 2 .
This requires root privileges.
.It Fl L .It Fl L
Use Use
.Xr stat 2 .Xr stat 2

View File

@ -186,6 +186,7 @@ int format1(const struct stat *, /* stat info */
char *, size_t, /* a place to put the output */ char *, size_t, /* a place to put the output */
int, int, int, int, /* the parsed format */ int, int, int, int, /* the parsed format */
int, int); int, int);
int hex2byte(const char [2]);
#if HAVE_STRUCT_STAT_ST_FLAGS #if HAVE_STRUCT_STAT_ST_FLAGS
char *xfflagstostr(unsigned long); char *xfflagstostr(unsigned long);
#endif #endif
@ -214,7 +215,7 @@ main(int argc, char *argv[])
lsF = 0; lsF = 0;
fmtchar = '\0'; fmtchar = '\0';
usestat = 0; usestat = 0;
nfs_handle = 0; nfs_handle = 0;
nonl = 0; nonl = 0;
quiet = 0; quiet = 0;
linkfail = 0; linkfail = 0;
@ -327,32 +328,27 @@ main(int argc, char *argv[])
rc = fstat(STDIN_FILENO, &st); rc = fstat(STDIN_FILENO, &st);
} else { } else {
int j; int j;
char *inval;
file = argv[0]; file = argv[0];
if (nfs_handle) { if (nfs_handle) {
rc = 0; rc = 0;
bzero (&fhnd, sizeof fhnd); bzero(&fhnd, sizeof(fhnd));
j = MIN(2 * sizeof fhnd, strlen(file)); j = MIN(2 * sizeof(fhnd), strlen(file));
if (j & 1) { if ((j & 1) != 0) {
rc = -1; rc = -1;
} else { } else {
while (j) { while (j) {
((char*) &fhnd)[j / 2 - 1] = rc = hex2byte(&file[j - 2]);
strtol(&file[j - 2], if (rc == -1)
&inval, 16);
if (inval != NULL) {
rc = -1;
break; break;
} ((char*) &fhnd)[j / 2 - 1] = rc;
argv[0][j - 2] = '\0';
j -= 2; j -= 2;
} }
if (!rc)
rc = fhstat(&fhnd, &st);
else
errno = EINVAL;
} }
if (rc == -1)
errno = EINVAL;
else
rc = fhstat(&fhnd, &st);
} else if (usestat) { } else if (usestat) {
/* /*
@ -1091,3 +1087,12 @@ format1(const struct stat *st,
return (snprintf(buf, blen, lfmt, data)); return (snprintf(buf, blen, lfmt, data));
} }
#define hex2nibble(c) (c <= '9' ? c - '0' : toupper(c) - 'A' + 10)
int
hex2byte(const char c[2]) {
if (!(ishexnumber(c[0]) && ishexnumber(c[1])))
return -1;
return (hex2nibble(c[0]) << 4) + hex2nibble(c[1]);
}