Skip to content

Commit

Permalink
Added mkdir function for BASIC
Browse files Browse the repository at this point in the history
  • Loading branch information
totalspectrum committed Sep 8, 2023
1 parent 856e556 commit d9190e6
Show file tree
Hide file tree
Showing 6 changed files with 482 additions and 440 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 6.4.1
- Added MKDIR function for BASIC

Version 6.4.0
- Added getcrc() builtin for Spin2
- Added VFS layer for Parallax flash file system
Expand Down
12 changes: 9 additions & 3 deletions doc/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -1572,10 +1572,8 @@ chain #4

### CHDIR

Changes the current (default) directory for the program. Note that using this function requires that the "dir.bi" header be included. For example:
Changes the current (default) directory for the program. For example:
```
#include "dir.bi"
...
r = chdir("/host/dir")
```
Returns 0 on success, nonzero on failure.
Expand Down Expand Up @@ -2751,6 +2749,14 @@ print mid$(a$, 3, 2)
```
prints "cd".

### MKDIR

Attempts to create a new directory.
```
r = mkdir("/host/dir")
```
Returns 0 on success, nonzero on failure.

### MOD

`x mod y` finds the integer remainder when `x` is divided by `y`.
Expand Down
1 change: 1 addition & 0 deletions frontends/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ Aliases basicalias[] = {
{ "kill", "_remove" },
{ "lpeek", "__lpeek" },
{ "lpoke", "__lpoke" },
{ "mkdir", "_mkdir" },
{ "mount", "_mount" },
{ "pausems", "_waitms" },
{ "pausesec", "_waitsec" },
Expand Down
27 changes: 27 additions & 0 deletions include/libsys/mkdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <sys/types.h>
#include <sys/vfs.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>

/* create a directory */
int _mkdir(const char *orig_name)
{
int r;
struct vfs *v;
char *name = __getfilebuffer();
v = (struct vfs *)__getvfsforfile(name, orig_name, NULL);
if (!v || !v->open) {
#ifdef _DEBUG
__builtin_printf("mkdir: ENOSYS: vfs=%x\n", (unsigned)v);
#endif
return _seterror(ENOSYS);
}
r = (*v->mkdir)(name);
if (r != 0) {
return _seterror(-r);
}
return 0;
}
2 changes: 1 addition & 1 deletion sys/common.spin
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pri file "libsys/strings.bas" instrrev(off, x, y): r=long
pri file "libsys/dir.bas" curdir`$(): r = string
pri file "libsys/dir.bas" dir`$(pat = "", attrib = 0): r=string
pri file "libsys/remove.c" _remove(f=string): r=long

pri file "libsys/mkdir.c" _mkdir(f=string): r=long
pri file "libc/stdlib/errno.c" _seterror(r)
pri file "libc/stdlib/errno.c" _geterror(): r=long
pri file "libc/stdlib/errno.c" _geterrnoptr(): r=@long
Expand Down
Loading

0 comments on commit d9190e6

Please sign in to comment.