Skip to content

Commit

Permalink
Revert "Revert "fix compilation for MSVC""
Browse files Browse the repository at this point in the history
This reverts commit 508acfe.
  • Loading branch information
slyshykO committed Aug 13, 2021
1 parent 508acfe commit e96698d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ if (STLINK_HAVE_UNISTD_H)
add_definitions(-DSTLINK_HAVE_UNISTD_H)
endif ()

CHECK_INCLUDE_FILE(dirent.h STLINK_HAVE_DIRENT_H)
if (STLINK_HAVE_DIRENT_H)
add_definitions(-DSTLINK_HAVE_DIRENT_H)
endif ()

if (MSVC)
# Use string.h rather than strings.h and disable annoying warnings
add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710)
Expand Down
2 changes: 1 addition & 1 deletion src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ int stlink_chip_id(stlink_t *sl, uint32_t *chip_id) {

if (ret || !(*chip_id)) {
*chip_id = 0;
ret = ret?:-1;
ret = ret?ret:-1;
ELOG("Could not find chip id!\n");
} else {
*chip_id = (*chip_id) & 0xfff;
Expand Down
45 changes: 40 additions & 5 deletions src/stlink-lib/chipid.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stlink.h>
#include "chipid.h"

#include <dirent.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
Expand Down Expand Up @@ -962,7 +961,7 @@ struct stlink_chipid_params *stlink_chipid_get_params(uint32_t chipid) {
// fprintf (stderr, "getparams: %x\n", chipid);
for (params = devicelist ; params != NULL ; params = params -> next)
if (params->chip_id == chipid) break;

p2 = stlink_chipid_get_params_old(chipid);

#if 1
Expand Down Expand Up @@ -1061,7 +1060,7 @@ void dump_chips (void)
struct stlink_chipid_params *ts;
char *p, buf[100];
FILE *fp;

for (size_t n = 0; n < STLINK_ARRAY_SIZE(devices); n++) {
ts = &devices[n];

Expand All @@ -1086,7 +1085,9 @@ void dump_chips (void)
}
}

void init_chipids(char *dir_to_scan)
#if defined(STLINK_HAVE_DIRENT_H)
#include <dirent.h>
void init_chipids(char *dir_to_scan)
{
DIR *d;
size_t nl; // namelen
Expand Down Expand Up @@ -1121,11 +1122,45 @@ void init_chipids(char *dir_to_scan)
dump_a_chip (stderr, op);
fprintf (stderr, "---------- new ------------\n");
dump_a_chip (stderr, p);

}
}
#endif
}
#endif //STLINK_HAVE_DIRENT_H

#if defined(_WIN32) && !defined(STLINK_HAVE_DIRENT_H)
#include <fileapi.h>
#include <strsafe.h>
void init_chipids(char *dir_to_scan)
{
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAA ffd;
char file_pattern[MAX_PATH] = {0};
char filepath[MAX_PATH] = {0};
StringCchCopyA(file_pattern, STLINK_ARRAY_SIZE(file_pattern), dir_to_scan);
if (FAILED(StringCchCatA(file_pattern, STLINK_ARRAY_SIZE(file_pattern), "\\*.chip"))) {
ELOG("Path to chips's dir too long.\n");
return;
};
hFind = FindFirstFileA(file_pattern, &ffd);
if (INVALID_HANDLE_VALUE == hFind){
ELOG("Can't find any chip description file in %s.\n", file_pattern);
return;
}

do {
memset(filepath, 0, STLINK_ARRAY_SIZE(filepath));
StringCchCopyA(filepath, STLINK_ARRAY_SIZE(filepath), dir_to_scan);
StringCchCatA(filepath, STLINK_ARRAY_SIZE(file_pattern), "\\");
StringCchCatA(filepath, STLINK_ARRAY_SIZE(file_pattern), ffd.cFileName);
process_chipfile(filepath);
} while(FindNextFileA(hFind, &ffd) != 0);

FindClose(hFind);
}
#endif //defined(_WIN32) && !defined(STLINK_HAVE_DIRENT_H)




0 comments on commit e96698d

Please sign in to comment.