Last active
August 4, 2016 18:39
-
-
Save binki/e40182e4098d9714a609918908c623b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*- c-file-style: "linux" -*- */ | |
#include <errno.h> | |
#include <stdio.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
int main(int argc, const char *const argv[]) | |
{ | |
struct stat statbuf; | |
if (argc < 2) | |
{ | |
fprintf(stderr, "Usage: %s source dest [backup]", argv[0]); | |
return 1; | |
} | |
if (argc > 3) | |
{ | |
if (unlink(argv[3])) | |
{ | |
if (errno != ENOENT) | |
{ | |
perror("unlink"); | |
return 1; | |
} | |
} | |
if (link(argv[2], argv[3])) | |
{ | |
perror("link"); | |
return 1; | |
} | |
} | |
else | |
{ | |
if (stat(argv[2], &statbuf)) | |
{ | |
perror("stat"); | |
return 1; | |
} | |
} | |
if (rename(argv[1], argv[2])) | |
{ | |
perror("rename"); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment