| 226 | | /* map first file */ |
|---|
| 227 | | if ((fd = open(argv[2], O_RDONLY)) == -1) { |
|---|
| 228 | | fprintf(stderr, "Error - Unable to open file: %s.\n", strerror(errno)); |
|---|
| 229 | | exit(1); |
|---|
| 230 | | } |
|---|
| 231 | | if (fstat(fd, &fs1) != 0) { |
|---|
| 232 | | fprintf(stderr, "Error - Unable to get file size: %s.\n", strerror(errno)); |
|---|
| 233 | | exit(1); |
|---|
| 234 | | } |
|---|
| 235 | | if (fs1.st_size < 1) { |
|---|
| 236 | | fprintf(stdout, "File %s is empty.\n", argv[2]); |
|---|
| 237 | | exit(0); |
|---|
| 238 | | } |
|---|
| 239 | | if ((content1 = mmap(0, fs1.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { |
|---|
| 240 | | fprintf(stderr, "Error - Unable to map file into memory: %s.\n", strerror(errno)); |
|---|
| 241 | | exit(1); |
|---|
| 242 | | } |
|---|
| 243 | | close(fd); |
|---|
| 244 | | |
|---|
| 245 | | |
|---|
| 246 | | /* map second file */ |
|---|
| 247 | | if ((fd = open(argv[3], O_RDONLY)) == -1) { |
|---|
| 248 | | fprintf(stderr, "Error - Unable to open file: %s.\n", strerror(errno)); |
|---|
| 249 | | exit(1); |
|---|
| 250 | | } |
|---|
| 251 | | if (fstat(fd, &fs2) != 0) { |
|---|
| 252 | | fprintf(stderr, "Error - Unable to get file size: %s.\n", strerror(errno)); |
|---|
| 253 | | exit(1); |
|---|
| 254 | | } |
|---|
| 255 | | if (fs2.st_size < 1) { |
|---|
| 256 | | fprintf(stdout, "File is empty.\n"); |
|---|
| 257 | | exit(0); |
|---|
| 258 | | } |
|---|
| 259 | | if ((content2 = mmap(0, fs2.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { |
|---|
| 260 | | fprintf(stderr, "Error - Unable to map file into memory: %s.\n", strerror(errno)); |
|---|
| 261 | | exit(1); |
|---|
| 262 | | } |
|---|
| 263 | | close(fd); |
|---|
| | 225 | /* mmap files */ |
|---|
| | 226 | for (i=0; i<2; i++) { |
|---|
| | 227 | if ((fd = open(argv[i+2], O_RDONLY)) == -1) { |
|---|
| | 228 | fprintf(stderr, "Error - Unable to open file: %s.\n", strerror(errno)); |
|---|
| | 229 | exit(EXIT_FAILURE); |
|---|
| | 230 | } |
|---|
| | 231 | if (fstat(fd, &fs[i]) != 0) { |
|---|
| | 232 | fprintf(stderr, "Error - Unable to get file size: %s.\n", strerror(errno)); |
|---|
| | 233 | exit(EXIT_FAILURE); |
|---|
| | 234 | } |
|---|
| | 235 | if (fs[i].st_size < 1) { |
|---|
| | 236 | fprintf(stdout, "File %s is empty.\n", argv[i+2]); |
|---|
| | 237 | exit(EXIT_SUCCESS); |
|---|
| | 238 | } |
|---|
| | 239 | if ((content[i] = mmap(0, fs[i].st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { |
|---|
| | 240 | fprintf(stderr, "Error - Unable to map file into memory: %s.\n", strerror(errno)); |
|---|
| | 241 | exit(EXIT_FAILURE); |
|---|
| | 242 | } |
|---|
| | 243 | close(fd); |
|---|
| | 244 | } |
|---|