Skip to content

Instantly share code, notes, and snippets.

@binki
Last active Aug 4, 2016
Embed
What would you like to do?
/* -*- 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