Advertisement
Guest User

setCV posix

a guest
Mar 30th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <errno.h>
  4. #include <limits.h>
  5. #include <string.h>
  6. #include <fcntl.h>
  7. #include <stdlib.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10.  
  11. #define SECTOR_SIZE 4096
  12.  
  13. char numeFisierSursa[PATH_MAX],numeFisierDestinatie[PATH_MAX];
  14. char buffer[SECTOR_SIZE],comanda[10];
  15. int bytes_read;
  16.  
  17. int main(int argc,char **argv)
  18. {
  19. FILE *fptr1,*fptr2;
  20.  
  21. printf("Nume fisier sursa : ");
  22. scanf("%s",numeFisierSursa);
  23.  
  24. printf("Nume fisier destinatie : ");
  25. scanf("%s",numeFisierDestinatie);
  26.  
  27. int f1=open(numeFisierSursa,O_RDONLY);
  28.  
  29. if(f1<0)
  30. {
  31. perror("Error on opening file");
  32. exit(1);
  33. }
  34.  
  35. int f2=open(numeFisierDestinatie,O_WRONLY);
  36.  
  37. if(f2 > 0 )
  38. {
  39. printf("Doriti sa suprascrieti continutul ? da/nu ");
  40. scanf("%10s",&comanda);
  41. if(strcmp(comanda,"da")!=0)
  42. {
  43. printf("\nNu ati acordat permisiunea");
  44. exit(5);
  45. }
  46. open(numeFisierDestinatie,O_WRONLY | O_TRUNC);
  47. chmod(numeFisierDestinatie,S_IRUSR | S_IWUSR);
  48. }
  49.  
  50.  
  51. while(1){
  52. bytes_read = read(f1,buffer,SECTOR_SIZE);
  53. if(bytes_read == 0)
  54. break;
  55. if(bytes_read == -1)
  56. {
  57. perror("error on writing");
  58. exit(6);
  59. }
  60.  
  61. for(int i=0;buffer[i]!=NULL;i++)
  62. if(buffer[i] >= 'a' && buffer[i] <= 'z')
  63. buffer[i]=buffer[i]-'a'+'A';
  64.  
  65.  
  66. if(write(f2,buffer,SECTOR_SIZE)<0)
  67. {
  68. perror("Error on writing");
  69. exit(7);
  70. }
  71.  
  72. }
  73.  
  74. if(close(f1)==-1 || close(f2)==-1)
  75. {
  76. perror("Error on closing files");
  77. exit(9);
  78. }
  79.  
  80.  
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement