1
0

mkdir.c 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #define word char
  2. #include "lib/math.c"
  3. #include "lib/stdlib.c"
  4. #include "lib/sys.c"
  5. #include "lib/brfs.c"
  6. int main()
  7. {
  8. // Read number of arguments
  9. word argc = shell_argc();
  10. if (argc < 2)
  11. {
  12. bdos_println("Usage: mkdir <directory>");
  13. return 1;
  14. }
  15. // Read directory name
  16. char** args = shell_argv();
  17. char* dirname = args[1];
  18. char absolute_path[MAX_PATH_LENGTH];
  19. // Check if absolute path
  20. if (dirname[0] != '/')
  21. {
  22. char* cwd = fs_getcwd();
  23. strcpy(absolute_path, cwd);
  24. strcat(absolute_path, "/");
  25. strcat(absolute_path, dirname);
  26. }
  27. else
  28. {
  29. strcpy(absolute_path, dirname);
  30. }
  31. // Create directory
  32. if (fs_mkdir(absolute_path))
  33. {
  34. //fs_syncflash();
  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. }