-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmove.c
More file actions
31 lines (26 loc) · 710 Bytes
/
move.c
File metadata and controls
31 lines (26 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// A re-implementation of the Linux mv command
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void print_error(char *this, char *filename1, char *filename2){
fprintf(stderr, "%s cannot move %s to %s\n%s\n",
this, filename1, filename2, strerror(errno));
exit(EXIT_FAILURE);
}
void print_usage(char *this){
fprintf(stderr, "SYNTAX ERROR:\nUsage: %s [old filename] [new filename]\n", this);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]){
errno = 0;
FILE *fpr, *fpw;
char ch;
if(argc != 3){
print_usage(argv[0]);
}
else if(rename(argv[1], argv[2]) == -1){
print_error(argv[0], argv[1], argv[2]);
}
return 0;
}