IEC_UINT utilAppendPath(IEC_CHAR *szDir, IEC_UINT uSize, IEC_CHAR *szAppend, IEC_BOOL bDir) { IEC_UINT uLen = (IEC_UINT)OS_STRLEN(szDir); /* old + new + zero byte + final '\' + delimiter '\' */ if (OS_STRLEN(szDir) + OS_STRLEN(szAppend) + 1 + (bDir ? 1 : 0) + (szDir[uLen] != VMM_PATH_DELI ? 1 : 0) > uSize) { RETURN(ERR_OUT_OF_MEMORY); } if (szDir[uLen - 1] != VMM_PATH_DELI) { szDir[uLen++] = VMM_PATH_DELI; szDir[uLen ] = '\0'; } OS_STRCAT(szDir, szAppend); if (bDir == TRUE) { uLen = (IEC_UINT)OS_STRLEN(szDir); szDir[uLen++] = VMM_PATH_DELI; szDir[uLen ] = '\0'; } RETURN(OK); }
/** * utilStricmp * * compare two NULL terminate strings case non sensitiv * * @return <0 => str1 < str2; 0 => str1 = str2 ; 0< => str1 > str2 */ IEC_INT utilStricmp(IEC_CHAR OS_LPTR *szStr1, IEC_CHAR OS_LPTR *szStr2) { IEC_INT iLen1 = (IEC_INT)OS_STRLEN(szStr1); IEC_INT iLen2 = (IEC_INT)OS_STRLEN(szStr2); if (iLen1 != iLen2) { return (IEC_INT)(iLen1 - iLen2); } return utilStrnicmp(szStr1, szStr2, iLen1); }
// // Make_OS_Error: C // void Make_OS_Error(REBVAL *out, int errnum) { REBCHR str[100]; OS_FORM_ERROR(errnum, str, 100); Val_Init_String(out, Copy_OS_Str(str, OS_STRLEN(str))); }
IEC_BOOL utilIs_8_3(IEC_CHAR *szPath) { IEC_UINT i; IEC_UINT uLen = (IEC_UINT)OS_STRLEN(szPath); for (i = 0; i <= uLen; i++) { IEC_UINT j; for (j = 0; szPath[i] != '\0' && szPath[i] != '.' && szPath[i] != VMM_PATH_DELI; j++) { i++; } if (j > 8) { return FALSE; } else if (szPath[i] == '\0') { return (IEC_BOOL)(j <= 8); } else if (szPath[i] == '.') { return (IEC_BOOL)(uLen - i - 1 <= 3); } } /* Should not reach this point */ return FALSE; }
/** * utilTruncCRLF * * Truncates CR/LF characters from the end of a string. */ IEC_UINT utilTruncCRLF(IEC_CHAR *szString) { IEC_UINT uLen; for (uLen = (IEC_UINT)OS_STRLEN(szString); uLen != 0 && (szString[uLen - 1] == '\r' || szString[uLen -1] == '\n'); uLen--) { szString[uLen - 1] = '\0'; } RETURN(OK); }
*/ static int Read_Dir(REBREQ *dir, REBSER *files) /* ** Provide option to get file info too. ** Provide option to prepend dir path. ** Provide option to use wildcards. ** ***********************************************************************/ { REBINT result; REBCNT len; REBSER *fname; REBSER *name; REBREQ file; RESET_TAIL(files); CLEARS(&file); // Temporary filename storage: fname = BUF_OS_STR; file.special.file.path = cast(REBCHR*, Reset_Buffer(fname, MAX_FILE_NAME)); SET_FLAG(dir->modes, RFM_DIR); dir->common.data = cast(REBYTE*, &file); while ((result = OS_DO_DEVICE(dir, RDC_READ)) == 0 && !GET_FLAG(dir->flags, RRF_DONE)) { len = OS_STRLEN(file.special.file.path); if (GET_FLAG(file.modes, RFM_DIR)) len++; name = Copy_OS_Str(file.special.file.path, len); if (GET_FLAG(file.modes, RFM_DIR)) SET_ANY_CHAR(name, name->tail-1, '/'); Val_Init_File(Alloc_Tail_Array(files), name); } if (result < 0 && dir->error != -RFE_OPEN_FAIL && ( OS_STRCHR(dir->special.file.path, '*') || OS_STRCHR(dir->special.file.path, '?') ) ) { result = 0; // no matches found, but not an error } return result; }
/** * utilAnsiToIec * * Converts an null terminated ANSI string to an IEC string. The string is * truncated if necessary. * */ IEC_UINT utilAnsiToIec(IEC_CHAR *szAnsi, IEC_STRING OS_LPTR *strIEC) { IEC_UINT uRes = OK; if (utilCheckString(szAnsi, strIEC->MaxLen)) { strIEC->CurLen = (IEC_STRLEN)OS_STRLEN(szAnsi); } else { strIEC->CurLen = strIEC->MaxLen; uRes = WRN_TRUNCATED; } OS_MEMCPY(strIEC->Contents, szAnsi, strIEC->CurLen); return uRes; }
IEC_UINT utilCreateDir(IEC_CHAR *pBuffer, IEC_UINT uLen, IEC_UINT (* fpGetDir) (IEC_CHAR *, IEC_UINT), IEC_CHAR *szDir, IEC_CHAR *szFile) { IEC_UINT uDummy; IEC_UINT uRes = utilCreatePath(pBuffer, uLen, fpGetDir, szDir, szFile); if (uRes != OK) { RETURN(OK); } uDummy = (IEC_UINT)(OS_STRLEN(pBuffer)); pBuffer[uDummy] = VMM_PATH_DELI; pBuffer[uDummy + 1] = '\0'; uRes = xxxCreateDir(pBuffer, TRUE, DIR_MODE_WRITE); RETURN(uRes); }