Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 9 roky
před 9 roky
před 9 roky
před 9 roky
před 9 roky
před 9 roky
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. unsigned long read_file_to_buffer( const char* const filepath,
  5. char* obuff,
  6. int remove_new_line_chr)
  7. {
  8. FILE* fh=0;
  9. size_t len=0;
  10. char* line=NULL;
  11. unsigned long total_len=0;
  12. if( (fh=fopen(filepath, "rb")) == 0 )
  13. {
  14. fprintf(stderr, "File %s doesn't exist. Exiting...\n", filepath);
  15. exit(1);
  16. }
  17. if(obuff=NULL)
  18. {
  19. //allocate
  20. fseek(fh, 0, SEEK_END);
  21. int pos = ftell(fh);
  22. fseek(fh, 0, SEEK_CUR);
  23. obuff = malloc(pos);
  24. }
  25. while( getline(&line, &len, fh) != -1 )
  26. {
  27. len = strlen(line);
  28. if(remove_new_line_chr)
  29. len--;
  30. strncpy(obuff+total_len, line, len);
  31. total_len+=len;
  32. free(line);
  33. line=NULL;
  34. }
  35. return total_len;
  36. }
  37. Result_t load_base64_to_hex(const char* const filepath, uint8_t* hex_buffer, size_t* len)
  38. {
  39. uint8_t* base64_buff;
  40. *len = read_file_to_buffer(filepath, base64_buff, 1);
  41. /// int base64_to_hex(const unsigned char* const i_string,
  42. //int i_string_len,
  43. //unsigned char* o_hex_array );
  44. base64_to_hex(base64_buff, *len, hex_buffer);
  45. }
  46. void check(int iFlag, const unsigned char* const msg)
  47. {
  48. if(!iFlag)
  49. {
  50. fprintf(stderr, "ERROR: %s\n", msg);
  51. exit(1);
  52. }
  53. }