JsTTDStreamHandle CALLBACK Helpers::TTCreateStreamCallback(size_t uriLength, const char* uri, size_t asciiNameLength, const char* asciiName, bool read, bool write) { AssertMsg((read | write) & (!read | !write), "Read/Write streams not supported yet -- defaulting to read only"); if(uriLength + asciiNameLength + 1 > MAX_URI_LENGTH) { wprintf(_u("We assume bounded MAX_URI_LENGTH for simplicity.")); exit(1); } char path[MAX_URI_LENGTH]; memset(path, 0, MAX_URI_LENGTH); memcpy_s(path, MAX_URI_LENGTH, uri, uriLength); memcpy_s(path + uriLength, MAX_URI_LENGTH - uriLength, asciiName, asciiNameLength); JsTTDStreamHandle res = TTDHostOpen(uriLength + asciiNameLength, path, write); if(res == nullptr) { fprintf(stderr, "Failed to open file: %s\n", path); } Helpers::TTReportLastIOErrorAsNeeded(res != nullptr, "Failed File Open"); return res; }
JsTTDStreamHandle CALLBACK Helpers::TTCreateStreamCallback(size_t uriByteLength, const byte* uriBytes, const char* asciiResourceName, bool read, bool write) { AssertMsg((read | write) & (!read | !write), "Read/Write streams not supported yet -- defaulting to read only"); void* res = nullptr; TTDHostCharType path[MAX_PATH]; TTDHostInitFromUriBytes(path, uriBytes, uriByteLength); TTDHostAppendAscii(path, asciiResourceName); res = TTDHostOpen(path, write); if(res == nullptr) { #if _WIN32 fwprintf(stderr, _u("Failed to open file: %ls\n"), path); #else fprintf(stderr, "Failed to open file: %s\n", path); #endif } Helpers::TTReportLastIOErrorAsNeeded(res != nullptr, "Failed File Open"); return res; }