Make fileio() and do_op() arguments const where possible
This commit is contained in:
parent
a1018999c4
commit
87df3216cb
92
src/fileio.c
92
src/fileio.c
|
@ -57,47 +57,47 @@ struct ihexrec {
|
|||
};
|
||||
|
||||
|
||||
static int b2ihex(unsigned char * inbuf, int bufsize,
|
||||
static int b2ihex(const unsigned char *inbuf, int bufsize,
|
||||
int recsize, int startaddr,
|
||||
char * outfile, FILE * outf, FILEFMT ffmt);
|
||||
const char *outfile, FILE *outf, FILEFMT ffmt);
|
||||
|
||||
static int ihex2b(char * infile, FILE * inf,
|
||||
AVRMEM * mem, int bufsize, unsigned int fileoffset,
|
||||
static int ihex2b(const char *infile, FILE *inf,
|
||||
const AVRMEM *mem, int bufsize, unsigned int fileoffset,
|
||||
FILEFMT ffmt);
|
||||
|
||||
static int b2srec(unsigned char * inbuf, int bufsize,
|
||||
static int b2srec(const unsigned char *inbuf, int bufsize,
|
||||
int recsize, int startaddr,
|
||||
char * outfile, FILE * outf);
|
||||
const char *outfile, FILE *outf);
|
||||
|
||||
static int srec2b(char * infile, FILE * inf,
|
||||
AVRMEM * mem, int bufsize, unsigned int fileoffset);
|
||||
static int srec2b(const char *infile, FILE *inf,
|
||||
const AVRMEM *mem, int bufsize, unsigned int fileoffset);
|
||||
|
||||
static int ihex_readrec(struct ihexrec *ihex, char *rec);
|
||||
|
||||
static int srec_readrec(struct ihexrec *srec, char *rec);
|
||||
|
||||
static int fileio_rbin(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size);
|
||||
const char *filename, FILE *f, const AVRMEM *mem, int size);
|
||||
|
||||
static int fileio_ihex(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size,
|
||||
const char *filename, FILE *f, const AVRMEM *mem, int size,
|
||||
FILEFMT ffmt);
|
||||
|
||||
static int fileio_srec(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size);
|
||||
const char *filename, FILE *f, const AVRMEM *mem, int size);
|
||||
|
||||
#ifdef HAVE_LIBELF
|
||||
static int elf2b(char * infile, FILE * inf,
|
||||
AVRMEM * mem, struct avrpart * p,
|
||||
static int elf2b(const char *infile, FILE *inf,
|
||||
const AVRMEM *mem, const AVRPART *p,
|
||||
int bufsize, unsigned int fileoffset);
|
||||
|
||||
static int fileio_elf(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem,
|
||||
struct avrpart * p, int size);
|
||||
const char *filename, FILE *f, const AVRMEM *mem,
|
||||
const AVRPART *p, int size);
|
||||
#endif
|
||||
|
||||
static int fileio_num(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size,
|
||||
const char *filename, FILE *f, const AVRMEM *mem, int size,
|
||||
FILEFMT fmt);
|
||||
|
||||
|
||||
|
@ -115,11 +115,11 @@ char * fileio_fmtstr(FILEFMT format)
|
|||
}
|
||||
|
||||
|
||||
static int b2ihex(unsigned char * inbuf, int bufsize,
|
||||
static int b2ihex(const unsigned char *inbuf, int bufsize,
|
||||
int recsize, int startaddr,
|
||||
char * outfile, FILE * outf, FILEFMT ffmt)
|
||||
const char *outfile, FILE *outf, FILEFMT ffmt)
|
||||
{
|
||||
unsigned char * buf;
|
||||
const unsigned char *buf;
|
||||
unsigned int nextaddr;
|
||||
int n, nbytes, n_64k;
|
||||
int i;
|
||||
|
@ -292,8 +292,8 @@ static int ihex_readrec(struct ihexrec * ihex, char * rec)
|
|||
* If an error occurs, return -1.
|
||||
*
|
||||
* */
|
||||
static int ihex2b(char * infile, FILE * inf,
|
||||
AVRMEM * mem, int bufsize, unsigned int fileoffset,
|
||||
static int ihex2b(const char *infile, FILE *inf,
|
||||
const AVRMEM *mem, int bufsize, unsigned int fileoffset,
|
||||
FILEFMT ffmt)
|
||||
{
|
||||
char buffer [ MAX_LINE_LEN ];
|
||||
|
@ -394,11 +394,11 @@ static int ihex2b(char * infile, FILE * inf,
|
|||
}
|
||||
}
|
||||
|
||||
static int b2srec(unsigned char * inbuf, int bufsize,
|
||||
static int b2srec(const unsigned char *inbuf, int bufsize,
|
||||
int recsize, int startaddr,
|
||||
char * outfile, FILE * outf)
|
||||
const char *outfile, FILE *outf)
|
||||
{
|
||||
unsigned char * buf;
|
||||
const unsigned char *buf;
|
||||
unsigned int nextaddr;
|
||||
int n, nbytes, addr_width;
|
||||
unsigned char cksum;
|
||||
|
@ -573,8 +573,8 @@ static int srec_readrec(struct ihexrec * srec, char * rec)
|
|||
}
|
||||
|
||||
|
||||
static int srec2b(char * infile, FILE * inf,
|
||||
AVRMEM * mem, int bufsize, unsigned int fileoffset)
|
||||
static int srec2b(const char *infile, FILE * inf,
|
||||
const AVRMEM *mem, int bufsize, unsigned int fileoffset)
|
||||
{
|
||||
char buffer [ MAX_LINE_LEN ];
|
||||
unsigned int nextaddr, maxaddr;
|
||||
|
@ -741,7 +741,7 @@ static Elf_Scn *elf_get_scn(Elf *e, Elf32_Phdr *ph, Elf32_Shdr **shptr)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int elf_mem_limits(AVRMEM *mem, struct avrpart * p,
|
||||
static int elf_mem_limits(const AVRMEM *mem, const AVRPART *p,
|
||||
unsigned int *lowbound,
|
||||
unsigned int *highbound,
|
||||
unsigned int *fileoff)
|
||||
|
@ -799,8 +799,8 @@ static int elf_mem_limits(AVRMEM *mem, struct avrpart * p,
|
|||
}
|
||||
|
||||
|
||||
static int elf2b(char * infile, FILE * inf,
|
||||
AVRMEM * mem, struct avrpart * p,
|
||||
static int elf2b(const char *infile, FILE *inf,
|
||||
const AVRMEM *mem, const AVRPART *p,
|
||||
int bufsize, unsigned int fileoffset)
|
||||
{
|
||||
Elf *e;
|
||||
|
@ -1040,8 +1040,7 @@ static char *itoa_simple(int n, char *buf, int base)
|
|||
|
||||
|
||||
static int fileio_rbin(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size)
|
||||
{
|
||||
const char *filename, FILE *f, const AVRMEM *mem, int size) {
|
||||
int rc;
|
||||
unsigned char *buf = mem->buf;
|
||||
|
||||
|
@ -1070,13 +1069,15 @@ static int fileio_rbin(struct fioparms * fio,
|
|||
|
||||
|
||||
static int fileio_imm(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size)
|
||||
const char *fname, FILE *f, const AVRMEM *mem, int size)
|
||||
{
|
||||
int rc = 0;
|
||||
char * e, * p;
|
||||
char *e, *p, *filename;
|
||||
unsigned long b;
|
||||
int loc;
|
||||
|
||||
filename = cfg_strdup(__func__, fname);
|
||||
|
||||
switch (fio->op) {
|
||||
case FIO_READ:
|
||||
loc = 0;
|
||||
|
@ -1089,6 +1090,7 @@ static int fileio_imm(struct fioparms * fio,
|
|||
strtoul (p + 2, &e, 2);
|
||||
if (*e != 0) {
|
||||
pmsg_error("invalid byte value (%s) specified for immediate mode\n", p);
|
||||
free(filename);
|
||||
return -1;
|
||||
}
|
||||
mem->buf[loc] = b;
|
||||
|
@ -1100,25 +1102,29 @@ static int fileio_imm(struct fioparms * fio,
|
|||
|
||||
case FIO_WRITE:
|
||||
pmsg_error("invalid file format 'immediate' for output\n");
|
||||
free(filename);
|
||||
return -1;
|
||||
|
||||
default:
|
||||
pmsg_error("invalid operation=%d\n", fio->op);
|
||||
free(filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc < 0 || (fio->op == FIO_WRITE && rc < size)) {
|
||||
pmsg_ext_error("%s error %s %s: %s; %s %d of the expected %d bytes\n",
|
||||
fio->iodesc, fio->dir, filename, strerror(errno), fio->rw, rc, size);
|
||||
free(filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(filename);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
static int fileio_ihex(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size,
|
||||
const char *filename, FILE *f, const AVRMEM *mem, int size,
|
||||
FILEFMT ffmt)
|
||||
{
|
||||
int rc;
|
||||
|
@ -1148,7 +1154,7 @@ static int fileio_ihex(struct fioparms * fio,
|
|||
|
||||
|
||||
static int fileio_srec(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size)
|
||||
const char *filename, FILE *f, const AVRMEM *mem, int size)
|
||||
{
|
||||
int rc;
|
||||
|
||||
|
@ -1178,8 +1184,8 @@ static int fileio_srec(struct fioparms * fio,
|
|||
|
||||
#ifdef HAVE_LIBELF
|
||||
static int fileio_elf(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem,
|
||||
struct avrpart * p, int size)
|
||||
const char *filename, FILE *f, const AVRMEM *mem,
|
||||
const AVRPART *p, int size)
|
||||
{
|
||||
int rc;
|
||||
|
||||
|
@ -1203,7 +1209,7 @@ static int fileio_elf(struct fioparms * fio,
|
|||
#endif
|
||||
|
||||
static int fileio_num(struct fioparms *fio,
|
||||
char * filename, FILE * f, AVRMEM * mem, int size,
|
||||
const char *filename, FILE *f, const AVRMEM *mem, int size,
|
||||
FILEFMT fmt)
|
||||
{
|
||||
const char *prefix;
|
||||
|
@ -1282,9 +1288,7 @@ static int fileio_num(struct fioparms * fio,
|
|||
}
|
||||
|
||||
|
||||
int fileio_setparms(int op, struct fioparms * fp,
|
||||
struct avrpart * p, AVRMEM * m)
|
||||
{
|
||||
int fileio_setparms(int op, struct fioparms *fp, const AVRPART *p, const AVRMEM * m) {
|
||||
fp->op = op;
|
||||
|
||||
switch (op) {
|
||||
|
@ -1404,12 +1408,12 @@ int fileio_fmt_autodetect(const char * fname)
|
|||
|
||||
|
||||
|
||||
int fileio(int oprwv, char * filename, FILEFMT format,
|
||||
struct avrpart * p, char * memtype, int size)
|
||||
int fileio(int oprwv, const char *filename, FILEFMT format,
|
||||
const AVRPART *p, const char *memtype, int size)
|
||||
{
|
||||
int op, rc;
|
||||
FILE * f;
|
||||
char * fname;
|
||||
const char *fname;
|
||||
struct fioparms fio;
|
||||
AVRMEM * mem;
|
||||
int using_stdio;
|
||||
|
|
|
@ -579,7 +579,8 @@ const char * pinmask_to_str(const pinmask_t * const pinmask);
|
|||
|
||||
The target file will be selected at configure time. */
|
||||
|
||||
extern long serial_recv_timeout;
|
||||
extern long serial_recv_timeout; /* ms */
|
||||
|
||||
union filedescriptor
|
||||
{
|
||||
int ifd;
|
||||
|
@ -797,7 +798,6 @@ typedef struct programmer_t {
|
|||
int (*parseextparams) (const struct programmer_t *pgm, const LISTID xparams);
|
||||
void (*setup) (struct programmer_t *pgm);
|
||||
void (*teardown) (struct programmer_t *pgm);
|
||||
|
||||
// Cached r/w API for terminal reads/writes
|
||||
int (*write_byte_cached)(const struct programmer_t *pgm, const AVRPART *p, const AVRMEM *m,
|
||||
unsigned long addr, unsigned char value);
|
||||
|
@ -969,8 +969,8 @@ char * fileio_fmtstr(FILEFMT format);
|
|||
|
||||
int fileio_fmt_autodetect(const char * fname);
|
||||
|
||||
int fileio(int oprwv, char * filename, FILEFMT format,
|
||||
struct avrpart * p, char * memtype, int size);
|
||||
int fileio(int oprwv, const char *filename, FILEFMT format,
|
||||
const AVRPART *p, const char *memtype, int size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1020,10 +1020,10 @@ extern UPDATE * dup_update(UPDATE * upd);
|
|||
extern UPDATE * new_update(int op, char * memtype, int filefmt,
|
||||
char * filename);
|
||||
extern void free_update(UPDATE * upd);
|
||||
extern int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd,
|
||||
extern int do_op(const PROGRAMMER *pgm, const AVRPART *p, UPDATE *upd,
|
||||
enum updateflags flags);
|
||||
|
||||
extern int memstats(struct avrpart *p, char *memtype, int size, Filestats *fsp);
|
||||
extern int memstats(const AVRPART *p, const char *memtype, int size, Filestats *fsp);
|
||||
|
||||
// Convenience functions for printing
|
||||
const char *update_plural(int x);
|
||||
|
@ -1036,7 +1036,7 @@ int update_is_okfile(const char *fn);
|
|||
int update_is_writeable(const char *fn);
|
||||
int update_is_readable(const char *fn);
|
||||
|
||||
int update_dryrun(struct avrpart *p, UPDATE *upd);
|
||||
int update_dryrun(const AVRPART *p, UPDATE *upd);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
12
src/update.c
12
src/update.c
|
@ -188,7 +188,7 @@ void free_update(UPDATE * u)
|
|||
|
||||
|
||||
// Memory statistics considering holes after a file read returned size bytes
|
||||
int memstats(struct avrpart *p, char *memtype, int size, Filestats *fsp) {
|
||||
int memstats(const AVRPART *p, const char *memtype, int size, Filestats *fsp) {
|
||||
Filestats ret = { 0 };
|
||||
AVRMEM *mem = avr_locate_mem(p, memtype);
|
||||
|
||||
|
@ -332,7 +332,7 @@ int update_is_readable(const char *fn) {
|
|||
}
|
||||
|
||||
|
||||
static void ioerror(const char *iotype, UPDATE *upd) {
|
||||
static void ioerror(const char *iotype, const UPDATE *upd) {
|
||||
int errnocp = errno;
|
||||
|
||||
pmsg_ext_error("file %s is not %s: ", update_outname(upd->filename), iotype);
|
||||
|
@ -344,7 +344,7 @@ static void ioerror(const char *iotype, UPDATE *upd) {
|
|||
}
|
||||
|
||||
// Basic checks to reveal serious failure before programming
|
||||
int update_dryrun(struct avrpart *p, UPDATE *upd) {
|
||||
int update_dryrun(const AVRPART *p, UPDATE *upd) {
|
||||
static char **wrote;
|
||||
static int nfwritten;
|
||||
|
||||
|
@ -426,9 +426,8 @@ int update_dryrun(struct avrpart *p, UPDATE *upd) {
|
|||
}
|
||||
|
||||
|
||||
int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags flags)
|
||||
{
|
||||
struct avrpart * v;
|
||||
int do_op(const PROGRAMMER *pgm, const AVRPART *p, UPDATE *upd, enum updateflags flags) {
|
||||
AVRPART *v;
|
||||
AVRMEM *mem;
|
||||
int size;
|
||||
int rc;
|
||||
|
@ -486,6 +485,7 @@ int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags f
|
|||
pmsg_error("read from file %s failed\n", update_inname(upd->filename));
|
||||
return LIBAVRDUDE_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
size = rc;
|
||||
pmsg_info("reading input file %s for %s%s\n",
|
||||
update_inname(upd->filename), mem->desc, alias_mem_desc);
|
||||
|
|
Loading…
Reference in New Issue