/RISCOS/Modules/getpath_riscos.c

http://unladen-swallow.googlecode.com/ · C · 60 lines · 52 code · 7 blank · 1 comment · 8 complexity · 49972891f21711690bc912a4f4efa9c7 MD5 · raw file

  1. #include "Python.h"
  2. #include "osdefs.h"
  3. static char *prefix, *exec_prefix, *progpath, *module_search_path=NULL;
  4. static void
  5. calculate_path()
  6. {
  7. char *pypath = getenv("Python$Path");
  8. if (pypath) {
  9. int pathlen = strlen(pypath);
  10. module_search_path = malloc(pathlen + 1);
  11. if (module_search_path)
  12. strncpy(module_search_path, pypath, pathlen + 1);
  13. else {
  14. fprintf(stderr,
  15. "Not enough memory for dynamic PYTHONPATH.\n"
  16. "Using default static PYTHONPATH.\n");
  17. }
  18. }
  19. if (!module_search_path)
  20. module_search_path = "<Python$Dir>.Lib";
  21. prefix = "<Python$Dir>";
  22. exec_prefix = prefix;
  23. progpath = Py_GetProgramName();
  24. }
  25. /* External interface */
  26. char *
  27. Py_GetPath()
  28. {
  29. if (!module_search_path)
  30. calculate_path();
  31. return module_search_path;
  32. }
  33. char *
  34. Py_GetPrefix()
  35. {
  36. if (!module_search_path)
  37. calculate_path();
  38. return prefix;
  39. }
  40. char *
  41. Py_GetExecPrefix()
  42. {
  43. if (!module_search_path)
  44. calculate_path();
  45. return exec_prefix;
  46. }
  47. char *
  48. Py_GetProgramFullPath()
  49. {
  50. if (!module_search_path)
  51. calculate_path();
  52. return progpath;
  53. }