MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / AllocAndCopyFilePath

Function AllocAndCopyFilePath

extern/nfd/nfd_portal.cpp:1007–1027  ·  view source on GitHub ↗

If fileUri starts with "file://", strips that prefix and URI-decodes the remaining part to a new buffer, and make outPath point to it, and returns NFD_OKAY. Otherwise, does not modify outPath and returns NFD_ERROR (with the correct error set)

Source from the content-addressed store, hash-verified

1005// buffer, and make outPath point to it, and returns NFD_OKAY. Otherwise, does not modify outPath
1006// and returns NFD_ERROR (with the correct error set)
1007nfdresult_t AllocAndCopyFilePath(const char* fileUri, char*& outPath) {
1008 const char* prefix_begin = FILE_URI_PREFIX;
1009 const char* const prefix_end = FILE_URI_PREFIX + FILE_URI_PREFIX_LEN;
1010 for (; prefix_begin != prefix_end; ++prefix_begin, ++fileUri) {
1011 if (*prefix_begin != *fileUri) {
1012 NFDi_SetError("D-Bus freedesktop portal returned a URI that is not a file URI.");
1013 return NFD_ERROR;
1014 }
1015 }
1016 size_t decoded_len;
1017 const char* file_uri_end;
1018 if (!TryUriDecodeLen(fileUri, decoded_len, file_uri_end)) {
1019 NFDi_SetError("D-Bus freedesktop portal returned a malformed URI.");
1020 return NFD_ERROR;
1021 }
1022 char* const path_without_prefix = NFDi_Malloc<char>(decoded_len + 1);
1023 char* const out_end = UriDecodeUnchecked(fileUri, file_uri_end, path_without_prefix);
1024 *out_end = '\0';
1025 outPath = path_without_prefix;
1026 return NFD_OKAY;
1027}
1028
1029#ifdef NFD_APPEND_EXTENSION
1030bool TryGetValidExtension(const char* extn,

Callers 5

NFD_OpenDialogNFunction · 0.85
NFD_SaveDialogNFunction · 0.85
NFD_PickFolderNFunction · 0.85
NFD_PathSet_GetPathNFunction · 0.85
NFD_PathSet_EnumNextNFunction · 0.85

Calls 3

TryUriDecodeLenFunction · 0.85
UriDecodeUncheckedFunction · 0.85
NFDi_SetErrorFunction · 0.70

Tested by

no test coverage detected