#include <fcntl.h>
#include <ctype.h>
#include <sys/ioctl.h>
+#define BB_DECLARE_EXTERN
+#define bb_need_help
+#include "messages.c"
+
+#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */
+
#if ! defined BB_FEATURE_USE_DEVPS_PATCH
int len, i, c;
#ifdef BB_FEATURE_AUTOWIDTH
struct winsize win = { 0, 0 };
- int terminal_width = 0;
+ int terminal_width = TERMINAL_WIDTH;
#else
-#define terminal_width 79
+#define terminal_width TERMINAL_WIDTH
#endif
- if (argc > 1 && **(argv + 1) == '-')
- usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
+ if (argc > 1 && strcmp(argv[1], dash_dash_help) == 0) {
+ usage ("ps\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+ "\nReport process status\n"
+ "\nThis version of ps accepts no options.\n"
+#endif
+ );
+ }
dir = opendir("/proc");
if (!dir)
- fatalError("Can't open /proc");
+ fatalError("Can't open /proc\n");
#ifdef BB_FEATURE_AUTOWIDTH
ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (*groupName == '\0')
sprintf(groupName, "%d", p.rgid);
- len = fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
- p.state);
sprintf(path, "/proc/%s/cmdline", entry->d_name);
file = fopen(path, "r");
if (file == NULL)
- fatalError("Can't open %s: %s\n", path, strerror(errno));
+ continue;
i = 0;
+ len = fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
+ p.state);
while (((c = getc(file)) != EOF) && (i < (terminal_width-len))) {
i++;
if (c == '\0')
fprintf(stdout, "\n");
}
closedir(dir);
- exit(TRUE);
+ return(TRUE);
}
char groupName[10] = "";
#ifdef BB_FEATURE_AUTOWIDTH
struct winsize win = { 0, 0 };
- int terminal_width = 0;
+ int terminal_width = TERMINAL_WIDTH;
#else
-#define terminal_width 79
+#define terminal_width TERMINAL_WIDTH
#endif
if (argc > 1 && **(argv + 1) == '-')