summaryrefslogtreecommitdiff
path: root/ndisasm.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2002-04-30 20:53:55 +0000
committerH. Peter Anvin <hpa@zytor.com>2002-04-30 20:53:55 +0000
commiteba20a73f2b3396f617747e789e35a679eb09606 (patch)
tree2a1b5e2652e39022a1d6ff7a36a630041edad1b6 /ndisasm.c
parent87bc61964cf5d2cc2e322883d6f927a43fb53af3 (diff)
downloadnasm-eba20a73f2b3396f617747e789e35a679eb09606.tar.gz
nasm-eba20a73f2b3396f617747e789e35a679eb09606.tar.bz2
nasm-eba20a73f2b3396f617747e789e35a679eb09606.zip
NASM 0.98p3
Diffstat (limited to 'ndisasm.c')
-rw-r--r--ndisasm.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/ndisasm.c b/ndisasm.c
index 90639e9..a07a278 100644
--- a/ndisasm.c
+++ b/ndisasm.c
@@ -33,7 +33,8 @@ static const char *help =
static void output_ins (unsigned long, unsigned char *, int, char *);
static void skip (unsigned long dist, FILE *fp);
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
unsigned char buffer[INSN_MAX * 2], *p, *q;
char outbuf[256];
char *pname = *argv;
@@ -52,7 +53,7 @@ int main(int argc, char **argv) {
while (--argc) {
char *v, *vv, *p = *++argv;
- if (*p == '-') {
+ if (*p == '-' && p[1]) {
p++;
while (*p) switch (tolower(*p)) {
case 'a': /* auto or intelligent sync */
@@ -170,12 +171,16 @@ int main(int argc, char **argv) {
return 0;
}
- fp = fopen(filename, "rb");
- if (!fp) {
- fprintf(stderr, "%s: unable to open `%s': %s\n",
- pname, filename, strerror(errno));
- return 1;
- }
+ if (strcmp(filename, "-")) {
+ fp = fopen(filename, "rb");
+ if (!fp) {
+ fprintf(stderr, "%s: unable to open `%s': %s\n",
+ pname, filename, strerror(errno));
+ return 1;
+ }
+ } else
+ fp = stdin;
+
if (initskip > 0)
skip (initskip, fp);
@@ -191,9 +196,12 @@ int main(int argc, char **argv) {
unsigned long to_read = buffer+sizeof(buffer)-p;
if (to_read > nextsync-offset-(p-q))
to_read = nextsync-offset-(p-q);
- lenread = fread (p, 1, to_read, fp);
- if (lenread == 0)
- eof = TRUE; /* help along systems with bad feof */
+ if (to_read) {
+ lenread = fread (p, 1, to_read, fp);
+ if (lenread == 0)
+ eof = TRUE; /* help along systems with bad feof */
+ } else
+ lenread = 0;
p += lenread;
if (offset == nextsync) {
if (synclen) {
@@ -222,12 +230,16 @@ int main(int argc, char **argv) {
q = buffer;
}
} while (lenread > 0 || !(eof || feof(fp)));
- fclose (fp);
+
+ if (fp != stdin)
+ fclose (fp);
+
return 0;
}
static void output_ins (unsigned long offset, unsigned char *data,
- int datalen, char *insn) {
+ int datalen, char *insn)
+{
int bytes;
printf("%08lX ", offset);
@@ -256,7 +268,8 @@ static void output_ins (unsigned long offset, unsigned char *data,
* Skip a certain amount of data in a file, either by seeking if
* possible, or if that fails then by reading and discarding.
*/
-static void skip (unsigned long dist, FILE *fp) {
+static void skip (unsigned long dist, FILE *fp)
+{
char buffer[256]; /* should fit on most stacks :-) */
/*