fn85.3 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. .TH Fn85 3 "September 2017" "Version 1.0" "libfn85 API"
  2. .SH NAME
  3. fn85 \- file name in base 85 (from arbitrary bytes) library.
  4. .SH SYNOPSIS
  5. .br
  6. .B #include <fn85.h>
  7. .sp
  8. Link with \fI\-lfn85\fP or `pkg-config --libs fn85`
  9. .SH DESCRIPTION
  10. fn85 encodes 4 bytes of arbitrary data as 5 printable ascii characters suitable for use in a file name. This is done by treating each byte as a digit in a 256 radix number and converting said number to an 85 radix number. The digits used to represent this 85 radix number are the following in order from 0 to 85:
  11. .sp
  12. 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$%&*+,-:;<=>?@[]^_`{|}
  13. .sp
  14. .SS Types
  15. .B Fn85_err
  16. .RB "represents a decoding error. Possible values are " FN85_OKAY " for no error, " FN85_INVALID " for trying to decode something that is not a valid digit, and " FN85_TOO_HIGH " for decoding a number that is greater than the possible value that can be represented by 4 bytes. It is defined as such:"
  17. .sp
  18. typedef enum { FN85_OKAY, FN85_INVALID, FN85_TOO_HIGH } Fn85_err;
  19. .SS Functions
  20. .BI "void fn85_encode(char *" des ", const void *" src ", size_t " units ");"
  21. .br
  22. .BI "Fn85_err fn85_decode(void *" des ", const char *" src ", size_t " units ", size_t *" pos ", const char **" error ");"
  23. .sp
  24. .B fn85_encode ()
  25. .RI "encodes 4 * " units " bytes from " src " to 5 * " units " digits in " des "."
  26. .sp
  27. .B fn85_decode ()
  28. .RI "decodes 5 * " units " digits from " src " to 4 * " units " bytes in " des ". The value of " pos " should be initialized before calling the function and is increased by the number of valid digits before an error occurs. If no error occurs, this number is increased by 5 * " units ". If " error " is not NULL, it will be set to an appropriate error string upon an error occurring."
  29. .SH "Return Value"
  30. The function
  31. .B fn85_decode ()
  32. returns a value of type
  33. .B Fn85_err
  34. which denotes if an error occured in decoding, and if so, what said error was. The value FN85_OKAY denotes that no error has occurred, this also means an error string will not be set.
  35. .SH EXAMPLES
  36. .SS Encoding and decoding simple data
  37. .nf
  38. #include <stdio.h>
  39. #include <fn85.h>
  40. int
  41. main(int argc, char *argv[])
  42. {
  43. char dat[16] = "hello, world!!!";
  44. char dat2[21];
  45. char dat3[sizeof(dat)];
  46. size_t pos = 0;
  47. const char *error;
  48. /* encode and print encoding */
  49. fn85_encode(dat2, dat, 4);
  50. dat2[20] = '\e0';
  51. printf("%s\n", dat2);
  52. /* decode and check for errors */
  53. if (fn85_decode(dat3, dat2, 4, &pos, &error) == FN85_OKAY) {
  54. printf("%s\n", dat3);
  55. } else {
  56. printf("%s at %zu\n", error, pos);
  57. }
  58. return 0;
  59. }
  60. .fi
  61. .SH AUTHOR
  62. Uladox (more than based!)
  63. .SH "AVAILABILITY AND SOURCE"
  64. .B fn85
  65. can be found in its repository at https://www.notabug.org/Uladox/fn85
  66. .SH "SEE ALSO"
  67. .BR ascii (7)
  68. .BR utf-8 (7)
  69. .BR filesystems (5)
  70. .BR rid (3)
  71. .BR uuid (3)
  72. .BR endian (3)
  73. .BR base32 (1)
  74. .BR base64 (1)