| git.druid.rocks | index | druid520 | kaboom | src/ | user/ | touch.nsc |
src/user/touch.nsc
include "syscalls.nsh";
include "lib.nsh";
include "string.nsh";
include "stdio.nsh";
/* creates name (a bare name or a real path) if it doesn't already
* exist -- a no-op, not an error, if it does. kfs has no mtime field
* on an inode at all yet, so unlike real touch this can't update an
* existing file's timestamp; "make sure this file exists" is the
* whole feature for now. */
global i32
main(i32 argc, ptr argv)
{
ptr name;
u64 name_len;
i64 kind;
if(argc < 2)
{
fputs(2, "usage: touch name\n");
return 1;
}
name = argv_get(argv, 1);
name_len = strlen(name);
kind = sys_stat(name, name_len);
if(kind >= (i64)0)
{
return 0; /* already exists -- nothing to do */
}
if(sys_writefile(name, name_len, "", (u64)0) == 0)
{
print_err(2, "touch", "failed");
return 1;
}
return 0;
}