Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <dirent.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/wait.h>
- #include <errno.h>
- #define MSGSIZE 512
- int main()
- {
- char inbuf[MSGSIZE];
- int p[2], pid, nbytes, filesize, filepos;
- DIR *d;
- struct dirent *dir;
- FILE *curr;
- FILE *new;
- int status;
- char *filename;
- char *bytes = (char *)calloc(MSGSIZE,sizeof(char));
- if (pipe(p) < 0)
- {
- exit(1);
- }
- int i = chdir("/home/ira/osisp/6/images/test"); // путь к папке с картинками(335)
- d = opendir( "." );
- if( d == NULL )
- {
- printf("Cannot open dir");
- exit(EXIT_FAILURE);
- }
- while( ( dir = readdir( d ) ) )
- {
- if( strcmp( dir->d_name, "." ) == 0 ||
- strcmp( dir->d_name, ".." ) == 0 )
- {
- continue;
- }
- filename = dir->d_name;
- printf("%s \n",filename); // ДАЖЕ ЗДЕСЬ НЕ ВСЕ ИМЕНА ФАЙЛОВ ВЫВОДИТ????????????????????????????
- curr = fopen(dir->d_name,"rb");
- if (curr == NULL)
- {
- printf("Error opening file");
- exit(EXIT_FAILURE);
- }
- fseek(curr,0, SEEK_END);
- filesize = ftell(curr);
- fseek(curr,0,SEEK_SET);
- filepos =0;
- while(filepos != filesize)
- {
- if(filesize-filepos > MSGSIZE)
- {
- fread(bytes,sizeof(char), MSGSIZE, curr);
- write(p[1], bytes, MSGSIZE);
- filepos = filepos + MSGSIZE;
- }
- else
- {
- fread(bytes,sizeof(char),filesize-filepos,curr);
- write(p[1], bytes, filesize-filepos);
- fclose(curr);
- //printf("Wrote 1 file \n");
- break;
- }
- }
- if(pid == 0)
- {
- int reading_bytes = 0;
- chdir("/home/ira/osisp/6/images/out"); // путь для выходных изображений
- new = fopen(filename,"wb");
- while(reading_bytes != filesize)
- {
- if(filesize-reading_bytes > MSGSIZE)
- {
- read(p[0], bytes, MSGSIZE);
- fwrite(bytes,sizeof(char),MSGSIZE,new);
- reading_bytes = reading_bytes + MSGSIZE;
- }
- else
- {
- read(p[0], bytes,filesize-reading_bytes);
- fwrite(bytes,sizeof(char),filesize-reading_bytes,new);
- fclose(new);
- //printf("Red 1 file \n");
- break;
- }
- }
- exit(0);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment