@@ -416,6 +416,8 @@ static void MixAudioFrames(float *framesOut, const float *framesIn, ma_uint32 fr
416
416
#if defined(RAUDIO_STANDALONE )
417
417
static bool IsFileExtension (const char * fileName , const char * ext ); // Check file extension
418
418
static const char * GetFileExtension (const char * fileName ); // Get pointer to extension for a filename string (includes the dot: .png)
419
+ static const char * GetFileName (const char * filePath ); // Get pointer to filename for a path string
420
+ static const char * GetFileNameWithoutExt (const char * filePath ); // Get filename string without extension (uses static string)
419
421
420
422
static unsigned char * LoadFileData (const char * fileName , int * dataSize ); // Load file data as byte array (read)
421
423
static bool SaveFileData (const char * fileName , void * data , int dataSize ); // Save data to file from byte array (write)
@@ -2642,6 +2644,50 @@ static const char *GetFileExtension(const char *fileName)
2642
2644
return dot ;
2643
2645
}
2644
2646
2647
+ // String pointer reverse break: returns right-most occurrence of charset in s
2648
+ static const char * strprbrk (const char * s , const char * charset )
2649
+ {
2650
+ const char * latestMatch = NULL ;
2651
+ for (; s = strpbrk (s , charset ), s != NULL ; latestMatch = s ++ ) { }
2652
+ return latestMatch ;
2653
+ }
2654
+
2655
+ // Get pointer to filename for a path string
2656
+ static const char * GetFileName (const char * filePath )
2657
+ {
2658
+ const char * fileName = NULL ;
2659
+ if (filePath != NULL ) fileName = strprbrk (filePath , "\\/" );
2660
+
2661
+ if (!fileName ) return filePath ;
2662
+
2663
+ return fileName + 1 ;
2664
+ }
2665
+
2666
+ // Get filename string without extension (uses static string)
2667
+ static const char * GetFileNameWithoutExt (const char * filePath )
2668
+ {
2669
+ #define MAX_FILENAMEWITHOUTEXT_LENGTH 256
2670
+
2671
+ static char fileName [MAX_FILENAMEWITHOUTEXT_LENGTH ] = { 0 };
2672
+ memset (fileName , 0 , MAX_FILENAMEWITHOUTEXT_LENGTH );
2673
+
2674
+ if (filePath != NULL ) strcpy (fileName , GetFileName (filePath )); // Get filename with extension
2675
+
2676
+ int size = (int )strlen (fileName ); // Get size in bytes
2677
+
2678
+ for (int i = 0 ; (i < size ) && (i < MAX_FILENAMEWITHOUTEXT_LENGTH ); i ++ )
2679
+ {
2680
+ if (fileName [i ] == '.' )
2681
+ {
2682
+ // NOTE: We break on first '.' found
2683
+ fileName [i ] = '\0' ;
2684
+ break ;
2685
+ }
2686
+ }
2687
+
2688
+ return fileName ;
2689
+ }
2690
+
2645
2691
// Load data from file into a buffer
2646
2692
static unsigned char * LoadFileData (const char * fileName , int * dataSize )
2647
2693
{
@@ -2699,9 +2745,19 @@ static bool SaveFileData(const char *fileName, void *data, int dataSize)
2699
2745
2700
2746
fclose (file );
2701
2747
}
2702
- else TRACELOG (LOG_WARNING , "FILEIO: [%s] Failed to open file" , fileName );
2748
+ else
2749
+ {
2750
+ TRACELOG (LOG_WARNING , "FILEIO: [%s] Failed to open file" , fileName );
2751
+ return false;
2752
+ }
2703
2753
}
2704
- else TRACELOG (LOG_WARNING , "FILEIO: File name provided is not valid" );
2754
+ else
2755
+ {
2756
+ TRACELOG (LOG_WARNING , "FILEIO: File name provided is not valid" );
2757
+ return false;
2758
+ }
2759
+
2760
+ return true;
2705
2761
}
2706
2762
2707
2763
// Save text data to file (write), string must be '\0' terminated
@@ -2720,9 +2776,19 @@ static bool SaveFileText(const char *fileName, char *text)
2720
2776
2721
2777
fclose (file );
2722
2778
}
2723
- else TRACELOG (LOG_WARNING , "FILEIO: [%s] Failed to open text file" , fileName );
2779
+ else
2780
+ {
2781
+ TRACELOG (LOG_WARNING , "FILEIO: [%s] Failed to open text file" , fileName );
2782
+ return false;
2783
+ }
2724
2784
}
2725
- else TRACELOG (LOG_WARNING , "FILEIO: File name provided is not valid" );
2785
+ else
2786
+ {
2787
+ TRACELOG (LOG_WARNING , "FILEIO: File name provided is not valid" );
2788
+ return false;
2789
+ }
2790
+
2791
+ return true;
2726
2792
}
2727
2793
#endif
2728
2794
0 commit comments