When unsetting the proxy in the settings dialog unset the global proxy too. Update...
[Rockbox.git] / tools / gigabeat.c
blobf4d64ea511fd5599dcf4de22414bd7fd5855a41a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Christian Hack
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <stdio.h>
21 #include <stdlib.h>
23 static FILE * openinfile( const char * filename )
25 FILE * F = fopen( filename, "rb" );
26 if( F == NULL )
28 fprintf( stderr, "Couldn't open input file %s\n", filename );
29 perror( "Error was " );
30 exit( -1 );
32 return F;
35 static FILE * openoutfile( const char * filename )
37 FILE * F = fopen( filename, "wb" );
38 if( F == NULL )
40 fprintf( stderr, "Couldn't open output file %s\n", filename );
41 perror( "Error was " );
42 exit( -1 );
44 return F;
47 int gigabeat_code(char *infile, char *outfile)
49 FILE *in, *out;
50 unsigned long size = 0;
51 unsigned long bytes_read;
52 unsigned char buf[4];
53 unsigned long data;
54 unsigned long key = 0x19751217;
56 in = openinfile(infile);
57 out = openoutfile(outfile);
59 while (!feof(in)) {
60 bytes_read = fread(buf, 1, 4, in);
62 /* Read in little-endian */
63 data = le2int(buf);
65 data = data ^ key;
67 key = key + (key << 1);
68 key = key + 0x19751217;
70 size += bytes_read;
72 /* Write out little-endian */
73 int2le(data, buf);
75 fwrite(buf, 1, bytes_read, out);
78 fprintf(stderr, "File processed successfully\n" );
80 fclose(in);
81 fclose(out);
82 return(0);