MCPcopy Create free account
hub / github.com/csound/csound / csoundFileOpenWithType

Function csoundFileOpenWithType

Engine/envvar.c:1012–1211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1010 */
1011
1012void *csoundFileOpenWithType(CSOUND *csound, void *fd, int type,
1013 const char *name, void *param, const char *env,
1014 int csFileType, int isTemporary)
1015{
1016 CSFILE *p = NULL;
1017 char *fullName = NULL;
1018 FILE *tmp_f = NULL;
1019 SF_INFO sfinfo;
1020 int tmp_fd = -1, nbytes = (int) sizeof(CSFILE);
1021
1022
1023 /* check file type */
1024 if (UNLIKELY((unsigned int) (type - 1) >= (unsigned int) CSFILE_SND_W)) {
1025 csoundErrorMsg(csound, Str("internal error: csoundFileOpen(): "
1026 "invalid type: %d"), type);
1027 return NULL;
1028 }
1029 /* get full name and open file */
1030 if (env == NULL) {
1031#if defined(WIN32)
1032 /* To handle Widows errors in file name characters. */
1033 size_t sz = 2 * MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0);
1034 wchar_t *wfname = alloca(sz);
1035 wchar_t *wmode = 0;
1036
1037 MultiByteToWideChar(CP_UTF8, 0, name, -1, wfname, sz);
1038 sz = 2 * MultiByteToWideChar(CP_UTF8, 0, param, -1, NULL, 0);
1039 wmode = alloca(sz);
1040 MultiByteToWideChar(CP_UTF8, 0, param, -1, wmode, sz);
1041 if (type == CSFILE_STD) {
1042 tmp_f = _wfopen(wfname, wmode);
1043 if (UNLIKELY(tmp_f == NULL)) {
1044 /* csoundErrorMsg(csound, Str("csound->FileOpen2(\"%s\") failed: %s."), */
1045 /* name, strerror(errno)); */
1046 goto err_return;
1047 }
1048 fullName = (char*) name;
1049 }
1050#else
1051 if (type == CSFILE_STD) {
1052 fullName = (char*) name;
1053 tmp_f = fopen(fullName, (char*) param);
1054 if (UNLIKELY(tmp_f == NULL)) {
1055 /* csoundErrorMsg(csound, Str("csound->FileOpen2(\"%s\") failed: %s."), */
1056 /* name, strerror(errno)); */
1057 goto err_return;
1058 }
1059 }
1060#endif
1061 else {
1062 fullName = (char*) name;
1063 if (type == CSFILE_SND_R || type == CSFILE_FD_R)
1064 tmp_fd = open(fullName, RD_OPTS);
1065 else
1066 tmp_fd = open(fullName, WR_OPTS);
1067 if (tmp_fd < 0)
1068 goto err_return;
1069 }

Callers 6

createExScoreFunction · 0.85
createMIDI2Function · 0.85
createSampleFunction · 0.85
createFileFunction · 0.85
createFileaFunction · 0.85

Calls 4

csoundErrorMsgFunction · 0.85
csoundFindFile_StdFunction · 0.85
csoundFindFile_FdFunction · 0.85
sftype2csfiletypeFunction · 0.85

Tested by

no test coverage detected