Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
1.6 KiB

  1. //
  2. // mxToolKit (c) 1999 by Mete Ciragan
  3. //
  4. // file: mxpath.cpp
  5. // implementation: all
  6. // last modified: May 04 1999, Mete Ciragan
  7. // copyright: The programs and associated files contained in this
  8. // distribution were developed by Mete Ciragan. The programs
  9. // are not in the public domain, but they are freely
  10. // distributable without licensing fees. These programs are
  11. // provided without guarantee or warrantee expressed or
  12. // implied.
  13. //
  14. #include "mxtk/mxpath.h"
  15. #ifdef WIN32
  16. #include <windows.h>
  17. #else
  18. #include <unistd.h"
  19. #endif
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. bool
  24. mx_setcwd (const char *path)
  25. {
  26. #ifdef WIN32
  27. return (SetCurrentDirectory (path) == TRUE);
  28. #else
  29. return (chdir (path) != -1);
  30. #endif
  31. }
  32. const char *
  33. mx_getcwd ()
  34. {
  35. static char path[256];
  36. #ifdef WIN32
  37. GetCurrentDirectory (256, path);
  38. #else
  39. getcwd (path, 256);
  40. #endif
  41. return path;
  42. }
  43. const char *
  44. mx_getpath (const char *filename)
  45. {
  46. static char path[256];
  47. #ifdef WIN32
  48. _splitpath (filename, 0, path, 0, 0);
  49. #else
  50. strcpy (path, filename);
  51. char *ptr = strrchr (path, '/');
  52. if (ptr)
  53. *ptr = '\0';
  54. #endif
  55. return path;
  56. }
  57. const char *
  58. mx_getextension (const char *filename)
  59. {
  60. static char ext[256];
  61. #ifdef WIN32
  62. _splitpath (filename, 0, 0, 0, ext);
  63. #else
  64. char *ptr = strrchr (filename, '.');
  65. if (ptr)
  66. strcpy (ext, ptr);
  67. else
  68. strcpy (ext, "");
  69. #endif
  70. return ext;
  71. }
  72. const char *
  73. mx_gettemppath ()
  74. {
  75. static char path[256];
  76. #ifdef WIN32
  77. GetTempPath (256, path);
  78. #else
  79. strcpy (path, "/tmp");
  80. #endif
  81. return path;
  82. }