se7enuts

x3333

May 31st, 2016
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. /* Vytautas Deinis IF-4/6 Ld3 2*/
  2. /* Failas: loginas_ld3.c */
  3. #define _XOPEN_SOURCE 500
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
  10. #include <ftw.h>
  11. #include <dirent.h>
  12.  
  13. #define SIZE 1048576
  14.  
  15. int kp_test_open(const char *name);
  16. int kp_test_close(int fd);
  17. int kp_ftwinfo(const char *p, const struct stat *st, int fl, struct FTW *fbuf);
  18.  
  19.  
  20.  
  21. int kp_test_open(const char *name){
  22. int dskr;
  23. dskr = open( name, O_RDONLY );
  24. if( dskr == -1 ){
  25. perror( name );
  26. exit(1);
  27.  
  28. }
  29.  
  30. return dskr;
  31. }
  32.  
  33. int kp_test_close(int fd){
  34. int rv;
  35. rv = close( fd );
  36.  
  37. if( rv != 0 ) perror ( "close() failed" );
  38. else puts( "closed" );
  39. return rv;
  40. }
  41.  
  42.  
  43.  
  44. int kp_ftwinfo(const char *p, const struct stat *st, int fl, struct FTW *fbuf){
  45.  
  46. // KAD PATIKRINTI AR FAILAS if(fl == FTW_F ) asdasd; else asdasd; // direktorijai FTW_D // jeigu truksta teisiu katalogui nuskaityti
  47. if(fl == FTW_F) {
  48.  
  49. if(st->st_size > SIZE) {
  50. printf( "Dydis %d bits--", st->st_size); //veikia
  51. printf( "Rastas failas: "); //veikia
  52. puts( p ); // spausdinti //veikia
  53. chmod(p, S_IRWXU); //veikia
  54. }
  55.  
  56. }
  57.  
  58. return 0;
  59. }
  60.  
  61.  
  62. int main(int argc, char* argv[] )
  63. {
  64. printf( "(C) 2016 Vytautas Deinis, %s\n", __FILE__ );
  65. int f1, f2, f3, f4;
  66. int rv;
  67.  
  68. if( argc != 2 ){
  69. printf( "Naudojimas:\n %s failas_ar_katalogas\n", argv[0] );
  70. exit( 255 );
  71. }
  72.  
  73. //f1 = kp_test_open( argv[1] );
  74.  
  75. rv = nftw( argv[1], kp_ftwinfo, 50, 0 );
  76. if( rv == -1 ){
  77.  
  78. perror( "nftw failed" );
  79.  
  80. exit( 1 );
  81. }
  82. if( rv != 0 ){
  83.  
  84. printf( "ntfw fn function returnd %d != 0 -> nftw finished\n", rv );
  85.  
  86. }
  87. //kp_test_close(f1);
  88. return 0;
  89.  
  90.  
  91. }
Add Comment
Please, Sign In to add comment