fx2lafw, sysclk-lwla: Avoid g_stat()

It turns out that g_stat() breaks apart when using 64 bit stat on
32-bit systems. Since the actual type of GStatBuf is decided when
glib/gstdio.h is included, it is thus possible for GLib itself to
be compiled with a different type than user code.

Ouch. Unfortunately going back to plain stat() also means that we
lose Unicode filename support on Windows.
This commit is contained in:
Daniel Elstner 2015-09-16 23:33:45 +02:00
parent eb2373f167
commit 2a09aac268
2 changed files with 5 additions and 4 deletions

View File

@ -39,7 +39,7 @@ int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi,
const char *filename) const char *filename)
{ {
FILE *fw; FILE *fw;
GStatBuf st; struct stat st;
struct sr_usb_dev_inst *usb; struct sr_usb_dev_inst *usb;
int chunksize, result, ret; int chunksize, result, ret;
unsigned char *buf; unsigned char *buf;
@ -49,7 +49,7 @@ int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi,
sr_dbg("Uploading FPGA firmware at %s.", filename); sr_dbg("Uploading FPGA firmware at %s.", filename);
usb = sdi->conn; usb = sdi->conn;
if (g_stat(filename, &st) < 0) { if (stat(filename, &st) < 0) {
sr_err("Unable to upload FPGA firmware: %s", g_strerror(errno)); sr_err("Unable to upload FPGA firmware: %s", g_strerror(errno));
return SR_ERR; return SR_ERR;
} }

View File

@ -19,6 +19,7 @@
#include <config.h> #include <config.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <libsigrok/libsigrok.h> #include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
@ -33,13 +34,13 @@
*/ */
static unsigned char *load_bitstream_file(const char *filename, int *length_p) static unsigned char *load_bitstream_file(const char *filename, int *length_p)
{ {
GStatBuf statbuf; struct stat statbuf;
FILE *file; FILE *file;
unsigned char *stream; unsigned char *stream;
size_t length, count; size_t length, count;
/* Retrieve and validate the file size. */ /* Retrieve and validate the file size. */
if (g_stat(filename, &statbuf) < 0) { if (stat(filename, &statbuf) < 0) {
sr_err("Failed to access bitstream file: %s.", sr_err("Failed to access bitstream file: %s.",
g_strerror(errno)); g_strerror(errno));
return NULL; return NULL;