Advertisement
tkamiten

Pset6 Load and Indexes

Jun 4th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. bool load(FILE* file, BYTE** content, size_t* length)
  2. {
  3.  
  4. int counter = 0;
  5. BYTE* buf = NULL;
  6. BYTE* ptr;
  7. BYTE* r_ptr;
  8.  
  9. ptr = (BYTE *)malloc(sizeof(BYTE));
  10.  
  11. while(fread(buf, sizeof(BYTE), 1, file) == 1)
  12. {
  13. r_ptr = (BYTE *)realloc(ptr,sizeof(BYTE));
  14. *r_ptr = *buf;
  15. counter++;
  16. }
  17.  
  18. *content = ptr;
  19. *length = counter;
  20. return true;
  21. }
  22. char* indexes(const char* path)
  23. {
  24. int res_p; // store access return integer
  25. int res_h;
  26.  
  27. char* php = NULL;
  28. char* html= NULL;
  29.  
  30. strcpy(php, path);
  31. strcat(php, "index.php");
  32. const char* php_c =(const char*)php;
  33.  
  34. strcpy(html, path);
  35. strcat(html, "index.html");
  36. const char* html_c =(const char*)html;
  37.  
  38. char* path_p = malloc(strlen(path) + 1 + 9);
  39. strcpy(path_p, path);
  40. strcat(path_p, "index.php");
  41.  
  42. char* path_h = malloc(strlen(path) + 1 + 10);
  43. strcpy(path_h, path);
  44. strcat(path_h, "index.html");
  45.  
  46. res_p = access(php_c, F_OK);
  47. res_h = access(html_c, F_OK);
  48.  
  49. if (res_p == 0)
  50. return path_p;
  51. else
  52. {
  53. if (res_h == 0)
  54. return path_h;
  55. else
  56. return NULL;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement