|
CS456 - Systems Programming
| Displaying exercises/e1/solution/mv.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#define K 1024
void usage(void)
{
printf("Usage: mv <src> <dst>\n");
exit(0);
}
void help(void)
{
printf("Usage: mv <src> <dst>\n");
printf("Options:\n");
printf(" --help Prints this help\n");
exit(0);
}
int main(int argc, char *argv[])
{
if (argc < 2) usage();
if (argc == 2 && strcmp(argv[1], "--help") == 0) help();
if (argc < 3) usage();
if (rename(argv[1], argv[2]) < 0) {
perror("rename");
return 1;
}
return 0;
}
|