k9core

Coreutils for *nix operating systems [fork]
git clone git://bvnf.space/k9core.git
Log | Files | Refs | LICENSE

mv.c (806B)


      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
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

/*
int
move(const char *src, const char *dst)
{
  int source = open(src,O_RDONLY);
  int destination = creat(dst,0644);

  if(destination == -1)
    {
	 printf("Error opening destination file\n");
	 return 1;
    }
  if(source == -1)
    {
	 printf("Error opening source file\n");
	 return 1;
    }
  int lines;
  char buf[8912];
  while((lines = read(source,buf,sizeof(buf))) > 0)
    write(destination,buf,lines);
  close(destination); close(source);
  return 0;
}
*/
int
main(int argc, char *argv[])
{
	if(argc != 3) {
		fprintf(stderr, "usage: mv source destination\n");
		return 1;
	} else if(rename(argv[1], argv[2]) == -1) {
		fprintf(stderr, "mv: %s\n", strerror(errno));
		return 1;
	}
	return 0;
}