Search
lxdream.org :: lxdream/src/loader.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/loader.c
changeset 446:def93c34c84c
prev435:7a5d71e8560b
next450:207461e79f21
author nkeynes
date Tue Oct 16 12:28:42 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Change command line handling to not require -d
file annotate diff log raw
1.1 --- a/src/loader.c Wed Oct 10 11:02:04 2007 +0000
1.2 +++ b/src/loader.c Tue Oct 16 12:28:42 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: loader.c,v 1.17 2007-10-10 11:02:04 nkeynes Exp $
1.6 + * $Id: loader.c,v 1.18 2007-10-16 12:28:42 nkeynes Exp $
1.7 *
1.8 * File loading routines, mostly for loading demos without going through the
1.9 * whole procedure of making a CD image for them.
1.10 @@ -45,13 +45,14 @@
1.11 #define CDI_V2 0x80000004
1.12 #define CDI_V3 0x80000005
1.13
1.14 -int file_load_elf_fd( int fd );
1.15 +gboolean file_load_elf_fd( int fd );
1.16
1.17
1.18 gboolean file_load_magic( const gchar *filename )
1.19 {
1.20 char buf[32];
1.21 struct stat st;
1.22 + gboolean result = TRUE;
1.23
1.24 int fd = open( filename, O_RDONLY );
1.25 if( fd == -1 ) {
1.26 @@ -90,20 +91,20 @@
1.27 } else if( memcmp( buf, "PK\x03\x04", 4 ) == 0 ) {
1.28 /* ZIP file, aka SBI file */
1.29 WARN( "SBI files not supported yet" );
1.30 + result = FALSE;
1.31 } else if( memcmp( buf, DREAMCAST_SAVE_MAGIC, 16 ) == 0 ) {
1.32 /* Save state */
1.33 - dreamcast_load_state( filename );
1.34 + result = (dreamcast_load_state( filename )==0);
1.35 } else if( buf[0] == 0x7F && buf[1] == 'E' &&
1.36 buf[2] == 'L' && buf[3] == 'F' ) {
1.37 /* ELF binary */
1.38 lseek( fd, 0, SEEK_SET );
1.39 - file_load_elf_fd( fd );
1.40 + result = file_load_elf_fd( fd );
1.41 } else {
1.42 - /* Assume raw binary */
1.43 - file_load_binary( filename );
1.44 - }
1.45 + result = FALSE;
1.46 + }
1.47 close(fd);
1.48 - return TRUE;
1.49 + return result;
1.50 }
1.51
1.52 void file_load_postload( int pc )
1.53 @@ -139,14 +140,14 @@
1.54 }
1.55 }
1.56
1.57 -int file_load_elf_fd( int fd )
1.58 +gboolean file_load_elf_fd( int fd )
1.59 {
1.60 Elf32_Ehdr head;
1.61 Elf32_Phdr phdr;
1.62 int i;
1.63
1.64 if( read( fd, &head, sizeof(head) ) != sizeof(head) )
1.65 - return -1;
1.66 + return FALSE;
1.67 if( head.e_ident[EI_CLASS] != ELFCLASS32 ||
1.68 head.e_ident[EI_DATA] != ELFDATA2LSB ||
1.69 head.e_ident[EI_VERSION] != 1 ||
1.70 @@ -154,7 +155,7 @@
1.71 head.e_machine != EM_SH ||
1.72 head.e_version != 1 ) {
1.73 ERROR( "File is not an SH4 ELF executable file" );
1.74 - return -1;
1.75 + return FALSE;
1.76 }
1.77
1.78 /* Program headers */
1.79 @@ -173,5 +174,5 @@
1.80 }
1.81
1.82 file_load_postload( head.e_entry );
1.83 - return 0;
1.84 + return TRUE;
1.85 }
.