home *** CD-ROM | disk | FTP | other *** search
- /* This file is intended to be compiled with Turbo-C */
-
- #include <stdio.h>
- #include <fcntl.h>
-
- fatal(char *s)
- {
- fputs(s, stderr);
- exit(1);
- }
-
- main(int argc, char **argv)
- {
- int f1;
- int f2;
- char buf1[512];
- char buf2[512];
- int len1, len2;
-
- if (argc < 3)
- fatal("Usage: udpate srcfile destfile\n");
-
- f1 = _open(argv[1], O_RDONLY);
- if (f1 < 0)
- fatal("Cannot open src file\n");
-
- f2 = _open(argv[2], O_RDONLY);
-
- if (f2 >= 0)
- while (1)
- {
- len1 = _read(f1, buf1, 512);
- len2 = _read(f2, buf2, 512);
- if (len1 != len2)
- break;
- if (memcmp(buf1, buf2, len1))
- break;
- if (len1)
- continue;
- exit(0);
- }
-
- if (f2 >= 0)
- {
- printf("File `%s' updated\n", argv[2]);
- _close(f2);
- }
- else
- printf("File `%s' created\n", argv[2]);
-
- lseek(f1, 0L, 0);
- f2 = _creat(argv[2], 0);
- while (1)
- {
- len1 = _read(f1, buf1, 512);
- if (len1 == 0)
- break;
- len2 = _write(f2, buf1, len1);
- }
- _close(f1);
- _close(f2);
- exit(0);
- }
-