############ progX --> progY
snice kill: skill
- ln skill $@
+ ln -f skill $@
pkill: pgrep
- ln pgrep pkill
+ ln -f pgrep pkill
#include "proc/version.h" /* procps_version */
static int i_am_pkill = 0;
-char *progname = "pgrep";
+static const char *progname = "pgrep";
union el {
long num;
static int opt_exact = 0;
static int opt_signal = SIGTERM;
-static char *opt_delim = "\n";
+static const char *opt_delim = "\n";
static union el *opt_pgrp = NULL;
static union el *opt_gid = NULL;
static union el *opt_ppid = NULL;
* Useful names could be in /proc/PID/fd/2 (stderr, seldom redirected)
* and in /proc/PID/fd/255 (used by bash to remember the tty).
*/
-static int link_name(char * const buf, int maj, int min, int pid, char *name){
+static int link_name(char * const buf, int maj, int min, int pid, const char *name){
struct stat sbuf;
char path[32];
int count;
/* These mostly rely on POSIX to make them zero. */
-static const symb hashtable[256];
+static symb hashtable[256];
static char *sysmap_data;
static unsigned sysmap_room;
static unsigned ksyms_room = 4096;
static symb *ksyms_index;
static unsigned ksyms_count;
-static int idx_room;
+static unsigned idx_room;
/*********************************/
to octal as we go, separating items of the list by 'sep' and stopping after
processing max chars of output (accounting for expansion due to octal rep).
*/
-unsigned print_strlist(FILE* file, char **strs, char* sep, unsigned max) {
- int i, n, seplen = strlen(sep);
+unsigned print_strlist(FILE* file, char **strs, unsigned max) {
+ int i, n;
for (n=0; *strs && n < max; strs++) {
for (i=0; strs[0][i] && n+i < max; i++)
if (isprint(strs[0][i]) || strs[0][i] == ' ')
return max - n;
}
n += i;
- if (n + seplen < max) {
- fputs(sep, file);
- n += seplen;
+ if (n + 1 < max) {
+ fputc(' ', file);
+ n++;
} else
return max - n;
}
extern int open_psdb_message(const char *override, void (*message)(const char *, ...));
extern unsigned print_str (FILE* file, char *s, unsigned max);
-extern unsigned print_strlist(FILE* file, char **strs, char* sep, unsigned max);
+extern unsigned print_strlist(FILE* file, char **strs, unsigned max);
/* fprintf(stderr, "statm2proc converted %d fields.\n",num); */
}
-static int file2str(char *directory, char *what, char *ret, int cap) {
+static int file2str(const char *directory, const char *what, char *ret, int cap) {
static char filename[80];
int fd, num_read;
return num_read;
}
-static char** file2strvec(char* directory, char* what) {
+static char** file2strvec(const char* directory, const char* what) {
char buf[2048]; /* read buf bytes at a time */
char *p, *rbuf = 0, *endbuf, **q, **ret;
int fd, tot = 0, n, c, end_of_file = 0;
#endif
typedef struct mapstruct {
- char *name;
+ const char *name;
int num;
} mapstruct;
-static mapstruct sigtable[] = {
+static const mapstruct sigtable[] = {
{"ABRT", SIGABRT}, /* IOT */
{"ALRM", SIGALRM},
{"BUS", SIGBUS},
static const int number_of_signals = sizeof(sigtable)/sizeof(mapstruct);
static int compare_signal_names(const void *a, const void *b){
- return strcasecmp( ((mapstruct*)a)->name, ((mapstruct*)b)->name );
+ return strcasecmp( ((const mapstruct*)a)->name, ((const mapstruct*)b)->name );
}
/* return -1 on failure */
typedef struct mem_table_struct {
const char *name; /* memory type name */
- const unsigned *slot; /* slot in return struct */
+ unsigned *slot; /* slot in return struct */
} mem_table_struct;
static int compare_mem_table_structs(const void *a, const void *b){
- return strcmp(((mem_table_struct*)a)->name,((mem_table_struct*)b)->name);
+ return strcmp(((const mem_table_struct*)a)->name,((const mem_table_struct*)b)->name);
}
/* example data, following junk, with comments added:
unsigned kb_writeback;
unsigned kb_slab;
unsigned nr_reversemaps;
-unsigned kb_active;
unsigned kb_committed_as;
unsigned kb_dirty;
unsigned kb_inactive;
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
- kb_inactive = -1;
+ kb_inactive = ~0U;
head = buf;
for(;;){
kb_low_total = kb_main_total;
kb_low_free = kb_main_free;
}
- if(kb_inactive==-1){
+ if(kb_inactive==~0U){
kb_inactive = kb_inact_dirty + kb_inact_clean;
}
kb_swap_used = kb_swap_total - kb_swap_free;
typedef struct vm_table_struct {
const char *name; /* VM statistic name */
- const unsigned *slot; /* slot in return struct */
+ unsigned *slot; /* slot in return struct */
} vm_table_struct;
static int compare_vm_table_structs(const void *a, const void *b){
- return strcmp(((vm_table_struct*)a)->name,((vm_table_struct*)b)->name);
+ return strcmp(((const vm_table_struct*)a)->name,((const vm_table_struct*)b)->name);
}
unsigned vm_nr_dirty;
/* global.c */
extern int all_processes;
-extern char *bsd_j_format;
-extern char *bsd_l_format;
-extern char *bsd_s_format;
-extern char *bsd_u_format;
-extern char *bsd_v_format;
+extern const char *bsd_j_format;
+extern const char *bsd_l_format;
+extern const char *bsd_s_format;
+extern const char *bsd_u_format;
+extern const char *bsd_v_format;
extern int bsd_c_option;
extern int bsd_e_option;
extern uid_t cached_euid;
extern selection_node *selection_list;
extern unsigned simple_select;
extern sort_node *sort_list;
-extern char *sysv_f_format;
-extern char *sysv_fl_format;
-extern char *sysv_j_format;
-extern char *sysv_l_format;
+extern const char *sysv_f_format;
+extern const char *sysv_fl_format;
+extern const char *sysv_j_format;
+extern const char *sysv_l_format;
extern int unix_f_option;
extern int user_is_number;
extern int wchan_is_number;
sort_node *tmp_list = sort_list;
while(tmp_list){
int result;
- result = (*tmp_list->sr)(*(const proc_t **)a, *(const proc_t **)b);
+ result = (*tmp_list->sr)(*(const proc_t *const*)a, *(const proc_t *const*)b);
if(result) return (tmp_list->reverse) ? -result : result;
tmp_list = tmp_list->next;
}
#include <grp.h>
#include <string.h>
-/*#undef __GLIBC_MINOR__
-#define __GLIBC_MINOR__ 1 */
#include "common.h"
-/*#undef __GLIBC_MINOR__
-#define __GLIBC_MINOR__ 0 */
#include <sys/sysmacros.h>
#include "../proc/version.h"
#endif
-static char *saved_personality_text = "You found a bug!";
+static const char * saved_personality_text = "You found a bug!";
int all_processes = -1;
-char *bsd_j_format = (char *)0xdeadbeef;
-char *bsd_l_format = (char *)0xdeadbeef;
-char *bsd_s_format = (char *)0xdeadbeef;
-char *bsd_u_format = (char *)0xdeadbeef;
-char *bsd_v_format = (char *)0xdeadbeef;
+const char *bsd_j_format = (const char *)0xdeadbeef;
+const char *bsd_l_format = (const char *)0xdeadbeef;
+const char *bsd_s_format = (const char *)0xdeadbeef;
+const char *bsd_u_format = (const char *)0xdeadbeef;
+const char *bsd_v_format = (const char *)0xdeadbeef;
int bsd_c_option = -1;
int bsd_e_option = -1;
uid_t cached_euid = -1;
selection_node *selection_list = (selection_node *)0xdeadbeef;
unsigned simple_select = 0xffffffff;
sort_node *sort_list = (sort_node *)0xdeadbeef; /* ready-to-use sort list */
-char *sysv_f_format = (char *)0xdeadbeef;
-char *sysv_fl_format = (char *)0xdeadbeef;
-char *sysv_j_format = (char *)0xdeadbeef;
-char *sysv_l_format = (char *)0xdeadbeef;
+const char *sysv_f_format = (const char *)0xdeadbeef;
+const char *sysv_fl_format = (const char *)0xdeadbeef;
+const char *sysv_j_format = (const char *)0xdeadbeef;
+const char *sysv_l_format = (const char *)0xdeadbeef;
int unix_f_option = -1;
int user_is_number = -1;
int wchan_is_number = -1;
} personality_table_struct;
static int compare_personality_table_structs(const void *a, const void *b){
- return strcasecmp(((personality_table_struct*)a)->name,((personality_table_struct*)b)->name);
+ return strcasecmp(((const personality_table_struct*)a)->name,((const personality_table_struct*)b)->name);
}
static const char *set_personality(void){
- char *s;
+ const char *s;
size_t sl;
char buf[16];
personality_table_struct findme = { buf, NULL};
struct tm *proc_time;
struct tm *our_time;
time_t t;
- char *fmt;
+ const char *fmt;
int tm_year;
int tm_yday;
our_time = localtime(&seconds_since_1970); /* not reentrant */
/************ comparison functions for bsearch *************/
static int compare_format_structs(const void *a, const void *b){
- return strcmp(((format_struct*)a)->spec,((format_struct*)b)->spec);
+ return strcmp(((const format_struct*)a)->spec,((const format_struct*)b)->spec);
}
static int compare_macro_structs(const void *a, const void *b){
- return strcmp(((macro_struct*)a)->spec,((macro_struct*)b)->spec);
+ return strcmp(((const macro_struct*)a)->spec,((const macro_struct*)b)->spec);
}
/******** look up structs as needed by the sort & format parsers ******/
} gnu_table_struct;
static int compare_gnu_table_structs(const void *a, const void *b){
- return strcmp(((gnu_table_struct*)a)->name,((gnu_table_struct*)b)->name);
+ return strcmp(((const gnu_table_struct*)a)->name,((const gnu_table_struct*)b)->name);
}
/* Option arguments are after ':', after '=', or in argv[n+1] */
static void O_wrap(sf_node *sfn, int otype){
format_node *fnode;
format_node *endp;
- char *trailer;
+ const char *trailer;
trailer = (otype=='b') ? "END_BSD" : "END_SYS5" ;
* This guy just facilitates Batch and protects against dumb ttys
* -- we'd 'inline' him but he's only called twice per frame,
* yet used in many other locations. */
-static char *tg2 (int x, int y)
+static const char *tg2 (int x, int y)
{
return Cap_can_goto ? tgoto(cursor_address, x, y) : "";
}
* SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT and SIGTERM */
static void stop (int dont_care_sig)
{
+ (void)dont_care_sig;
bye_bye(0, NULL);
}
* SIGTSTP, SIGTTIN and SIGTTOU */
static void suspend (int dont_care_sig)
{
+ (void)dont_care_sig;
/* reset terminal */
tcsetattr(STDIN_FILENO, TCSAFLUSH, &Savedtty);
printf("%s%s", tg2(0, Screen_rows), Cap_curs_norm);
* SK_Kb (1) it's kilobytes
* SK_Mb (2) it's megabytes
* SK_Gb (3) it's gigabytes */
-static char *scale_num (unsigned num, const int width, const unsigned type)
+static const char *scale_num (unsigned num, const int width, const unsigned type)
{
/* kilobytes, megabytes, gigabytes, duh! */
static float scale[] = { 1024, 1024*1024, 1024*1024*1024, 0 };
/*
* Do some scaling stuff.
* Format 'tics' to fit 'width' */
-static char *scale_tics (TICS_t tics, const int width)
+static const char *scale_tics (TICS_t tics, const int width)
{
#define T1 "%u:%02u.%02u"
#define T2 "%u:%02u"
* SIGWINCH and SIGCONT */
static void wins_resize (int dont_care_sig)
{
+ (void)dont_care_sig;
struct winsize wz;
WIN_t *w;
*/
int main (int dont_care_argc, char **argv)
{
+ (void)dont_care_argc;
before(*argv);
/*
Ok, she's gone now. Don't you mind her, she means well but yes, she is
exit(EXIT_FAILURE);
}
-static void crash(char *filename) {
+static void crash(const char *filename) {
perror(filename);
exit(EXIT_FAILURE);
}
fputs(" ", stdout);
if (best) {
if (best->cmdline)
- print_strlist(stdout, best->cmdline, " ", maxcmd);
+ print_strlist(stdout, best->cmdline, maxcmd);
else
printf("%*.*s", -maxcmd, maxcmd, best->cmd);
} else {