mkdir.c 951 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #define word char
  2. #include "lib/math.c"
  3. #include "lib/stdlib.c"
  4. #include "lib/sys.c"
  5. int main()
  6. {
  7. // Read number of arguments
  8. word argc = shell_argc();
  9. if (argc < 2)
  10. {
  11. bdos_println("Usage: mkdir <directory>");
  12. return 1;
  13. }
  14. // Read directory name
  15. char** args = shell_argv();
  16. char* dirname = args[1];
  17. char absolute_path[MAX_PATH_LENGTH];
  18. // Check if absolute path
  19. if (dirname[0] != '/')
  20. {
  21. char* cwd = fs_getcwd();
  22. strcpy(absolute_path, cwd);
  23. strcat(absolute_path, "/");
  24. strcat(absolute_path, dirname);
  25. }
  26. else
  27. {
  28. strcpy(absolute_path, dirname);
  29. }
  30. // Create directory
  31. if (fs_mkdir(absolute_path))
  32. {
  33. fs_syncflash();
  34. }
  35. else
  36. {
  37. bdos_println("Could not create directory");
  38. }
  39. return 'q';
  40. }
  41. void interrupt()
  42. {
  43. // Handle all interrupts
  44. word i = get_int_id();
  45. switch(i)
  46. {
  47. case INTID_TIMER1:
  48. timer1Value = 1; // Notify ending of timer1
  49. break;
  50. }
  51. }