libcm is a C development framework with an emphasis on audio signal processing applications.
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.

cmFileSysLinux.c 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //| Copyright: (C) 2009-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #include "cmPrefix.h"
  4. #include "cmGlobal.h"
  5. #include "cmRpt.h"
  6. #include "cmErr.h"
  7. #include "cmCtx.h"
  8. #include "cmMem.h"
  9. #include "cmMallocDebug.h"
  10. #include "cmLinkedHeap.h"
  11. #include "cmFileSys.h"
  12. #include "cmFileSysLinux.h"
  13. #include <glob.h>
  14. //http://developer.apple.com/library/mac/#qa/qa1549/_index.html
  15. cmChar_t* _cmCreatePathByExpandingTildePath( _cmFsLinux_t* p, const char* path )
  16. {
  17. glob_t globbuf;
  18. char **v;
  19. char *expandedPath = NULL, *result = NULL;
  20. assert(path != NULL);
  21. if (glob(path, GLOB_TILDE, NULL, &globbuf) == 0) //success
  22. {
  23. v = globbuf.gl_pathv; //list of matched pathnames
  24. expandedPath = v[0]; //number of matched pathnames, gl_pathc == 1
  25. result = cmLhAllocZ(p->lhH,cmChar_t,strlen(expandedPath) + 1);
  26. //result = (char*)calloc(1, strlen(expandedPath) + 1); //the extra char is for the null-termination
  27. if(result)
  28. strncpy(result, expandedPath, strlen(expandedPath) + 1); //copy the null-termination as well
  29. globfree(&globbuf);
  30. }
  31. return result;
  32. }
  33. cmFsRC_t _cmLinuxFileSysInit( _cmFsLinux_t** pp, cmLHeapH_t lhH, cmErr_t* err )
  34. {
  35. _cmFsLinux_t* p = cmLhAllocZ(lhH,_cmFsLinux_t,1);
  36. p->err = err;
  37. p->lhH = lhH;
  38. p->userDir = _cmCreatePathByExpandingTildePath(p,"~");
  39. p->prefDir = p->userDir; // user preferences will be stored invisible files in the home directory
  40. p->rsrcDir = "/usr/share"; // program resources will be stored in /usr/share/app-name
  41. *pp = p;
  42. return kOkFsRC;
  43. }
  44. cmFsRC_t _cmLinuxFileSysFinalize( _cmFsLinux_t* p )
  45. {
  46. return kOkFsRC;
  47. }