Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sys
- #include <unistd.h>
- #include <fcntl.h>
- #define BUFSIZE 512
- #define PERM 0644
- /* funkcja kopiujaca */
- int copyfile(const char *plik1, const char *plik2)
- {
- int infile, outfile;
- ssize_t nread;
- char buffer[BUFSIZE];
- if((infile = open(plik1, O_RDONLY)) == -1)
- return(-1);
- if((outfile = open(plik2, O_WRONLY|O_CREAT|O_TRUNC, PERM)) == -1)
- {
- close(infile);
- return(-2);
- }
- /*teraz czytaj z plik1 po BUFSIZE znakow naraz*/
- while((nread = read(infile, buffer, BUFSIZE))>0)
- {
- /*zapisz bufor do ploku wyjsciowego*/
- write(outfile, buffer, nread);
- }
- close(infile);
- close(outfile);
- }
- /////////////////////////////
- int main(int argc, char** argv)
- {
- if (argc<3)
- {
- printf("Uzyj: %s plik_zrodlo plik_celn",argv[0]);
- exit(1);
- }
- copyfile(argv[1],argv[2]);
- }
- bibl
- #include <stdio.h>
- #include <stdlib.h>
- /*funkcja kopiujaca*/
- int copyfile(const char *plik1, const char *plik2)
- {
- FILE *in, *out;
- int c;
- if ((in = fopen(plik1,"r")) == NULL)
- return(-1);
- if ((out = fopen(plik2,"w")) == NULL)
- {
- fclose(in);
- return(-2);
- }
- while((c = getc(in)) != EOF)
- putc(c, out);
- fclose(in);
- fclose(out);
- }
- ////////////////////////////////
- int main(int argc, char** argv)
- {
- if(argc<3)
- {
- printf("Uzyj: %s plik_zrodlo plik_celn",argv[0]);
- exit(1);
- }
- copyfile(argv[1],argv[2]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement