sbase/fs.h
FRIGN 58098575e7 Audit cp() in libutil
1) Rename cp_HLPflag -> cp_follow for consistency.
2) Use function-pointers for stat to clear up the code.
3) BUGFIX: TERMINATE THE RESULT BUFFER OF READLINK !!!
   It's something I noticed earlier and it actually lead to some
   pretty insane behaviour on our side using glibc (musl somehow
   magically solves this).
   Basically, symlinks used to contain the data of the file they
   pointed to. I wondered for weeks where this came from and now
   this has finally been solved.
4) BUGFIX: Do not unconditionally unlink target-files. Even GNU
   coreutils do it wrong.
   The basic idea is this:
   If fflag == 0 --> don't touch target files if they exist.
   If fflag == 1 --> unlink all and don't error out when we try
                     to unlink a file which doesn't exist.
5) Use estrlcpy and estrlcat instead of snprintf for path building.
6) Make it clearer what happens in preserve.
2015-03-19 17:57:12 +01:00

41 lines
825 B
C

/* See LICENSE file for copyright and license details. */
#include <sys/stat.h>
#include <sys/types.h>
struct history {
struct history *prev;
dev_t dev;
ino_t ino;
};
struct recursor {
void (*fn)(const char *, struct stat *st, void *, struct recursor *);
struct history *hist;
int depth;
int follow;
int flags;
};
enum {
SAMEDEV = 1 << 0,
};
extern int cp_aflag;
extern int cp_fflag;
extern int cp_pflag;
extern int cp_rflag;
extern int cp_vflag;
extern int cp_follow;
extern int cp_status;
extern int rm_fflag;
extern int rm_rflag;
extern int rm_status;
extern int recurse_status;
void recurse(const char *, void *, struct recursor *);
int cp(const char *, const char *, int);
void rm(const char *, struct stat *st, void *, struct recursor *);