mkdir.c 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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** dirname = shell_argv(1);
  16. char absolute_path[MAX_PATH_LENGTH];
  17. // Check if absolute path
  18. if (dirname[1][0] != '/')
  19. {
  20. char* cwd = fs_getcwd();
  21. uprintln("CWD:");
  22. uprintln(cwd);
  23. strcpy(absolute_path, cwd);
  24. strcat(absolute_path, "/");
  25. strcat(absolute_path, dirname[1]);
  26. }
  27. else
  28. {
  29. strcpy(absolute_path, dirname[1]);
  30. }
  31. // Create directory
  32. if (fs_mkdir(absolute_path))
  33. {
  34. bdos_println("Directory created");
  35. }
  36. else
  37. {
  38. bdos_println("Could not create directory");
  39. }
  40. return 'q';
  41. }
  42. void interrupt()
  43. {
  44. // Handle all interrupts
  45. word i = get_int_id();
  46. switch(i)
  47. {
  48. case INTID_TIMER1:
  49. timer1Value = 1; // Notify ending of timer1
  50. break;
  51. }
  52. }