@@ -63,7 +63,10 @@ static void cdfs_determine_sector_size(cdfs_track_t* track)
6363
6464static void cdfs_seek_track_sector (cdfs_track_t * track , unsigned int sector )
6565{
66- intfstream_seek (track -> stream , sector * track -> stream_sector_size + track -> stream_sector_header_size + track -> first_sector_offset , SEEK_SET );
66+ intfstream_seek (track -> stream ,
67+ sector * track -> stream_sector_size +
68+ track -> stream_sector_header_size +
69+ track -> first_sector_offset , SEEK_SET );
6770}
6871
6972void cdfs_seek_sector (cdfs_file_t * file , unsigned int sector )
@@ -73,21 +76,21 @@ void cdfs_seek_sector(cdfs_file_t* file, unsigned int sector)
7376 {
7477 if (sector != file -> current_sector )
7578 {
76- file -> current_sector = sector ;
79+ file -> current_sector = sector ;
7780 file -> sector_buffer_valid = 0 ;
7881 }
7982
80- file -> pos = file -> current_sector * 2048 ;
81- file -> current_sector_offset = 0 ;
83+ file -> pos = file -> current_sector * 2048 ;
84+ file -> current_sector_offset = 0 ;
8285 }
8386}
8487
8588static int cdfs_find_file (cdfs_file_t * file , const char * path )
8689{
8790 uint8_t buffer [2048 ], * tmp ;
8891 int sector , path_length ;
89-
9092 const char * slash = strrchr (path , '\\' );
93+
9194 if (slash )
9295 {
9396 /* navigate the path to the directory record for the file */
@@ -105,12 +108,13 @@ static int cdfs_find_file(cdfs_file_t* file, const char* path)
105108 {
106109 int offset ;
107110
108- /* find the cd information (always 16 frames in) */
111+ /* find the CD information (always 16 frames in) */
109112 cdfs_seek_track_sector (file -> track , 16 );
110113 intfstream_read (file -> track -> stream , buffer , sizeof (buffer ));
111114
112115 /* the directory_record starts at 156 bytes into the sector.
113- * the sector containing the root directory contents is a 3 byte value that is 2 bytes into the directory_record. */
116+ * the sector containing the root directory contents is a
117+ * 3 byte value that is 2 bytes into the directory_record. */
114118 offset = 156 + 2 ;
115119 sector = buffer [offset ] | (buffer [offset + 1 ] << 8 ) | (buffer [offset + 2 ] << 16 );
116120 }
@@ -120,21 +124,26 @@ static int cdfs_find_file(cdfs_file_t* file, const char* path)
120124 intfstream_read (file -> track -> stream , buffer , sizeof (buffer ));
121125
122126 path_length = strlen (path );
123- tmp = buffer ;
127+ tmp = buffer ;
128+
124129 while (tmp < buffer + sizeof (buffer ))
125130 {
126- /* the first byte of the record is the length of the record - if 0, we reached the end of the data */
131+ /* The first byte of the record is the length of
132+ * the record - if 0, we reached the end of the data */
127133 if (!* tmp )
128134 break ;
129135
130- /* filename is 33 bytes into the record and the format is "FILENAME;version" or "DIRECTORY" */
136+ /* filename is 33 bytes into the record and
137+ * the format is "FILENAME;version" or "DIRECTORY" */
131138 if ((tmp [33 + path_length ] == ';' || tmp [33 + path_length ] == '\0' ) &&
132139 strncasecmp ((const char * )(tmp + 33 ), path , path_length ) == 0 )
133140 {
134141 /* the file size is in bytes 10-13 of the record */
135- file -> size = tmp [10 ] | (tmp [11 ] << 8 ) | (tmp [12 ] << 16 ) | (tmp [13 ] << 24 );
142+ file -> size = tmp [10 ] | (tmp [11 ] << 8 )
143+ | (tmp [12 ] << 16 ) | (tmp [13 ] << 24 );
136144
137- /* the file contents are in the sector identified in bytes 2-4 of the record */
145+ /* the file contents are in the sector identified
146+ * in bytes 2-4 of the record */
138147 sector = tmp [2 ] | (tmp [3 ] << 8 ) | (tmp [4 ] << 16 );
139148 return sector ;
140149 }
@@ -153,15 +162,17 @@ int cdfs_open_file(cdfs_file_t* file, cdfs_track_t* track, const char* path)
153162
154163 memset (file , 0 , sizeof (* file ));
155164
156- file -> track = track ;
157-
165+ file -> track = track ;
158166 file -> current_sector = -1 ;
167+
159168 if (path )
160169 file -> first_sector = cdfs_find_file (file , path );
161170 else if (file -> track -> stream_sector_size )
162171 {
163172 file -> first_sector = 0 ;
164- file -> size = (intfstream_get_size (file -> track -> stream ) / file -> track -> stream_sector_size ) * 2048 ;
173+ file -> size = (intfstream_get_size (
174+ file -> track -> stream ) / file -> track -> stream_sector_size )
175+ * 2048 ;
165176 }
166177 else
167178 file -> first_sector = -1 ;
@@ -189,12 +200,14 @@ int64_t cdfs_read_file(cdfs_file_t* file, void* buffer, uint64_t len)
189200 {
190201 if (remaining >= len )
191202 {
192- memcpy (buffer , & file -> sector_buffer [file -> current_sector_offset ], len );
203+ memcpy (buffer ,
204+ & file -> sector_buffer [file -> current_sector_offset ], len );
193205 file -> current_sector_offset += len ;
194206 return len ;
195207 }
196208
197- memcpy (buffer , & file -> sector_buffer [file -> current_sector_offset ], remaining );
209+ memcpy (buffer ,
210+ & file -> sector_buffer [file -> current_sector_offset ], remaining );
198211 buffer = (char * )buffer + remaining ;
199212 bytes_read += remaining ;
200213 len -= remaining ;
@@ -204,11 +217,11 @@ int64_t cdfs_read_file(cdfs_file_t* file, void* buffer, uint64_t len)
204217
205218 ++ file -> current_sector ;
206219 file -> current_sector_offset = 0 ;
207- file -> sector_buffer_valid = 0 ;
220+ file -> sector_buffer_valid = 0 ;
208221 }
209222 else if (file -> current_sector < file -> first_sector )
210223 {
211- file -> current_sector = file -> first_sector ;
224+ file -> current_sector = file -> first_sector ;
212225 file -> current_sector_offset = 0 ;
213226 }
214227
@@ -217,8 +230,9 @@ int64_t cdfs_read_file(cdfs_file_t* file, void* buffer, uint64_t len)
217230 cdfs_seek_track_sector (file -> track , file -> current_sector );
218231 intfstream_read (file -> track -> stream , buffer , 2048 );
219232
220- buffer = (char * )buffer + 2048 ;
233+ buffer = (char * )buffer + 2048 ;
221234 bytes_read += 2048 ;
235+
222236 ++ file -> current_sector ;
223237
224238 len -= 2048 ;
@@ -243,7 +257,8 @@ void cdfs_close_file(cdfs_file_t* file)
243257{
244258 if (file )
245259 {
246- /* not really anything to do here, just clear out the first_sector so read() won't do anything */
260+ /* not really anything to do here, just
261+ * clear out the first_sector so read() won't do anything */
247262 file -> first_sector = -1 ;
248263 }
249264}
@@ -314,21 +329,26 @@ static void cdfs_skip_spaces(const char** ptr)
314329 ++ (* ptr );
315330}
316331
317- static cdfs_track_t * cdfs_wrap_stream (intfstream_t * stream , unsigned first_sector_offset )
332+ static cdfs_track_t * cdfs_wrap_stream (
333+ intfstream_t * stream , unsigned first_sector_offset )
318334{
319- cdfs_track_t * track ;
335+ cdfs_track_t * track = NULL ;
320336
321- if (stream == NULL )
337+ if (! stream )
322338 return NULL ;
323339
324- track = (cdfs_track_t * )calloc (1 , sizeof (* track ));
325- track -> stream = stream ;
340+ track = (cdfs_track_t * )
341+ calloc (1 , sizeof (* track ));
342+ track -> stream = stream ;
326343 track -> first_sector_offset = first_sector_offset ;
344+
327345 cdfs_determine_sector_size (track );
346+
328347 return track ;
329348}
330349
331- static cdfs_track_t * cdfs_open_cue_track (const char * path , unsigned int track_index )
350+ static cdfs_track_t * cdfs_open_cue_track (
351+ const char * path , unsigned int track_index )
332352{
333353 char * cue = NULL ;
334354 const char * line = NULL ;
@@ -442,10 +462,9 @@ static cdfs_track_t* cdfs_open_cue_track(const char* path, unsigned int track_in
442462
443463 if (found_track && index_number == 1 )
444464 {
445- if (strstr (current_track_path , "/" ) || strstr ( current_track_path , "\\" ))
446- {
465+ if ( strstr (current_track_path , "/" ) ||
466+ strstr ( current_track_path , "\\" ))
447467 strncpy (track_path , current_track_path , sizeof (track_path ));
448- }
449468 else
450469 {
451470 fill_pathname_basedir (track_path , path , sizeof (track_path ));
@@ -462,7 +481,10 @@ static cdfs_track_t* cdfs_open_cue_track(const char* path, unsigned int track_in
462481 if (string_is_empty (track_path ))
463482 return NULL ;
464483
465- track = cdfs_wrap_stream (intfstream_open_file (track_path , RETRO_VFS_FILE_ACCESS_READ , RETRO_VFS_FILE_ACCESS_HINT_NONE ), track_offset );
484+ track = cdfs_wrap_stream (intfstream_open_file (
485+ track_path , RETRO_VFS_FILE_ACCESS_READ ,
486+ RETRO_VFS_FILE_ACCESS_HINT_NONE ), track_offset );
487+
466488 if (track && track -> stream_sector_size == 0 )
467489 {
468490 track -> stream_sector_size = sector_size ;
@@ -482,11 +504,14 @@ static cdfs_track_t* cdfs_open_chd_track(const char* path, int32_t track_index)
482504 intfstream_t * intf_stream ;
483505 cdfs_track_t * track ;
484506
485- intf_stream = intfstream_open_chd_track (path , RETRO_VFS_FILE_ACCESS_READ , RETRO_VFS_FILE_ACCESS_HINT_NONE , track_index );
507+ intf_stream = intfstream_open_chd_track (path ,
508+ RETRO_VFS_FILE_ACCESS_READ , RETRO_VFS_FILE_ACCESS_HINT_NONE ,
509+ track_index );
486510 if (!intf_stream )
487511 return NULL ;
488512
489- track = cdfs_wrap_stream (intf_stream , intfstream_get_offset_to_start (intf_stream ));
513+ track = cdfs_wrap_stream (intf_stream ,
514+ intfstream_get_offset_to_start (intf_stream ));
490515
491516 if (track && track -> stream_sector_header_size == 0 )
492517 {
@@ -502,7 +527,8 @@ static cdfs_track_t* cdfs_open_chd_track(const char* path, int32_t track_index)
502527}
503528#endif
504529
505- struct cdfs_track_t * cdfs_open_track (const char * path , unsigned int track_index )
530+ struct cdfs_track_t * cdfs_open_track (const char * path ,
531+ unsigned int track_index )
506532{
507533 const char * ext = path_get_extension (path );
508534
@@ -538,8 +564,11 @@ cdfs_track_t* cdfs_open_raw_track(const char* path)
538564{
539565 const char * ext = path_get_extension (path );
540566
541- if (string_is_equal_noncase (ext , "bin" ) || string_is_equal_noncase (ext , "iso" ))
542- return cdfs_wrap_stream (intfstream_open_file (path , RETRO_VFS_FILE_ACCESS_READ , RETRO_VFS_FILE_ACCESS_HINT_NONE ), 0 );
567+ if ( string_is_equal_noncase (ext , "bin" ) ||
568+ string_is_equal_noncase (ext , "iso" ))
569+ return cdfs_wrap_stream (intfstream_open_file (path ,
570+ RETRO_VFS_FILE_ACCESS_READ ,
571+ RETRO_VFS_FILE_ACCESS_HINT_NONE ), 0 );
543572
544573 /* unsupported file type */
545574 return NULL ;
0 commit comments