/[dynamips]/upstream/dynamips-0.2.6-RC5/bin2c.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /upstream/dynamips-0.2.6-RC5/bin2c.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Sat Oct 6 16:03:58 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.6-RC1/bin2c.c
File MIME type: text/plain
File size: 863 byte(s)
import dynamips-0.2.6-RC1

1 dpavlin 1 #include <stdio.h>
2     #include <stdlib.h>
3     #include <unistd.h>
4    
5     int main(int argc,char *argv[])
6     {
7     unsigned char buffer[8];
8     FILE *fd_in,*fd_out;
9     size_t len;
10     int i;
11    
12     if (argc != 3) {
13     fprintf(stderr,"Usage: %s <input_file> <output_file>\n",argv[0]);
14     exit(EXIT_FAILURE);
15     }
16    
17     if (!(fd_in = fopen(argv[1],"r"))) {
18     fprintf(stderr,"Unable to open file \"%s\"\n",argv[1]);
19     exit(EXIT_FAILURE);
20     }
21    
22     if (!(fd_out = fopen(argv[2],"w"))) {
23     fprintf(stderr,"Unable to create file \"%s\"\n",argv[2]);
24     exit(EXIT_FAILURE);
25     }
26    
27     while(!feof(fd_in)) {
28     len = fread(buffer,1,sizeof(buffer),fd_in);
29     if (len == 0) break;
30    
31     fprintf(fd_out," ");
32     for(i=0;i<len;i++)
33     fprintf(fd_out,"0x%2.2x, ",buffer[i]);
34    
35     fprintf(fd_out,"\n");
36     }
37    
38     fclose(fd_in);
39     fclose(fd_out);
40     return(0);
41     }

  ViewVC Help
Powered by ViewVC 1.1.26