libcfe  0.12.1
some useful C-functions
mv.c
Go to the documentation of this file.
1 #include "config.h"
2 #include "mv.h"
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <errno.h>
8 #include <libintl.h>
9 
10 #include "create_path.h"
11 #include "output.h"
12 
13 int mv(const char *file, int file_len, const char *src, int src_len, const char *dest, int dest_len)
14 {
15  char *frompath = create_path(src, src_len, file, file_len);
16  char *topath = create_path(dest, dest_len, file, file_len);
17  if(rename(frompath, topath) != 0)
18  {
19  output(LOG_WARNING, _("cannot move file '%s' to '%s': %s"), frompath, topath, strerror(errno));
20  free(frompath);
21  frompath = NULL;
22  free(topath);
23  topath = NULL;
24  return -1;
25  }
26  free(frompath);
27  frompath = NULL;
28  free(topath);
29  topath = NULL;
30  return 0;
31 }
int mv(const char *file, int file_len, const char *src, int src_len, const char *dest, int dest_len)
Definition: mv.c:13
#define output
Definition: output.h:25
#define _(string)
Definition: output.h:43
char * create_path(const char *dir, int dirlen, const char *file, int filelen)
Definition: create_path.c:11