#define OUTPUT_FILE 2
/* Report problems. */
-void report(char *problem, char *message)
+static void report(const char *problem, const char *message)
{
fprintf(stderr, "%s:\n", problem);
fprintf(stderr, " %s\n\n", message);
}
-int copy_data(int srcfd, int dstfd)
+static int copy_data(int srcfd, int dstfd)
{
char buf[8192];
ssize_t n;
int total=0;
+ /** FIXME: handle error from read() */
+
/* Copy the little bytes themselves. (Source from cp.c). */
while ((n= read(srcfd, buf, sizeof(buf))) > 0) {
char *bp = buf;
- ssize_t r;
+ ssize_t r = 0;
+ /** FIXME: handle error from write() */
while (n > 0 && (r= write(dstfd, bp, n)) > 0) {
bp += r;
n -= r;
total += r;
}
- if (r <= 0) {
- if (r == 0) {
- fprintf(stderr, "Warning: EOF writing to output file.\n");
- return(-1);
- }
+ if (r == 0) {
+ fprintf(stderr, "Warning: EOF writing to output file.\n");
+ return(-1);
}
}
return(total);
int fdin, fdout;
char * bp;
int n,r;
- int total_size=0;
- int result;
+ int total_size;
/* Check if command line arguments are present, or print usage. */
if (argc!=3) {
bp = (char *) &aout;
n = sizeof(aout);
- lseek(fdout, 0, SEEK_SET);
+ lseek(fdout, 0L, SEEK_SET);
while (n > 0 && (r= write(fdout, bp, n)) > 0) {
bp += r;
n -= r;
}
- printf("Prepended data file (%u bytes) with a.out header (%u bytes).\n",
+ printf("Prepended data file (%d bytes) with a.out header (%u bytes).\n",
total_size, sizeof(aout));
printf("Done.\n");
*/
unsigned char boot_spec[24];
-char *bios_err(int err)
+static const char *bios_err(int err)
/* Translate BIOS error code to a readable string. (This is a rare trait
* known as error checking and reporting. Take a good look at it, you won't
* see it often.)
}
}
-void rwerr(char *rw, off_t sec, int err)
+static void rwerr(const char *rw, off_t sec, int err)
{
printf("\n%s error 0x%02x (%s) at sector %ld absolute\n",
rw, err, bios_err(err), sec);
int device; /* Device to edit parameters. */
} bootdev;
-struct termios termbuf;
-int istty;
+static struct termios termbuf;
+static int istty;
void quit(int status)
{
#define exit(s) quit(s)
-void report(char *label)
+void report(const char *label)
/* edparams: label: No such file or directory */
{
fprintf(stderr, "edparams: %s: %s\n", label, strerror(errno));
}
-void fatal(char *label)
+void fatal(const char *label)
{
report(label);
exit(1);
#endif /* UNIX */
-char *readline(void)
+static char *readline(void)
/* Read a line including a newline with echoing. */
{
char *line;
return line;
}
-int sugar(char *tok)
+static int sugar(const char *tok)
/* Recognize special tokens. */
{
return strchr("=(){};\n", tok[0]) != nil;
}
-char *onetoken(char **aline)
+static char *onetoken(char **aline)
/* Returns a string with one token for tokenize. */
{
char *line= *aline;
char *token;
} token;
-token **tokenize(token **acmds, char *line)
+static token **tokenize(token **acmds, char *line)
/* Takes a line apart to form tokens. The tokens are inserted into a command
* chain at *acmds. Tokenize returns a reference to where another line could
* be added. Tokenize looks at spaces as token separators, and recognizes only
return acmds;
}
-token *cmds; /* String of commands to execute. */
-int err; /* Set on an error. */
+static token *cmds; /* String of commands to execute. */
+static int err; /* Set on an error. */
-char *poptoken(void)
+static char *poptoken(void)
/* Pop one token off the command chain. */
{
token *cmd= cmds;
return tok;
}
-void voidtoken(void)
+static void voidtoken(void)
/* Remove one token from the command chain. */
{
free(poptoken());
(void) tokenize(&cmds, code);
}
-int interrupt(void)
+static int interrupt(void)
/* Clean up after an ESC has been typed. */
{
if (escape()) {
#if BIOS
-int activate;
+static int activate;
struct biosdev {
char name[8];
int device, primary, secondary;
} bootdev, tmpdev;
-int get_master(char *master, struct part_entry **table, u32_t pos)
+static int get_master(char *master, struct part_entry **table, u32_t pos)
/* Read a master boot sector and its partition table. */
{
int r, n;
return 0;
}
-void initialize(void)
+static void initialize(void)
{
char master[SECTOR_SIZE];
struct part_entry *table[NR_PARTITIONS];
R_LS, R_MENU, R_OFF, R_SAVE, R_SET, R_TRAP, R_UNSET
};
-char resnames[][6] = {
+static char resnames[][6] = {
"", "boot", "ctty", "delay", "echo", "exit", "help",
"ls", "menu", "off", "save", "set", "trap", "unset",
};
/* Using this for all null strings saves a lot of memory. */
#define null (resnames[0])
-enum resnames reserved(char *s)
+static enum resnames reserved(const char *s)
/* Recognize reserved strings. */
{
enum resnames r;
return R_NULL;
}
-void sfree(char *s)
+static void sfree(char *s)
/* Free a non-null string. */
{
if (s != nil && s != null) free(s);
}
-char *copystr(char *s)
+static char *copystr(char *s)
/* Copy a non-null string using malloc. */
{
char *c;
return c;
}
-int is_default(environment *e)
+static int is_default(environment *e)
{
return (e->flags & E_SPECIAL) && e->defval == nil;
}
-environment **searchenv(char *name)
+static environment **searchenv(char *name)
{
environment **aenv= &env;
return e == nil || !(e->flags & E_VAR) ? nil : e->value;
}
-char *b_body(char *name)
+static char *b_body(char *name)
/* The value of a function. */
{
environment *e= b_getenv(name);
return e == nil || !(e->flags & E_FUNCTION) ? nil : e->value;
}
-int b_setenv(int flags, char *name, char *arg, char *value)
+static int b_setenv(int flags, char *name, char *arg, char *value)
/* Change the value of an environment variable. Returns the flags of the
* variable if you are not allowed to change it, 0 otherwise.
*/
}
}
-long a2l(char *a)
+long a2l(const char *a)
/* Cheap atol(). */
{
int sign= 1;
return ul2a(n, 10);
}
-unsigned a2x(char *a)
+unsigned a2x(const char *a)
/* Ascii to hex. */
{
unsigned n= 0;
return n;
}
-void get_parameters(void)
+static void get_parameters(void)
{
char params[SECTOR_SIZE + 1];
token **acmds;
#endif
}
-char *addptr;
+static char *addptr;
-void addparm(char *n)
+static void addparm(const char *n)
{
while (*n != 0 && *addptr != 0) *addptr++ = *n++;
}
-void save_parameters(void)
+static void save_parameters(void)
/* Save nondefault environment variables to the bootparams sector. */
{
environment *e;
}
}
-void show_env(void)
+static void show_env(void)
/* Show the environment settings. */
{
environment *e;
return 0;
}
-void boot_device(char *devname)
+static void boot_device(char *devname)
/* Boot the device named by devname. */
{
dev_t dev= name2dev(devname);
int save_dev= device;
int r;
- char *err;
+ const char *err;
if (tmpdev.device < 0) {
+ /* FIXME: clearer error message. */
if (dev != -1) printf("Can't boot from %s\n", devname);
return;
}
(void) dev_open();
}
-void ctty(char *line)
+static void ctty(char *line)
{
if (line == nil) {
serial_line = -1;
#else /* DOS */
-void boot_device(char *devname)
+static void boot_device(char *devname)
/* No booting of other devices under DOS. */
{
printf("Can't boot devices under DOS\n");
}
-void ctty(char *line)
+static void ctty(char *line)
/* Don't know how to handle serial lines under DOS. */
{
printf("No serial line support under DOS\n");
#endif /* DOS */
#endif /* BIOS */
-void ls(char *dir)
+static void ls(char *dir)
/* List the contents of a directory. */
{
ino_t ino;
while ((ino= r_readdir(name)) != 0) printf("%s/%s\n", dir, name);
}
-u32_t milli_time(void)
+static u32_t milli_time(void)
{
return get_tick() * MSEC_PER_TICK;
}
-u32_t milli_since(u32_t base)
+static u32_t milli_since(u32_t base)
{
return (milli_time() + (TICKS_PER_DAY*MSEC_PER_TICK) - base)
% (TICKS_PER_DAY*MSEC_PER_TICK);
}
-char *Thandler;
-u32_t Tbase, Tcount;
+static char *Thandler;
+static u32_t Tbase, Tcount;
-void unschedule(void)
+static void unschedule(void)
/* Invalidate a waiting command. */
{
alarm(0);
}
}
-void schedule(long msec, char *cmd)
+static void schedule(long msec, char *cmd)
/* Schedule command at a certain time from now. */
{
unschedule();
} while (!interrupt() && !expired() && milli_since(base) < count);
}
-enum whatfun { NOFUN, SELECT, DEFFUN, USERFUN } menufun(environment *e)
+static enum whatfun { NOFUN, SELECT, DEFFUN, USERFUN } menufun(environment *e)
{
if (!(e->flags & E_FUNCTION) || e->arg[0] == 0) return NOFUN;
if (e->arg[1] != ',') return SELECT;
case SELECT:
printf(" %c Select %s kernel\n", e->arg[0],e->name);
break;
+ case NOFUN:
default:;
}
}
}
}
-void execute(void)
+static void execute(void)
/* Get one command from the command chain and execute it. */
{
token *second, *third, *fourth, *sep;
return !err;
}
-void monitor(void)
+static void monitor(void)
/* Read a line and tokenize it. */
{
char *line;