mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-10-17 10:55:06 +00:00
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#include <coreutils/command_support.h>
|
|
|
|
#include <app/manifest.h>
|
|
|
|
#include <tactility/filesystem/fs.h>
|
|
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
|
|
namespace coreutils::cp {
|
|
|
|
static int32_t main(int argc, char* argv[]) {
|
|
if (argc < 3) {
|
|
printf("usage: cp <src> <dst>\n");
|
|
return 1;
|
|
}
|
|
|
|
char source[FILE_MAX_PATH_STRING_LENGTH];
|
|
if (!resolvePathArg("cp", argv[1], source, sizeof(source))) {
|
|
return 1;
|
|
}
|
|
if (directory_exists(source)) {
|
|
fprintf(stderr, "cp: directories are not supported\n");
|
|
return 1;
|
|
}
|
|
|
|
char target[FILE_MAX_PATH_STRING_LENGTH];
|
|
if (!buildTarget(source, argv[2], target, sizeof(target))) {
|
|
fprintf(stderr, "cp: path too long\n");
|
|
return 1;
|
|
}
|
|
|
|
if (strcmp(source, target) == 0) {
|
|
fprintf(stderr, "cp: '%s' and '%s' are the same file\n", argv[1], argv[2]);
|
|
return 1;
|
|
}
|
|
|
|
return reportResult("cp", argv[1], file_copy(source, target, true));
|
|
}
|
|
|
|
extern const ::AppManifest manifest = {
|
|
.id = "cp",
|
|
.name = "cp",
|
|
.category = APP_CATEGORY_SYSTEM,
|
|
.location = { .type = APP_LOCATION_MEMORY, .location = reinterpret_cast<void*>(main) },
|
|
.flags = APP_MANIFEST_FLAG_HEADLESS,
|
|
.stack = { .depth = 4096, .desired_memory_capability = 0 },
|
|
};
|
|
|
|
} // namespace coreutils::cp
|