Skip to content

Commit

Permalink
port for bigendian arch
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyongzheng committed Aug 15, 2012
1 parent 61c9528 commit 9f07279
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions gimgunlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ struct patch_struct *prepend_patch (struct patch_struct *patch_list, unsigned lo
return new_patch;
}

int read_byte_at (FILE *fp, unsigned long offset)
unsigned int read_byte_at (FILE *fp, unsigned long offset)
{
int c;
if (fseek(fp, offset, SEEK_SET)) {
perror(NULL);
exit(1);
}
return getc(fp);
c = getc(fp);
if (c == EOF)
errexit("Unexpected EOF\n");
return c;
}

int read_2byte_at (FILE *fp, unsigned long offset)
unsigned int read_2byte_at (FILE *fp, unsigned long offset)
{
unsigned char buff[2];
if (fseek(fp, offset, SEEK_SET)) {
Expand All @@ -85,18 +89,18 @@ int read_2byte_at (FILE *fp, unsigned long offset)
return (buff[1] << 8) | buff[0];
}

unsigned int read_4byte_at (FILE *fp, unsigned long offset) //FIXME: doesn't work on bigendian
unsigned int read_4byte_at (FILE *fp, unsigned long offset)
{
unsigned int n = 0;
unsigned char buff[4];
if (fseek(fp, offset, SEEK_SET)) {
perror(NULL);
exit(1);
}
if (fread(&n, 4, 1, fp) != 1) {
if (fread(&buff, 4, 1, fp) != 1) {
perror(NULL);
exit(1);
}
return n;
return (buff[3] << 24) | (buff[2] << 16) | (buff[1] << 8) | buff[0];
}

void read_bytes_at (FILE *fp, unsigned long offset, unsigned char *buffer, int size)
Expand Down

0 comments on commit 9f07279

Please sign in to comment.