Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FMIURIToPath() to import framework #137

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/FMI.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ FMI_STATIC const char* FMIValueReferencesToString(FMIInstance *instance, const F

FMI_STATIC const char* FMIValuesToString(FMIInstance *instance, size_t nvr, const void *value, FMIVariableType variableType);

FMI_STATIC FMIStatus FMIURIToPath(const char *uri, char *path, size_t pathLength);

#ifdef __cplusplus
} /* end of extern "C" { */
#endif
Expand Down
36 changes: 36 additions & 0 deletions src/FMI.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,39 @@ const char* FMIValuesToString(FMIInstance *instance, size_t nvr, const void *val

return instance->buf2;
}

FMIStatus FMIURIToPath(const char *uri, char *path, size_t pathLength) {

#ifdef _WIN32
if (PathCreateFromUrlA(uri, path, &pathLength, 0) != S_OK) {
return FMIError;
}
#else
const char *scheme1 = "file:///";
const char *scheme2 = "file:/";

strncpy(path, uri, pathLength);

if (strncmp(uri, scheme1, strlen(scheme1)) == 0) {
strncpy(path, &uri[strlen(scheme1)] - 1, pathLength);
} else if (strncmp(uri, scheme2, strlen(scheme2)) == 0) {
strncpy(path, &uri[strlen(scheme2) - 1], pathLength);
} else {
return FMIError;
}
#endif

size_t length = strlen(path);

#ifdef _WIN32
char sep = '\\';
#else
char sep = '/';
#endif

if (path[length] != sep) {
strncat(path, &sep, 1);
}

return FMIOK;
}