static void StripPath( char const * path, char * outName, size_t const outSize ) { if ( path[0] == '\0' ) { outName[0] = '\0'; return; } size_t n = OVR_strlen( path ); char const * fnameStart = NULL; for ( int i = n - 1; i >= 0; --i ) { if ( path[i] == PATH_SEPARATOR ) { fnameStart = &path[i]; break; } } if ( fnameStart != NULL ) { // this will copy 0 characters if the path separator was the last character OVR_strncpy( outName, outSize, fnameStart + 1, n - ( fnameStart - path ) ); } else { OVR_strcpy( outName, outSize, path ); } }
eVrApiEventStatus SystemActivities_GetNextPendingEvent( EventQueue * queue, char * buffer, unsigned int const bufferSize ) { if ( buffer == NULL || bufferSize == 0 ) { return VRAPI_EVENT_ERROR_INVALID_BUFFER; } if ( bufferSize < 2 ) { buffer[0] = '\0'; return VRAPI_EVENT_ERROR_INVALID_BUFFER; } if ( queue == NULL ) { return VRAPI_EVENT_ERROR_INTERNAL; } EventQueue * q = reinterpret_cast< EventQueue* >( queue ); EventData const * eventData; if ( !q->Dequeue( eventData ) ) { return VRAPI_EVENT_NOT_PENDING; } OVR_strncpy( buffer, bufferSize, static_cast< char const * >( eventData->GetData() ), eventData->GetSize() ); bool overflowed = eventData->GetSize() >= bufferSize; delete eventData; return overflowed ? VRAPI_EVENT_BUFFER_OVERFLOW : VRAPI_EVENT_PENDING; }
void ExecuteConsoleFunction( long appPtr, char const * commandStr ) const { DROIDLOG( "OvrConsole", "Received console command \"%s\"", commandStr ); char cmdName[128]; char const * parms = ""; int cmdLen = (int)strlen( commandStr ); char const * spacePtr = strstr( commandStr, " " ); if ( spacePtr != NULL && spacePtr - commandStr < cmdLen ) { parms = spacePtr + 1; OVR_strncpy( cmdName, sizeof( cmdName ), commandStr, spacePtr - commandStr ); } else { OVR_strcpy( cmdName, sizeof( cmdName ), commandStr ); } LOG( "ExecuteConsoleFunction( %s, %s )", cmdName, parms ); for ( int i = 0 ; i < ConsoleFunctions.GetSizeI(); ++i ) { LOG( "Checking console function '%s'", ConsoleFunctions[i].GetName() ); if ( OVR_stricmp( ConsoleFunctions[i].GetName(), cmdName ) == 0 ) { LOG( "Executing console function '%s'", cmdName ); ConsoleFunctions[i].Execute( reinterpret_cast< void* >( appPtr ), parms ); return; } } DROIDLOG( "OvrConsole", "ERROR: unknown console command '%s'", cmdName ); }
//============================== // ovrLexer::CopyResult void ovrLexer::CopyResult( char const * buffer, char * token, size_t const maxTokenSize ) { // NOTE: if any multi-byte characters are ever treated as quotes, this code must change if ( IsQuote( *buffer ) ) { size_t len = UTF8Util::GetLength( buffer ); const uint32_t lastChar = UTF8Util::GetCharAt( len - 1, buffer ); if ( IsQuote( lastChar ) ) { // The first char and last char are single-byte quotes, we can now just step past the first and not copy the last. char const * start = buffer + 1; len = OVR_strlen( start ); // We do not care about UTF length here since we know the quotes are a single bytes OVR_strncpy( token, maxTokenSize, start, len - 1 ); return; } } OVR_strcpy( token, maxTokenSize, buffer ); }
static void StripFileName( char const * path, char * outPath, size_t const outSize ) { size_t n = OVR_strlen( path ); char const * fnameStart = NULL; for ( int i = n - 1; i >= 0; --i ) { if ( path[i] == PATH_SEPARATOR ) { fnameStart = &path[i]; break; } } if ( fnameStart != NULL ) { OVR_strncpy( outPath, outSize, path, ( fnameStart - path ) + 1 ); } else { OVR_strcpy( outPath, outSize, path ); } }