Permalink
Browse files

finish write functionality. use SAUCE_ID constant.

  • Loading branch information...
1 parent 2df2561 commit ccc04f62f8494991e9e8aebaaf18696c7296c035 @bricas committed Mar 29, 2010
Showing with 31 additions and 25 deletions.
  1. +31 −25 src/libsauce.c
View
@@ -144,32 +144,38 @@ int sauce_write_file( FILE *file, sauce *record ) {
}
int _write_record( FILE *file, sauce * record ) {
- if( fseek( file, 0, SEEK_END ) == 0 ) {
- fwrite( "\032", 1, 1, file );
-
- // TODO: write comments if needed
-
- fwrite( record->id, sizeof( record->id ) - 1, 1, file );
- fwrite( record->version, sizeof( record->version ) - 1, 1, file );
- fwrite( record->title, sizeof( record->title ) - 1, 1, file );
- fwrite( record->author, sizeof( record->author ) - 1, 1, file );
- fwrite( record->group, sizeof( record->group ) - 1, 1, file );
- fwrite( record->date, sizeof( record->date ) - 1, 1, file );
- fwrite( &(record->filesize), sizeof( record->filesize ), 1, file );
- fwrite( &(record->datatype), sizeof( record->datatype ), 1, file );
- fwrite( &(record->filetype), sizeof( record->filetype ), 1, file );
- fwrite( &(record->tinfo1), sizeof( record->tinfo1 ), 1, file );
- fwrite( &(record->tinfo2), sizeof( record->tinfo2 ), 1, file );
- fwrite( &(record->tinfo3), sizeof( record->tinfo3 ), 1, file );
- fwrite( &(record->tinfo4), sizeof( record->tinfo4 ), 1, file );
- fwrite( &(record->comments), sizeof( record->comments ), 1, file );
- fwrite( &(record->flags), sizeof( record->flags), 1, file );
- fwrite( record->filler, sizeof( record->filler ) - 1, 1, file );
- return 0;
- }
- else {
+ if( fseek( file, 0, SEEK_END ) != 0 ) {
return 1;
}
+
+ fwrite( "\032", 1, 1, file );
+
+ if( record->comments != 0 ) {
+ fwrite( COMMENT_ID, 5, 1, file );
+ int i;
+ for( i = 0; i < record->comments; i++ ) {
+ fwrite( record->comment_lines[ i ], COMMENT_SIZE, 1, file );
+ }
+ }
+
+ fwrite( record->id, sizeof( record->id ) - 1, 1, file );
+ fwrite( record->version, sizeof( record->version ) - 1, 1, file );
+ fwrite( record->title, sizeof( record->title ) - 1, 1, file );
+ fwrite( record->author, sizeof( record->author ) - 1, 1, file );
+ fwrite( record->group, sizeof( record->group ) - 1, 1, file );
+ fwrite( record->date, sizeof( record->date ) - 1, 1, file );
+ fwrite( &(record->filesize), sizeof( record->filesize ), 1, file );
+ fwrite( &(record->datatype), sizeof( record->datatype ), 1, file );
+ fwrite( &(record->filetype), sizeof( record->filetype ), 1, file );
+ fwrite( &(record->tinfo1), sizeof( record->tinfo1 ), 1, file );
+ fwrite( &(record->tinfo2), sizeof( record->tinfo2 ), 1, file );
+ fwrite( &(record->tinfo3), sizeof( record->tinfo3 ), 1, file );
+ fwrite( &(record->tinfo4), sizeof( record->tinfo4 ), 1, file );
+ fwrite( &(record->comments), sizeof( record->comments ), 1, file );
+ fwrite( &(record->flags), sizeof( record->flags), 1, file );
+ fwrite( record->filler, sizeof( record->filler ) - 1, 1, file );
+
+ return 0;
}
int sauce_remove_filename( char *filename ) {
@@ -188,7 +194,7 @@ int sauce_remove_filename( char *filename ) {
int sauce_remove_file( FILE *file ) {
sauce *record = sauce_read_file( file );
- if( record == NULL || strcmp( record->id, "SAUCE" ) != 0 ) {
+ if( record == NULL || strcmp( record->id, SAUCE_ID ) != 0 ) {
return 0;
}

0 comments on commit ccc04f6

Please sign in to comment.