some fixes

This commit is contained in:
Your Name 2024-02-03 18:36:30 +03:00
parent 2dd48bc2e2
commit c908b952f0
3 changed files with 5 additions and 14 deletions

View File

@ -89,7 +89,6 @@ int main(int argc, char **argv) {
off_t skip = 0; off_t skip = 0;
off_t seek = 0; off_t seek = 0;
off_t count = -1;
off_t bs = 0; off_t bs = 0;
off_t ibs = 512; off_t ibs = 512;

View File

@ -2,7 +2,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
char n_flag = '\n';
int printvars(int len, char **names) { int printvars(int len, char **names) {
int ret = 0; int ret = 0;
@ -14,7 +13,7 @@ int printvars(int len, char **names) {
continue; continue;
} }
printf("%s%c", val, n_flag); printf("%s\n", val);
} }
return ret; return ret;
@ -23,15 +22,8 @@ int printvars(int len, char **names) {
int main(int argc, char **argv, const char **envp) { int main(int argc, char **argv, const char **envp) {
int opt; int opt;
while ((opt = getopt(argc, argv, "0")) != -1) { while ((opt = getopt(argc, argv, "0")) != -1) {
switch (opt) { printf("printenv [var1 var2...]\n");
case '0': return 0;
n_flag = '\0';
break;
default:
printf("printenv [var1 var2...]\n\t[-0 end each output line with NUL]\n");
return 0;
}
} }
argv += optind; argv += optind;
@ -39,7 +31,7 @@ int main(int argc, char **argv, const char **envp) {
if (argc == 0) if (argc == 0)
while (*envp) while (*envp)
printf("%s%c", *envp++, n_flag); printf("%s\n", *envp++);
else else
return printvars(argc, argv); return printvars(argc, argv);

View File

@ -30,7 +30,7 @@ int hide_input(int fd, int flag) {
} }
void login(const struct passwd *pw) { void login(const struct passwd *pw) {
char *shell = pw->pw_shell[0] == '\0' ? "/bin/sh" : pw->pw_shell; char *shell = (pw->pw_shell[0] == '\0') ? "/bin/sh" : pw->pw_shell;
setenv("HOME", pw->pw_dir, 1); setenv("HOME", pw->pw_dir, 1);
setenv("SHELL", shell, 1); setenv("SHELL", shell, 1);