mv-stub.c (788B)
- // utils-std: Collection of commonly available Unix tools
- // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- // SPDX-License-Identifier: MPL-2.0
- #include <stdio.h> // fprintf, rename
- #include <unistd.h> // getopt
- #include <string.h> // strerror
- #include <errno.h>
- int
- main(int argc, char *argv[])
- {
- int c = -1;
- while((c = getopt(argc, argv, ":f")) != -1)
- {
- switch(c)
- {
- case 'f':
- // ignored
- break;
- case '?':
- fprintf(stderr, "mv: Unknown option '-%c'\n", optopt);
- break;
- }
- }
- argc -= optind;
- argv += optind;
- if(argc != 2)
- {
- fprintf(stderr, "Usage: mv [-f] src dest\n");
- return 1;
- }
- if(rename(argv[0], argv[1]) != 0)
- {
- fprintf(stderr, "mv: Failed renaming: %s\n", strerror(errno));
- return 1;
- }
- return 0;
- }