relpath.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <config-util.h>
  19. #include <config.h>
  20. #include <grub/util/misc.h>
  21. #include <grub/mm.h>
  22. #include <grub/misc.h>
  23. #include <grub/emu/misc.h>
  24. #include <grub/emu/hostdisk.h>
  25. #include <grub/emu/getroot.h>
  26. #include <string.h>
  27. #include <dos/dos.h>
  28. #include <dos/filesystem.h>
  29. #include <dos/exall.h>
  30. #include <proto/dos.h>
  31. #include <proto/exec.h>
  32. #include <devices/trackdisk.h>
  33. char *
  34. grub_make_system_path_relative_to_its_root (const char *path)
  35. {
  36. char *p;
  37. unsigned char *tmp;
  38. char *ret;
  39. BPTR lck;
  40. if (path[0] == '/' && path[1] == '/' && path[2] == ':')
  41. return xstrdup (path);
  42. tmp = xmalloc (2048);
  43. lck = Lock ((const unsigned char *) path, SHARED_LOCK);
  44. if (!lck || !NameFromLock (lck, tmp, 2040))
  45. {
  46. free (tmp);
  47. tmp = (unsigned char *) xstrdup (path);
  48. }
  49. if (lck)
  50. UnLock (lck);
  51. p = strchr ((char *) tmp, ':');
  52. if (!p)
  53. return (char *) tmp;
  54. if (p[1] == '/' || p[1] == '\0')
  55. {
  56. ret = xstrdup (p + 1);
  57. }
  58. else
  59. {
  60. ret = xmalloc (strlen (p + 1) + 2);
  61. ret[0] = '/';
  62. strcpy (ret + 1, p + 1);
  63. }
  64. free (tmp);
  65. return ret;
  66. }