subdir.c 830 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <rid.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "../rid_hex.h"
  5. /* define the directory we want to generate our Rid paths in */
  6. #define DAT_DIR "dat/"
  7. /* define the number of characters in DAT_DIR minus the '\0' */
  8. #define DAT_DIR_LEN (sizeof(DAT_DIR) - 1)
  9. /* A type for a string big enough for our path */
  10. typedef char Dir_path[DAT_DIR_LEN + sizeof(Rid_hex_path)];
  11. int
  12. main(int argc, char *argv[])
  13. {
  14. Rid id;
  15. Dir_path dir_path;
  16. /* create a random rid */
  17. rid_set(id, NULL);
  18. /* set the dat/ part of the path */
  19. strcpy(dir_path, DAT_DIR);
  20. /* generate the rest of the path */
  21. rid_hex_path(dir_path + DAT_DIR_LEN, id);
  22. /* Now we can do anything we want with dir_path, it's just a string
  23. * that looks something like "dat/41/7ed28b7db28473685f0c1dbf9f453f"
  24. */
  25. printf("%s\n", dir_path);
  26. return 0;
  27. }