ascii85.h 532 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * SPDX-License-Identifier: GPL-2.0
  3. *
  4. * Copyright (c) 2008 Intel Corporation
  5. * Copyright (c) 2018 The Linux Foundation. All rights reserved.
  6. */
  7. #ifndef _ASCII85_H_
  8. #define _ASCII85_H_
  9. #include <linux/kernel.h>
  10. #define ASCII85_BUFSZ 6
  11. static inline long
  12. ascii85_encode_len(long len)
  13. {
  14. return DIV_ROUND_UP(len, 4);
  15. }
  16. static inline const char *
  17. ascii85_encode(u32 in, char *out)
  18. {
  19. int i;
  20. if (in == 0)
  21. return "z";
  22. out[5] = '\0';
  23. for (i = 5; i--; ) {
  24. out[i] = '!' + in % 85;
  25. in /= 85;
  26. }
  27. return out;
  28. }
  29. #endif