1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
--- a/src/nemesis-fileio.c
+++ b/src/nemesis-fileio.c
@@ -63,7 +63,7 @@
fp = stdin;
fd = fileno(fp);
}
- else if ((fd = open(file, O_RDONLY)) < 0)
+ else if ((fp = fopen(file, "rb")) < 0)
{
#if !defined(WIN32)
fprintf(stderr, "ERROR: Unable to open %s file: %s. %s\n",
@@ -82,8 +82,12 @@
return -1;
}
+#ifdef DEBUG
+ printf("DEBUG: trying to read max %u bytes from %s\n", maxsize, file);
+#endif
+
/* read() can return negative values on successful reads, test for -1 */
- if ((bytesread = read(fd, (void *)memory, maxsize)) == -1)
+ if ((bytesread = fread((void *)memory, 1, maxsize, fp)) == -1)
{
#if !defined(WIN32)
fprintf(stderr, "ERROR: Unable to read %s file: %s. %s\n",
@@ -106,6 +110,11 @@
if (strncmp(file, "-", 1))
close(fd);
}
+
+#ifdef DEBUG
+ printf("DEBUG: bytes read from %s: %u.\n", file, bytesread);
+#endif
+
return bytesread;
}
|