ischeme_plugin.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <stdlib.h>
  2. #include <errno.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <faux/faux.h>
  10. #include <faux/str.h>
  11. #include <klish/ischeme.h>
  12. #include <klish/kscheme.h>
  13. #include <klish/kdb.h>
  14. uint8_t kdb_ischeme_major = KDB_MAJOR;
  15. uint8_t kdb_ischeme_minor = KDB_MINOR;
  16. bool_t kdb_ischeme_deploy_scheme(kdb_t *db, const kscheme_t *scheme)
  17. {
  18. faux_ini_t *ini = NULL;
  19. const char *out_path = NULL;
  20. int f = -1;
  21. char *out = NULL;
  22. ssize_t bytes_written = 0;
  23. assert(db);
  24. if (!db)
  25. return BOOL_FALSE;
  26. out = ischeme_deploy(scheme, 0);
  27. if (!out)
  28. return BOOL_FALSE;
  29. // Get configuration info from kdb object
  30. ini = kdb_ini(db);
  31. if (ini)
  32. out_path = faux_ini_find(ini, "DeployPath");
  33. if (out_path)
  34. f = open(out_path, O_WRONLY | O_CREAT | O_TRUNC, 00644);
  35. else
  36. f = STDOUT_FILENO;
  37. if (f < 0) {
  38. faux_str_free(out);
  39. return BOOL_FALSE;
  40. }
  41. bytes_written = faux_write_block(f, out, strlen(out));
  42. if (out_path)
  43. close(f);
  44. faux_str_free(out);
  45. if (bytes_written < 0)
  46. return BOOL_FALSE;
  47. return BOOL_TRUE;
  48. }