tools:Fix fpgaconf input file status
* tools:Fix fpgaconf input file status
changes:
- Check for input file is valid or not
* Fix code review comments
* Fix code  review comments
* Fix code review comments
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
+#include <sys/stat.h>
#include "safe_string/safe_string.h"
@@ -389,6 +390,8 @@ int read_bitstream(char *filename, struct bitstream_info *info)
FILE *f;
long len;
int ret;
+ struct stat file_mode;
+ memset(&file_mode, 0, sizeof(file_mode));
if (!filename || !info)
return -EINVAL;
@@ -402,6 +405,16 @@ int read_bitstream(char *filename, struct bitstream_info *info)
return -1;
}
+ if (fstat(fileno(f), &file_mode) != 0) {
+ perror(filename);
+ goto out_close;
+ }
+
+ if (S_ISREG(file_mode.st_mode) == 0) {
+ fprintf(stderr, "Invalid input GBS file\n");
+ goto out_close;
+ }
+
/* get filesize */
ret = fseek(f, 0, SEEK_END);
if (ret < 0) {
