chpst: fix "env directory" parsing to not strip everything

after 1st whitespace. -6 bytes.
This commit is contained in:
Denis Vlasenko 2008-04-01 16:13:14 +00:00
parent 9dedf72e71
commit 9895dfdb9a

View File

@ -114,6 +114,10 @@ static void edir(const char *directory_name)
if (!dir) if (!dir)
bb_perror_msg_and_die("opendir %s", directory_name); bb_perror_msg_and_die("opendir %s", directory_name);
for (;;) { for (;;) {
char buf[256];
char *tail;
int size;
errno = 0; errno = 0;
d = readdir(dir); d = readdir(dir);
if (!d) { if (!d) {
@ -135,12 +139,8 @@ static void edir(const char *directory_name)
bb_perror_msg_and_die("open %s/%s", bb_perror_msg_and_die("open %s/%s",
directory_name, d->d_name); directory_name, d->d_name);
} }
if (fd >= 0) { size = full_read(fd, buf, sizeof(buf)-1);
char buf[256]; close(fd);
char *tail;
int size;
size = safe_read(fd, buf, sizeof(buf)-1);
if (size < 0) if (size < 0)
bb_perror_msg_and_die("read %s/%s", bb_perror_msg_and_die("read %s/%s",
directory_name, d->d_name); directory_name, d->d_name);
@ -149,18 +149,16 @@ static void edir(const char *directory_name)
continue; continue;
} }
buf[size] = '\n'; buf[size] = '\n';
tail = memchr(buf, '\n', sizeof(buf)); tail = strchr(buf, '\n');
/* skip trailing whitespace */; /* skip trailing whitespace */
while (1) { while (1) {
if (tail[0] == ' ') tail[0] = '\0'; *tail = '\0';
if (tail[0] == '\t') tail[0] = '\0';
if (tail[0] == '\n') tail[0] = '\0';
if (tail == buf) break;
tail--; tail--;
if (tail < buf || !isspace(*tail))
break;
} }
xsetenv(d->d_name, buf); xsetenv(d->d_name, buf);
} }
}
closedir(dir); closedir(dir);
if (fchdir(wdir) == -1) if (fchdir(wdir) == -1)
bb_perror_msg_and_die("fchdir"); bb_perror_msg_and_die("fchdir");