Unbreak using stdin/stdout for file input / output.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@324 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
bdean 2003-05-07 00:14:03 +00:00
parent ffb2be1eda
commit 5280d185be
1 changed files with 20 additions and 6 deletions

View File

@ -937,6 +937,7 @@ int fileio(int op, char * filename, FILEFMT format,
struct fioparms fio; struct fioparms fio;
int i; int i;
AVRMEM * mem; AVRMEM * mem;
int using_stdio;
mem = avr_locate_mem(p, memtype); mem = avr_locate_mem(p, memtype);
if (mem == NULL) { if (mem == NULL) {
@ -977,6 +978,8 @@ int fileio(int op, char * filename, FILEFMT format,
} }
} }
using_stdio = 0;
if (strcmp(filename, "-")==0) { if (strcmp(filename, "-")==0) {
if (fio.op == FIO_READ) { if (fio.op == FIO_READ) {
fname = "<stdin>"; fname = "<stdin>";
@ -986,6 +989,7 @@ int fileio(int op, char * filename, FILEFMT format,
fname = "<stdout>"; fname = "<stdout>";
f = stdout; f = stdout;
} }
using_stdio = 1;
} }
else { else {
fname = filename; fname = filename;
@ -993,6 +997,14 @@ int fileio(int op, char * filename, FILEFMT format,
} }
if (format == FMT_AUTO) { if (format == FMT_AUTO) {
if (using_stdio) {
fprintf(stderr,
"%s: can't auto detect file format when using stdin/out.\n"
" Please specify a file format using the -f option and try again.\n",
progname);
exit(1);
}
format = fmt_autodetect(fname); format = fmt_autodetect(fname);
if (format < 0) { if (format < 0) {
fprintf(stderr, fprintf(stderr,
@ -1006,12 +1018,14 @@ int fileio(int op, char * filename, FILEFMT format,
} }
if (format != FMT_IMM) { if (format != FMT_IMM) {
fname = filename; if (!using_stdio) {
f = fopen(fname, fio.mode); fname = filename;
if (f == NULL) { f = fopen(fname, fio.mode);
fprintf(stderr, "%s: can't open %s file %s: %s\n", if (f == NULL) {
progname, fio.iodesc, fname, strerror(errno)); fprintf(stderr, "%s: can't open %s file %s: %s\n",
return -1; progname, fio.iodesc, fname, strerror(errno));
return -1;
}
} }
} }