Mike,
It seems Windows doesn't like 'e' for fopen. So I came up this patch
to solve this issue. You are more familiar with fopen. Do you think
this patch is a good idea?
Jie
* src/tap/detect.c (find_record): Use FOPEN_RB or FOPEN_WB for mode in fopen.
* src/tap/cable/gpio.c (gpio_export): Likewise.
(gpio_direction): Likewise.
* src/tap/cable/ice100.c (ice_read_hex_file): Likewise.
* src/bsdl/bsdl.c (urj_bsdl_read_file): Likewise.
* src/bsdl/vhdl_flex.l (urj_vhdl_flex_switch_file): Likewise.
* src/global/parse.c (urj_parse_file): Likewise.
* src/cmd/cmd_bfin.c (cmd_bfin_run): Likewise.
* src/cmd/cmd_flashmem.c (cmd_flashmem_run): Likewise.
* src/cmd/cmd_pld.c (cmd_pld_run): Likewise.
* src/cmd/cmd_writemem.c (cmd_writemem_run): Likewise.
* src/cmd/cmd_svf.c (cmd_svf_run): Likewise.
* src/cmd/cmd_readmem.c (cmd_readmem_run): Likewise.
* src/apps/bsdl2jtag/bsdl2jtag.c (main): Likewise.
* sysdep.h (FOPEN_RB, FOPEN_WB): Define for GLIBC >= 2.7.
Index: src/tap/detect.c
===================================================================
--- src/tap/detect.c (revision 1970)
+++ src/tap/detect.c (working copy)
@@ -59,7 +59,7 @@ find_record (char *filename, urj_tap_reg
urj_tap_register_t *tr;
int r = 0;
- file = fopen (filename, "rb");
+ file = fopen (filename, FOPEN_RB);
if (!file)
{
urj_log (URJ_LOG_LEVEL_ERROR, _("Unable to open file '%s'\n"), filename);
Index: src/tap/cable/gpio.c
===================================================================
--- src/tap/cable/gpio.c (revision 1970)
+++ src/tap/cable/gpio.c (working copy)
@@ -69,7 +69,7 @@ static int gpio_export (unsigned int gpi
else
fname = GPIO_UNEXPORT_PATH;
- fp = fopen (fname, "w");
+ fp = fopen (fname, FOPEN_WB);
if (!fp)
{
urj_warning (_("%s: cannot open to (un)export GPIO %u\n"), fname, gpio);
@@ -92,7 +92,7 @@ static int gpio_direction (unsigned int
"%sgpio%u/direction", GPIO_PATH, gpio);
fname[sizeof (fname) - 1] = '\0';
- fp = fopen (fname, "w");
+ fp = fopen (fname, FOPEN_WB);
if (!fp)
{
urj_warning (_("%s: cannot open to set direction\n"), fname);
Index: src/tap/cable/ice100.c
===================================================================
--- src/tap/cable/ice100.c (revision 1970)
+++ src/tap/cable/ice100.c (working copy)
@@ -429,7 +429,7 @@ ice_read_hex_file (const char *filename,
struct flash_block *last_flash_block = NULL, *q;
int base_address = 0;
- hex_file = fopen (filename, "rbe");
+ hex_file = fopen (filename, FOPEN_RB);
if (!hex_file)
{
urj_error_IO_set (_("Unable to open file `%s'"), filename);
Index: src/bsdl/bsdl.c
===================================================================
--- src/bsdl/bsdl.c (revision 1970)
+++ src/bsdl/bsdl.c (working copy)
@@ -112,7 +112,7 @@ urj_bsdl_read_file (urj_chain_t *chain,
jtag_ctrl.part = NULL;
}
- BSDL_File = fopen (BSDL_File_Name, "rb");
+ BSDL_File = fopen (BSDL_File_Name, FOPEN_RB);
urj_bsdl_msg (proc_mode, _("Reading file '%s'\n"), BSDL_File_Name);
Index: src/bsdl/vhdl_flex.l
===================================================================
--- src/bsdl/vhdl_flex.l (revision 1970)
+++ src/bsdl/vhdl_flex.l (working copy)
@@ -123,6 +123,11 @@ LEGAL NOTICES:
%{
/* Begin lex input specifications */
+#include <sysdep.h>
+/* Undef TRUE and FALSE to avoid redefinition error
+ when compiling for Windows host. */
+#undef TRUE
+#undef FALSE
#include <stdlib.h>
#include <ctype.h>
@@ -506,7 +511,7 @@ urj_vhdl_flex_switch_file (yyscan_t scan
extra = yyget_extra (scanner);
/* file in current directory has precedence */
- f = fopen (filename, "rb");
+ f = fopen (filename, FOPEN_RB);
if (!f)
{
const char *db_path = urj_get_data_dir ();
@@ -523,7 +528,7 @@ urj_vhdl_flex_switch_file (yyscan_t scan
strcat (db_file, "bsdl");
strcat (db_file, "/");
strcat (db_file, filename);
- f = fopen (db_file, "rb");
+ f = fopen (db_file, FOPEN_RB);
if (!f)
urj_bsdl_ftl_set (extra->proc_mode, URJ_ERROR_IO,
Index: src/global/parse.c
===================================================================
--- src/global/parse.c (revision 1971)
+++ src/global/parse.c (working copy)
@@ -225,7 +225,7 @@ urj_parse_file (urj_chain_t *chain, cons
FILE *f;
int go;
- f = fopen (filename, "rb");
+ f = fopen (filename, FOPEN_RB);
if (!f)
{
urj_error_IO_set ("Cannot open file '%s' to parse", filename);
Index: src/cmd/cmd_bfin.c
===================================================================
--- src/cmd/cmd_bfin.c (revision 1971)
+++ src/cmd/cmd_bfin.c (working copy)
@@ -350,7 +350,7 @@ cmd_bfin_run (urj_chain_t *chain, char *
}
/* Read the binary blob from the toolchain */
- fp = fopen (tmpfile, "rb");
+ fp = fopen (tmpfile, FOPEN_RB);
if (fp == NULL)
goto execute_cleanup;
Index: src/cmd/cmd_flashmem.c
===================================================================
--- src/cmd/cmd_flashmem.c (revision 1970)
+++ src/cmd/cmd_flashmem.c (working copy)
@@ -70,7 +70,7 @@ cmd_flashmem_run (urj_chain_t *chain, ch
else
noverify = 0;
- f = fopen (params[2], "rb");
+ f = fopen (params[2], FOPEN_RB);
if (!f)
{
urj_error_IO_set (_("Unable to open file `%s'"), params[2]);
Index: src/cmd/cmd_pld.c
===================================================================
--- src/cmd/cmd_pld.c (revision 1970)
+++ src/cmd/cmd_pld.c (working copy)
@@ -66,7 +66,7 @@ cmd_pld_run (urj_chain_t *chain, char *p
return URJ_STATUS_FAIL;
}
- if ((pld_file = fopen (params[2], "rb")) != NULL)
+ if ((pld_file = fopen (params[2], FOPEN_RB)) != NULL)
{
result = urj_pld_configure (chain, pld_file);
fclose (pld_file);
Index: src/cmd/cmd_writemem.c
===================================================================
--- src/cmd/cmd_writemem.c (revision 1970)
+++ src/cmd/cmd_writemem.c (working copy)
@@ -60,7 +60,7 @@ cmd_writemem_run (urj_chain_t *chain, ch
|| urj_cmd_get_number (params[2], &len) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
- f = fopen (params[3], "rb");
+ f = fopen (params[3], FOPEN_RB);
if (!f)
{
urj_error_IO_set (_("Unable to open file `%s'"), params[3]);
Index: src/cmd/cmd_svf.c
===================================================================
--- src/cmd/cmd_svf.c (revision 1970)
+++ src/cmd/cmd_svf.c (working copy)
@@ -78,7 +78,7 @@ cmd_svf_run (urj_chain_t *chain, char *p
if (print_progress)
urj_log_state.level = URJ_LOG_LEVEL_DETAIL;
- if ((SVF_FILE = fopen (params[1], "rb")) != NULL)
+ if ((SVF_FILE = fopen (params[1], FOPEN_RB)) != NULL)
{
result = urj_svf_run (chain, SVF_FILE, stop, ref_freq);
Index: src/cmd/cmd_readmem.c
===================================================================
--- src/cmd/cmd_readmem.c (revision 1970)
+++ src/cmd/cmd_readmem.c (working copy)
@@ -62,7 +62,7 @@ cmd_readmem_run (urj_chain_t *chain, cha
|| urj_cmd_get_number (params[2], &len) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
- f = fopen (params[3], "wb");
+ f = fopen (params[3], FOPEN_WB);
if (!f)
{
urj_error_IO_set (_("Unable to create file `%s'"), params[3]);
Index: src/apps/bsdl2jtag/bsdl2jtag.c
===================================================================
--- src/apps/bsdl2jtag/bsdl2jtag.c (revision 1970)
+++ src/apps/bsdl2jtag/bsdl2jtag.c (working copy)
@@ -22,8 +22,9 @@
*
*/
-#include <stdio.h>
+#include <sysdep.h>
+#include <stdio.h>
#include <urjtag/chain.h>
#include <urjtag/log.h>
@@ -79,7 +80,7 @@ main (int argc, char *const argv[])
return 1;
}
- jtag_file = fopen (argv[2], "wb");
+ jtag_file = fopen (argv[2], FOPEN_WB);
if (jtag_file == NULL)
{
printf ("Error: Can't open '%s' in write mode.\n", argv[2]);
Index: sysdep.h
===================================================================
--- sysdep.h (revision 1971)
+++ sysdep.h (working copy)
@@ -87,4 +87,14 @@ extern ssize_t getline(char **line, size
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+#if defined(__GLIBC__) \
+ && (__GLIBC__ > 2 \
+ || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
+#define FOPEN_RB "rbe"
+#define FOPEN_WB "wbe"
+#else
+#define FOPEN_RB "rb"
+#define FOPEN_WB "wb"
+#endif
+
#endif /* SYSDEP_H */
------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development