Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2007, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009-2010, The Linux Foundation. All rights reserved. |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google, Inc. nor the names of its contributors |
| 17 | * may be used to endorse or promote products derived from this |
| 18 | * software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | */ |
| 33 | |
| 34 | #include <stdio.h> |
| 35 | #include <stdlib.h> |
| 36 | #include <unistd.h> |
| 37 | #include <fcntl.h> |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 38 | #include <string.h> |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 39 | |
| 40 | #include <sys/stat.h> |
| 41 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 42 | int print_usage() |
| 43 | { |
| 44 | fprintf(stderr, "usage: mkheader <bin> <hdr> <none|unified-boot>\n"); |
| 45 | fprintf(stderr, |
| 46 | " mkheader <bin> <hdr> <unsecure-boot> <outbin>\n"); |
| 47 | fprintf(stderr, |
| 48 | " mkheader <bin> <hdr> <secure-boot> <outbin> <maxsize>\n"); |
| 49 | fprintf(stderr, |
| 50 | " mkheader <bin> <hdr> <secure-boot> <outbin> <maxsize> <certchain> <files...>\n\n"); |
| 51 | fprintf(stderr, "bin: Input raw appsbl binary\n"); |
| 52 | fprintf(stderr, |
| 53 | "hdr: Output of appsbl header location\n"); |
| 54 | fprintf(stderr, |
| 55 | "outbin: Output of the signed or unsigned apps boot location\n"); |
| 56 | fprintf(stderr, |
| 57 | "maxsize: Maximum size for certificate chain\n"); |
| 58 | fprintf(stderr, |
| 59 | "certchain: Output of the certchain location\n"); |
| 60 | fprintf(stderr, |
| 61 | "files: Input format <bin signature> <certifcate file(s) for certificate chain>...\n"); |
| 62 | fprintf(stderr, |
| 63 | "certificate chain: Files will be concatenated in order to create the certificate chain\n\n"); |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 64 | return -1; |
| 65 | } |
| 66 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 67 | int cat(FILE * in, FILE * out, unsigned size, unsigned buff_size) |
| 68 | { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 69 | unsigned bytes_left = size; |
| 70 | char buf[buff_size]; |
| 71 | int ret = 0; |
| 72 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 73 | while (bytes_left) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 74 | fread(buf, sizeof(char), buff_size, in); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 75 | if (!feof(in)) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 76 | bytes_left -= fwrite(buf, sizeof(char), buff_size, out); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 77 | } else |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 78 | bytes_left = 0; |
| 79 | } |
| 80 | ret = ferror(in) | ferror(out); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 81 | if (ret) |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 82 | fprintf(stderr, "ERROR: Occured during file concatenation\n"); |
| 83 | return ret; |
| 84 | } |
| 85 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 86 | int main(int argc, char *argv[]) |
| 87 | { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 88 | struct stat s; |
| 89 | unsigned size, base; |
| 90 | int unified_boot = 0; |
| 91 | unsigned unified_boot_magic[20]; |
| 92 | unsigned non_unified_boot_magic[10]; |
| 93 | unsigned magic_len = 0; |
| 94 | unsigned *magic; |
| 95 | unsigned cert_chain_size = 0; |
| 96 | unsigned signature_size = 0; |
| 97 | int secure_boot = 0; |
| 98 | int fd; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 99 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 100 | if (argc < 3) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 101 | return print_usage(); |
| 102 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 103 | |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 104 | if (argc == 4) { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 105 | if (!strcmp("unified-boot", argv[3])) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 106 | unified_boot = 1; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 107 | } else if (!strcmp("secure-boot", argv[3])) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 108 | fprintf(stderr, |
| 109 | "ERROR: Missing arguments: [outbin maxsize] | [outbin, maxsize, certchain, signature + certifcate(s)]\n"); |
| 110 | return print_usage(); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 111 | } else if (!strcmp("unsecure-boot", argv[3])) { |
| 112 | fprintf(stderr, |
| 113 | "ERROR: Missing arguments: outbin directory\n"); |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 114 | return print_usage(); |
| 115 | } |
| 116 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 117 | |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 118 | if (argc > 4) { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 119 | if (!strcmp("secure-boot", argv[3])) { |
| 120 | if (argc < 9 && argc != 6) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 121 | fprintf(stderr, |
| 122 | "ERROR: Missing argument(s): [outbin maxsize] | [outbin, maxsize, certchain, signature + certifcate(s)]\n"); |
| 123 | return print_usage(); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 124 | } |
| 125 | secure_boot = 1; |
| 126 | signature_size = 256; //Support SHA 256 |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 127 | cert_chain_size = atoi(argv[5]); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 128 | } |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 129 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 130 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 131 | if (stat(argv[1], &s)) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 132 | perror("cannot stat binary"); |
| 133 | return -1; |
| 134 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 135 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 136 | if (unified_boot) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 137 | magic = unified_boot_magic; |
| 138 | magic_len = sizeof(unified_boot_magic); |
| 139 | } else { |
| 140 | magic = non_unified_boot_magic; |
| 141 | magic_len = sizeof(non_unified_boot_magic); |
| 142 | } |
| 143 | |
| 144 | size = s.st_size; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 145 | #if MEMBASE |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 146 | base = MEMBASE; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 147 | #else |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 148 | base = 0; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 149 | #endif |
| 150 | |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 151 | printf("Image Destination Pointer: 0x%x\n", base); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 152 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 153 | magic[0] = 0x00000005; /* appsbl */ |
| 154 | magic[1] = 0x00000003; //Flash_partition_version /* nand */ |
| 155 | magic[2] = 0x00000000; //image source pointer |
| 156 | magic[3] = base; //image destination pointer |
| 157 | magic[4] = size + cert_chain_size + signature_size; //image size |
| 158 | magic[5] = size; //code size |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 159 | magic[6] = base + size; |
| 160 | magic[7] = signature_size; |
| 161 | magic[8] = size + base + signature_size; |
| 162 | magic[9] = cert_chain_size; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 163 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 164 | if (unified_boot == 1) { |
| 165 | magic[10] = 0x33836685; /* cookie magic number */ |
| 166 | magic[11] = 0x00000001; /* cookie version */ |
| 167 | magic[12] = 0x00000002; /* file formats */ |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 168 | magic[13] = 0x00000000; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 169 | magic[14] = 0x00000000; /* not setting size for boot.img */ |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 170 | magic[15] = 0x00000000; |
| 171 | magic[16] = 0x00000000; |
| 172 | magic[17] = 0x00000000; |
| 173 | magic[18] = 0x00000000; |
| 174 | magic[19] = 0x00000000; |
| 175 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 176 | |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 177 | fd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 178 | if (fd < 0) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 179 | perror("cannot open header for writing"); |
| 180 | return -1; |
| 181 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 182 | if (write(fd, magic, magic_len) != magic_len) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 183 | perror("cannot write header"); |
| 184 | close(fd); |
| 185 | unlink(argv[2]); |
| 186 | return -1; |
| 187 | } |
| 188 | close(fd); |
| 189 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 190 | if (secure_boot && argc > 6) { |
| 191 | FILE *input_file; |
| 192 | FILE *output_file; |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 193 | unsigned buff_size = 1; |
| 194 | char buf[buff_size]; |
| 195 | unsigned bytes_left; |
| 196 | unsigned current_cert_chain_size = 0; |
| 197 | int padding_size = 0; |
| 198 | int i; |
| 199 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 200 | if ((output_file = fopen(argv[6], "wb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 201 | perror("ERROR: Occured during fopen"); |
| 202 | return -1; |
| 203 | } |
| 204 | printf("Certificate Chain Output File: %s\n", argv[6]); |
| 205 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 206 | for (i = 8; i < argc; i++) { |
| 207 | if ((input_file = fopen(argv[i], "rb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 208 | perror("ERROR: Occured during fopen"); |
| 209 | return -1; |
| 210 | } |
| 211 | stat(argv[i], &s); |
| 212 | bytes_left = s.st_size; |
| 213 | current_cert_chain_size += bytes_left; |
| 214 | if (cat(input_file, output_file, bytes_left, buff_size)) |
| 215 | return -1; |
| 216 | fclose(input_file); |
| 217 | } |
| 218 | |
| 219 | //Pad certifcate chain to the max expected size from input |
| 220 | memset(buf, 0xFF, sizeof(buf)); |
| 221 | padding_size = cert_chain_size - current_cert_chain_size; |
Kinson Chik kchik@codeaurora.org | 1cb7b4d | 2010-12-15 15:00:59 -0800 | [diff] [blame] | 222 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 223 | if (padding_size < 0) { |
| 224 | fprintf(stderr, |
| 225 | "ERROR: Input certificate chain (Size=%d) is larger than the maximum specified (Size=%d)\n", |
Kinson Chik kchik@codeaurora.org | 1cb7b4d | 2010-12-15 15:00:59 -0800 | [diff] [blame] | 226 | current_cert_chain_size, cert_chain_size); |
| 227 | return -1; |
| 228 | } |
| 229 | |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 230 | bytes_left = (padding_size > 0) ? padding_size : 0; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 231 | while (bytes_left) { |
| 232 | if (!ferror(output_file)) |
| 233 | bytes_left -= |
| 234 | fwrite(buf, sizeof(buf), buff_size, |
| 235 | output_file); |
| 236 | else { |
| 237 | fprintf(stderr, |
| 238 | "ERROR: Occured during certifcate chain padding\n"); |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 239 | return -1; |
| 240 | } |
| 241 | } |
| 242 | fclose(output_file); |
| 243 | |
| 244 | //Concat and combine to signed image. Format [HDR][RAW APPSBOOT][PADDED CERT CHAIN] |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 245 | if ((output_file = fopen(argv[4], "wb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 246 | perror("ERROR: Occured during fopen"); |
| 247 | return -1; |
| 248 | } |
| 249 | printf("Image Output File: %s\n", argv[4]); |
| 250 | |
| 251 | //Header |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 252 | if ((input_file = fopen(argv[2], "rb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 253 | perror("ERROR: Occured during fopen"); |
| 254 | return -1; |
| 255 | } |
| 256 | stat(argv[2], &s); |
| 257 | if (cat(input_file, output_file, s.st_size, buff_size)) |
| 258 | return -1; |
| 259 | fclose(input_file); |
| 260 | |
| 261 | //Raw Appsbl |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 262 | if ((input_file = fopen(argv[1], "rb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 263 | perror("ERROR: Occured during fopen"); |
| 264 | return -1; |
| 265 | } |
| 266 | stat(argv[1], &s); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 267 | if (cat(input_file, output_file, s.st_size, buff_size)) |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 268 | return -1; |
| 269 | fclose(input_file); |
| 270 | |
| 271 | //Signature |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 272 | if ((input_file = fopen(argv[7], "rb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 273 | perror("ERROR: Occured during fopen"); |
| 274 | return -1; |
| 275 | } |
| 276 | stat(argv[7], &s); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 277 | if (cat(input_file, output_file, s.st_size, buff_size)) |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 278 | return -1; |
| 279 | fclose(input_file); |
| 280 | |
| 281 | //Certifcate Chain |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 282 | if ((input_file = fopen(argv[6], "rb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 283 | perror("ERROR: Occured during fopen"); |
| 284 | return -1; |
| 285 | } |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 286 | if (cat |
| 287 | (input_file, output_file, |
| 288 | (current_cert_chain_size + padding_size), buff_size)) |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 289 | return -1; |
| 290 | fclose(input_file); |
| 291 | |
| 292 | fclose(output_file); |
| 293 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 294 | } else if (argc == 5 || argc == 6) { |
| 295 | FILE *input_file; |
| 296 | FILE *output_file; |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 297 | unsigned buff_size = 1; |
| 298 | char buf[buff_size]; |
| 299 | |
| 300 | //Concat and combine to unsigned image. Format [HDR][RAW APPSBOOT] |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 301 | if ((output_file = fopen(argv[4], "wb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 302 | perror("ERROR: Occured during fopen"); |
| 303 | return -1; |
| 304 | } |
| 305 | printf("Image Output File: %s\n", argv[4]); |
| 306 | |
| 307 | //Header |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 308 | if ((input_file = fopen(argv[2], "rb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 309 | perror("ERROR: Occured during fopen"); |
| 310 | return -1; |
| 311 | } |
| 312 | stat(argv[2], &s); |
| 313 | if (cat(input_file, output_file, s.st_size, buff_size)) |
| 314 | return -1; |
| 315 | fclose(input_file); |
| 316 | |
| 317 | //Raw Appsbl |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 318 | if ((input_file = fopen(argv[1], "rb")) == NULL) { |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 319 | perror("ERROR: Occured during fopen"); |
| 320 | return -1; |
| 321 | } |
| 322 | stat(argv[1], &s); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 323 | if (cat(input_file, output_file, s.st_size, buff_size)) |
Kinson Chik | c874a2b | 2010-11-16 18:24:05 -0800 | [diff] [blame] | 324 | return -1; |
| 325 | fclose(input_file); |
| 326 | fclose(output_file); |
| 327 | } |
| 328 | |
| 329 | printf("Done execution\n"); |
| 330 | |
| 331 | return 0; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 332 | } |