| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <sys/stat.h> | 5 #include <sys/stat.h> |
| 6 #include <sys/types.h> | 6 #include <sys/types.h> |
| 7 | 7 |
| 8 #include <endian.h> | 8 #include <endian.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Returns valid fd or exits program. | 72 // Returns valid fd or exits program. |
| 73 int open_file(const char* path) { | 73 int open_file(const char* path) { |
| 74 int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 74 int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 75 if (fd < 0) { | 75 if (fd < 0) { |
| 76 perror("open"); | 76 perror("open"); |
| 77 fprintf(stderr, "failed to open %s\n", path); | 77 fprintf(stderr, "failed to open %s\n", path); |
| 78 exit(1); | 78 exit(1); |
| 79 } | 79 } |
| 80 return fd; |
| 80 } | 81 } |
| 81 | 82 |
| 82 typedef long long int64; | 83 typedef long long int64; |
| 83 // Compile assert sizeof(int64) == 8: | 84 // Compile assert sizeof(int64) == 8: |
| 84 char int64_8_bytes_long[(sizeof(int64) == 8) - 1]; | 85 char int64_8_bytes_long[(sizeof(int64) == 8) - 1]; |
| 85 | 86 |
| 86 } // namespace {} | 87 } // namespace {} |
| 87 | 88 |
| 88 int main(int argc, char** argv) { | 89 int main(int argc, char** argv) { |
| 89 if (argc != 3) { | 90 if (argc != 3) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 129 } |
| 129 // Do the rest on the second file | 130 // Do the rest on the second file |
| 130 for (;;) { | 131 for (;;) { |
| 131 size_t chunk_size = read_all(fd_in, buf, kBufSize); | 132 size_t chunk_size = read_all(fd_in, buf, kBufSize); |
| 132 if (chunk_size == 0) | 133 if (chunk_size == 0) |
| 133 break; | 134 break; |
| 134 write_all(fd2, buf, chunk_size); | 135 write_all(fd2, buf, chunk_size); |
| 135 } | 136 } |
| 136 return 0; | 137 return 0; |
| 137 } | 138 } |
| OLD | NEW |