Skip to content

Commit

Permalink
Merge pull request #1783 from ccoffing/size-reductions
Browse files Browse the repository at this point in the history
Size reductions
  • Loading branch information
ghaerr authored Jan 7, 2024
2 parents 88c288b + 8f0e516 commit bf32a25
Show file tree
Hide file tree
Showing 40 changed files with 126 additions and 231 deletions.
2 changes: 1 addition & 1 deletion elks/include/linuxmt/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define structof(p,t,m) ((t *) ((char *) (p) - offsetof (t,m)))

extern void do_exit(int);
extern void do_exit(int) wontreturn;

extern int kill_pg(pid_t,sig_t,int);
extern int kill_sl(void);
Expand Down
3 changes: 1 addition & 2 deletions elks/tools/elks-compress/elks-compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ typedef unsigned short elks_size_t;

static char *readsection(int fd, int size, char *filename)
{
int n;
char *p;

if (size == 0)
Expand All @@ -31,7 +30,7 @@ static char *readsection(int fd, int size, char *filename)
printf("Out of memory\n");
exit(1);
}
if ((n = read(fd, p, size)) != size)
if (read(fd, p, size) != size)
{
printf("Error reading section: %s\n", filename);
exit(1);
Expand Down
4 changes: 0 additions & 4 deletions elks/tools/mfsck/mfsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,8 @@ check_root2 (void) {

static int
add_zone(unsigned short * znr, int * corrected) {
int result;
int block;

result = 0;
block = check_zone_nr(znr, corrected);
if (!block)
return 0;
Expand Down Expand Up @@ -815,10 +813,8 @@ add_zone(unsigned short * znr, int * corrected) {

static int
add_zone2 (unsigned int *znr, int *corrected) {
int result;
int block;

result = 0;
block = check_zone_nr2 (znr, corrected);
if (!block)
return 0;
Expand Down
4 changes: 2 additions & 2 deletions elkscmd/ash/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ forkshell(jp, n, mode)
&& ! fd0_redirected_p ()) {
close(0);
if (open("/dev/null", O_RDONLY) != 0)
error("Can't open /dev/null");
error("Can't open %s", "/dev/null");
}
}
#else
Expand All @@ -579,7 +579,7 @@ forkshell(jp, n, mode)
&& ! fd0_redirected_p ()) {
close(0);
if (open("/dev/null", O_RDONLY) != 0)
error("Can't open /dev/null");
error("Can't open %s", "/dev/null");
}
}
#endif
Expand Down
14 changes: 6 additions & 8 deletions elkscmd/ash/linenoise_elks.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ static void abFree(struct abuf *ab) {
/* Helper of refreshSingleLine() and refreshMultiLine() to show hints
* to the right of the prompt. */
void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int plen) {
char seq[64];
if (hintsCallback && plen+l->len < l->cols) {
int color = -1, bold = 0;
char *hint = hintsCallback(l->buf,&color,&bold);
Expand All @@ -589,10 +588,11 @@ void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int plen) {
if (hintlen > hintmaxlen) hintlen = hintmaxlen;
if (bold == 1 && color == -1) color = 37;
if (color != -1 || bold != 0)
{
char seq[64];
fmtstr(seq, sizeof(seq), "\033[%d;%d;49m",bold,color);
else
seq[0] = '\0';
abAppend(ab,seq,strlen(seq));
abAppend(ab, seq, strlen(seq));
}
abAppend(ab,hint,hintlen);
if (color != -1 || bold != 0)
abAppend(ab,"\033[0m",4);
Expand Down Expand Up @@ -627,8 +627,7 @@ static void refreshSingleLine(struct linenoiseState *l) {

abInit(&ab);
/* Cursor to left edge */
strcpy(seq, "\r");
abAppend(&ab,seq,strlen(seq));
abAppend(&ab,"\r",1);
/* Write the prompt and the current buffer content */
abAppend(&ab,l->prompt,strlen(l->prompt));
if (maskmode == 1) {
Expand Down Expand Up @@ -712,8 +711,7 @@ static void refreshMultiLine(struct linenoiseState *l) {
{
lndebug("<newline>");
abAppend(&ab,"\n",1);
strcpy(seq, "\r");
abAppend(&ab,seq,strlen(seq));
abAppend(&ab,"\r",1);
rows++;
if (rows > (int)l->maxrows) l->maxrows = rows;
}
Expand Down
4 changes: 3 additions & 1 deletion elkscmd/ash/memalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ void
stunalloc(p)
register pointer p;
{
if (p == NULL) { /*DEBUG */
#if DEBUG
if (p == NULL) {
write(2, "stunalloc\n", 10);
abort();
}
#endif
stacknleft += stacknxt - (char *)p;
stacknxt = p;
}
Expand Down
68 changes: 0 additions & 68 deletions elkscmd/ash/mystring.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ static char sccsid[] = "@(#)mystring.c 5.1 (Berkeley) 3/7/91";
*
* equal(s1, s2) Return true if strings are equal.
* scopy(from, to) Copy a string.
* scopyn(from, to, n) Like scopy, but checks for overflow.
* strchr(s, c) Find first occurance of c in s.
* bcopy(from, to, n) Copy a block of memory.
* number(s) Convert a string of digits to an integer.
* is_number(s) Return true if s is a string of digits.
*/
Expand All @@ -61,71 +58,6 @@ static char sccsid[] = "@(#)mystring.c 5.1 (Berkeley) 3/7/91";
char nullstr[1]; /* zero length string */


/*
* scopyn - copy a string from "from" to "to", truncating the string
* if necessary. "To" is always nul terminated, even if
* truncation is performed. "Size" is the size of "to".
*/

void
scopyn(from, to, size)
register char const *from;
register char *to;
int size;
{

while (--size > 0) {
if ((*to++ = *from++) == '\0')
return;
}
*to = '\0';
}


/*
* strchr - find first occurrence of a character in a string.
*/

#ifndef SYS5
char *
mystrchr(s, charwanted)
char const *s;
char charwanted;
{
register char const *scan;

/*
* The odd placement of the two tests is so NUL is findable.
*/
for (scan = s ; *scan != charwanted ; ) /* ++ moved down for opt. */
if (*scan++ == '\0')
return NULL;
return (char *)scan;
}
#endif



/*
* bcopy - copy bytes
*
* This routine was derived from code by Henry Spencer.
*/

void
mybcopy(src, dst, length)
pointer dst;
const pointer src;
int length;
{
register char *d = dst;
register char *s = src;

while (--length >= 0)
*d++ = *s++;
}


/*
* prefix -- see if pfx is a prefix of string.
*/
Expand Down
17 changes: 2 additions & 15 deletions elkscmd/ash/mystring.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,16 @@
* @(#)mystring.h 5.1 (Berkeley) 3/7/91
*/

#ifndef SYSV
#define strchr mystrchr
#endif

#ifdef __STDC__
void scopyn(const char *, char *, int);
char *strchr(const char *, int);
void mybcopy(const pointer, pointer, int);
int prefix(const char *, const char *);
int number(const char *);
int is_number(const char *);
int strcmp(const char *, const char *); /* from C library */
char *strcpy(char *, const char *); /* from C library */
int strlen(const char *); /* from C library */
char *strcat(char *, const char *); /* from C library */
#include <string.h>
#else
void scopyn();
char *strchr();
void mybcopy();
int prefix();
int number();
int is_number();
char *strchr();
int strcmp();
char *strcpy();
int strlen();
Expand All @@ -66,4 +54,3 @@ char *strcat();

#define equal(s1, s2) (strcmp(s1, s2) == 0)
#define scopy(s1, s2) ((void)strcpy(s2, s1))
#define bcopy(src, dst, n) mybcopy((pointer)(src), (pointer)(dst), n)
2 changes: 1 addition & 1 deletion elkscmd/bc/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ execute ()
bc_raise (ex_stack->s_next->s_num,
ex_stack->s_num, &temp_num, scale);
if (is_zero (ex_stack->s_next->s_num) && is_neg (ex_stack->s_num))
rt_error ("divide by zero");
rt_error ("Divide by zero");
pop();
pop();
push_num (temp_num);
Expand Down
2 changes: 1 addition & 1 deletion elkscmd/bc/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ process_params (pc, func)
else
{
if (params->av_name < 0)
rt_error ("Parameter type mismatch parameter %s.",
rt_error ("Parameter type mismatch, parameter %s.",
a_names[-params->av_name]);
else
rt_error ("Parameter type mismatch, parameter %s.",
Expand Down
6 changes: 3 additions & 3 deletions elkscmd/bc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ lookup (name, namekind)
return (-id->a_name);
}
yyerror ("Too many array variables");
exit (1);
break;

case FUNCT:
if (id->f_name != 0)
Expand All @@ -536,7 +536,7 @@ lookup (name, namekind)
return (id->f_name);
}
yyerror ("Too many functions");
exit (1);
break;

case SIMPLE:
if (id->v_name != 0)
Expand All @@ -553,8 +553,8 @@ lookup (name, namekind)
return (id->v_name);
}
yyerror ("Too many variables");
exit (1);
}
exit (1);
}


Expand Down
3 changes: 0 additions & 3 deletions elkscmd/busyelks/cmd/uniq.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <stdlib.h>
#include <stdio.h>

char buffer[BUFSIZ];
int uflag = 1; /* default is union of -d and -u outputs */
int dflag = 1; /* flags are mutually exclusive */
int cflag = 0;
Expand All @@ -40,7 +39,6 @@ char *fn, *mode;

if ((p = fopen(fn, mode)) == NULL) {
perror("uniq");
fflush(stdout);
exit(1);
}
return(p);
Expand All @@ -53,7 +51,6 @@ char *argv[];
char *p;
int inf = -1, outf;

setbuf(stdout, buffer);
for (--argc, ++argv; argc > 0 && (**argv == '-' || **argv == '+');
--argc, ++argv) {
if (**argv == '+')
Expand Down
1 change: 0 additions & 1 deletion elkscmd/busyelks/cmd/wc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ char *argv[];
if (wflag) printf(" %6ld", wcount);
if (cflag) printf(" %6ld", ccount);
printf(" \n");
fflush(stdout);
exit(0);
}

Expand Down
1 change: 1 addition & 0 deletions elkscmd/busyelks/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIB_H

#include <sys/types.h>
#include <time.h>

#if defined(__cplusplus)
extern "C" {
Expand Down
17 changes: 5 additions & 12 deletions elkscmd/cron/cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ securepath(char *path)
if (stat(path, &sb) != 0)
fatal("%s: can't stat", path);
if (stat(".", &sb1) != 0)
fatal(".: can't stat");
fatal("%s: can't stat", ".");
if ((sb.st_dev != sb1.st_dev) || (sb.st_ino != sb1.st_ino))
fatal("cwd not %s", _PATH_CRONDIR);
}
Expand All @@ -211,12 +211,12 @@ triggered(Evmask *t, Evmask *m)
* print the contents of a crontab
*/
#if DEBUG
void
printcrontab(crontab *tab, int nrtab)
static void
printcrontab()
{
int i, j;

for (i = 0; i < nrtab; i++) {
for (i = 0; i < nrtabs; i++) {
if (tabs[i].nrl) {
struct passwd *pwd = getpwuid(tabs[i].user);

Expand All @@ -235,13 +235,6 @@ printcrontab(crontab *tab, int nrtab)
}
}
}
#else
void
printcrontab(crontab *tab, int nrtab)
{
(void)tab;
(void)nrtab;
}
#endif


Expand Down Expand Up @@ -318,9 +311,9 @@ checkcrondir()
printf(" IS %s", ctime(&newtime));
printf("total %d, added %d, updated %d, active %d\n",
nrtabs, ct_add, ct_update, nrtabs - ct_inact);
printcrontab();
#endif
ct_dirtime = newtime;
printcrontab(tabs, nrtabs);
}
}

Expand Down
1 change: 0 additions & 1 deletion elkscmd/cron/cron.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ void info(char *,...);
char *jobenv(crontab *, char *);
void xchdir(char *);
int xis_crondir(void);
void printcrontab(crontab *tab, int nrtab);



Expand Down
3 changes: 1 addition & 2 deletions elkscmd/cron/crontab.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ main(int argc, char **argv)
if (user) {
if ((pwd = getpwnam(user)) == 0)
fatal("user %s does not have a password entry.", user);
} else if ((pwd = getpwuid(getuid())) == 0)
fatal("you don't seem to have a password entry?");
} /* else `pwd` is already set from above */

if ((getuid() != 0) && (pwd->pw_uid != getuid()))
fatal("you may not %s %s's crontab.", what, pwd->pw_name);
Expand Down
Loading

0 comments on commit bf32a25

Please sign in to comment.