c99 -- ugh, this is HARD

This commit is contained in:
albert 2002-11-27 08:21:30 +00:00
parent c969fe0c58
commit ade43a692b
6 changed files with 33 additions and 26 deletions

View File

@ -102,11 +102,8 @@ static int compare_signal_names(const void *a, const void *b){
}
/* return -1 on failure */
int signal_name_to_number(char *name){
const mapstruct *ptr;
mapstruct ms;
int signal_name_to_number(const char *restrict name){
long val;
char *endp;
int offset;
/* clean up name */
@ -117,11 +114,17 @@ int signal_name_to_number(char *name){
if(!strcasecmp(name,"IOT")) return SIGABRT;
/* search the table */
ms.name = name;
ptr = bsearch(&ms, sigtable, number_of_signals,
sizeof(mapstruct), compare_signal_names
);
if(ptr) return ptr->num;
{
const mapstruct ms = {name,0};
const mapstruct *restrict const ptr = bsearch(
&ms,
sigtable,
number_of_signals,
sizeof(mapstruct),
compare_signal_names
);
if(ptr) return ptr->num;
}
if(!strcasecmp(name,"RTMIN")) return SIGRTMIN;
if(!strcasecmp(name,"EXIT")) return 0;
@ -134,8 +137,11 @@ int signal_name_to_number(char *name){
}
/* not found, so try as a number */
val = strtol(name,&endp,10);
if(*endp || endp==name) return -1; /* not valid */
{
char *endp;
val = strtol(name,&endp,10);
if(*endp || endp==name) return -1; /* not valid */
}
if(val+SIGRTMIN>127) return -1; /* not valid */
return val+offset;
}
@ -153,7 +159,7 @@ static const char *signal_number_to_name(int signo){
return buf;
}
int print_given_signals(int argc, char *argv[], int max_line){
int print_given_signals(int argc, const char **argv, int max_line){
char buf[1280]; /* 128 signals, "RTMIN+xx" is largest */
int ret = 0; /* to be used as exit code by caller */
int place = 0; /* position on this line */
@ -161,8 +167,7 @@ int print_given_signals(int argc, char *argv[], int max_line){
if(argc > 128) return 1;
while(argc--){
char tmpbuf[16];
char *txt; /* convenient alias */
txt = *argv;
const char *restrict const txt = *argv;
if(*txt >= '0' && *txt <= '9'){
long val;
char *endp;

View File

@ -9,10 +9,12 @@
* GNU Library General Public License for more details.
*/
/* return -1 on failure */
extern int signal_name_to_number(char *name);
#include "procps.h"
extern int print_given_signals(int argc, char *argv[], int max_line);
/* return -1 on failure */
extern int signal_name_to_number(const char *restrict name);
extern int print_given_signals(int argc, const char **argv, int max_line);
extern void pretty_print_signals(void);

View File

@ -42,7 +42,6 @@ thing##s[thing##_count++] = addme; \
static int my_pid;
static int saved_argc;
static char **saved_argv;
static int sig_or_pri;
@ -245,7 +244,7 @@ static void kill_usage(void){
}
/***** kill */
static void kill_main(int argc, const char *restrict argv[]){
static void kill_main(int argc, const char *restrict const *restrict argv){
const char *sigptr;
int signo = SIGTERM;
int exitvalue = 0;
@ -368,12 +367,12 @@ static void _skillsnice_usage(int line){
/***** common skill/snice argument parsing code */
#define NO_PRI_VAL ((int)0xdeafbeef)
static void skillsnice_parse(int argc, char *argv[]){
static void skillsnice_parse(int argc, const char *restrict const *restrict argv){
int signo = -1;
int prino = NO_PRI_VAL;
int force = 0;
int num_found = 0;
char *argptr;
const char *restrict argptr;
if(argc<2) skillsnice_usage();
if(argc==2 && argv[1][0]=='-'){
if(!strcmp(argv[1],"-L")){
@ -539,7 +538,6 @@ selection_collection:
int main(int argc, char *argv[]){
char *tmpstr;
my_pid = getpid();
saved_argv = argv;
saved_argc = argc;
if(!argc){
fprintf(stderr,"ERROR: could not determine own name.\n");

View File

@ -26,6 +26,7 @@
#include <dirent.h>
#include <string.h>
#include <errno.h>
#include "proc/procps.h"
/*
* Additional types we might need.

7
top.c
View File

@ -781,7 +781,8 @@ static const char *scale_tics (TICS_t tics, const int width)
* Handle our own memory stuff without the risk of leaving the
* user's terminal in an ugly state should things go sour. */
static void *alloc_c (unsigned numb) MALLOC
static void *alloc_c (unsigned numb) MALLOC;
static void *alloc_c (unsigned numb)
{
void * p;
@ -791,8 +792,8 @@ static void *alloc_c (unsigned numb) MALLOC
return p;
}
static void *alloc_r (void *q, unsigned numb) MALLOC
static void *alloc_r (void *q, unsigned numb) MALLOC;
static void *alloc_r (void *q, unsigned numb)
{
void *p;

View File

@ -54,7 +54,7 @@ static void crash(const char *filename) {
////////////////////////////////////////////////////////////////////////
static void getrunners(unsigned int *restirct running, unsigned int *restrict blocked) {
static void getrunners(unsigned int *restrict running, unsigned int *restrict blocked) {
static struct direct *ent;
DIR *proc;