Advertisement
tkamiten

load and indexes fixed 1

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