cp.c File Reference

#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <sys/stat.h>
#include <utime.h>
#include <dirent.h>
#include <errno.h>
#include <assert.h>
#include <sys/dir.h>

Include dependency graph for cp.c:

Go to the source code of this file.

Data Structures

struct  pathname
struct  entrylist

Defines

#define nil   0
#define DEBUG   0
#define NDEBUG   1
#define CHUNK   (1024 << (sizeof(int) + sizeof(char *)))
#define CONFORMING   1
#define arraysize(a)   (sizeof(a) / sizeof((a)[0]))
#define arraylimit(a)   ((a) + arraysize(a))
#define S_ISLNK(mode)   (0)
#define lstat   stat
#define symlink(path1, path2)   (errno= ENOSYS, -1)
#define readlink(path, buf, len)   (errno= ENOSYS, -1)
#define path_name(pp)   ((const char *) (pp)->path)
#define path_length(pp)   ((pp)->idx)
#define path_drop(pp)   deallocate((void *) (pp)->path)
#define PATH_MAX   1024

Typedefs

typedef enum identity identity_t
typedef enum action action_t
typedef pathname pathname_t
typedef entrylist entrylist_t

Enumerations

enum  identity {
  CP, MV, RM, LN,
  CPDIR, CLONE
}
enum  action { COPY, MOVE, REMOVE, LINK }

Functions

void report (const char *label)
void fatal (const char *label)
void report2 (const char *src, const char *dst)
void * allocate (void *mem, size_t size)
void deallocate (void *mem)
void path_init (pathname_t *pp)
void path_add (pathname_t *pp, const char *name)
void path_trunc (pathname_t *pp, size_t didx)
char * basename (const char *path)
int affirmative (void)
int writable (const struct stat *stp)
static char * link_islink (struct stat *stp, const char *file)
int trylink (const char *src, const char *dst, struct stat *srcst, struct stat *dstst)
int copy (const char *src, const char *dst, struct stat *srcst, struct stat *dstst)
void copy1 (const char *src, const char *dst, struct stat *srcst, struct stat *dstst)
void remove1 (const char *src, struct stat *srcst)
void link1 (const char *src, const char *dst, struct stat *srcst, struct stat *dstst)
int eat_dir (const char *dir, entrylist_t **dlist)
void chop_dlist (entrylist_t **dlist)
void drop_dlist (entrylist_t *dlist)
void do1 (pathname_t *src, pathname_t *dst, int depth)
void usage (void)
void main (int argc, char **argv)

Variables

char * prog_name
int ex_code = 0
identity_t identity
action_t action
int pflag = 0
int iflag = 0
int fflag = 0
int sflag = 0
int Sflag = 0
int mflag = 0
int rflag = 0
int vflag = 0
int xflag = 0
int xdev = 0
int expand = 0
int conforming = CONFORMING
int fc_mask
int uid
int gid
int istty


Define Documentation

#define arraylimit a   )     ((a) + arraysize(a))
 

Definition at line 43 of file cp.c.

#define arraysize a   )     (sizeof(a) / sizeof((a)[0]))
 

Definition at line 42 of file cp.c.

#define CHUNK   (1024 << (sizeof(int) + sizeof(char *)))
 

Definition at line 33 of file cp.c.

Referenced by add(), bload(), bopen(), bskip(), build_index(), copy(), def(), extract(), gzcopy(), gzscan(), gztack(), inf(), main(), new_block(), reader(), and slave().

#define CONFORMING   1
 

Definition at line 38 of file cp.c.

#define DEBUG   0
 

Definition at line 22 of file cp.c.

#define lstat   stat
 

Definition at line 73 of file cp.c.

#define NDEBUG   1
 

Definition at line 23 of file cp.c.

#define nil   0
 

Definition at line 8 of file cp.c.

#define path_drop pp   )     deallocate((void *) (pp)->path)
 

Definition at line 189 of file cp.c.

Referenced by add(), link1(), and main().

#define path_length pp   )     ((pp)->idx)
 

Definition at line 188 of file cp.c.

Referenced by apply_differences(), apply_remove(), do1(), link1(), main(), readstate(), recurse_dir(), and traverse().

#define PATH_MAX   1024
 

Definition at line 238 of file cp.c.

Referenced by addpath(), check_mtab(), chksymlinkzone(), decode_message(), descend(), diff_recursive(), do_exec(), fetch_name(), find(), find_bin(), finddev(), fpathconf(), fts_open(), get_data(), get_name(), iruserok(), link_islink(), list(), ltraverse(), main(), makelongnames(), makepath(), patch_stack(), tellstatus(), test21a(), test23a(), test23b(), test23c(), test25e(), test30c(), test31c(), test32b(), test33c(), update_mtab(), and work().

#define path_name pp   )     ((const char *) (pp)->path)
 

Definition at line 187 of file cp.c.

Referenced by add(), add_file(), apply_add(), apply_differences(), apply_link(), apply_remove(), do1(), is_added(), link1(), readstate(), and traverse().

#define readlink path,
buf,
len   )     (errno= ENOSYS, -1)
 

Definition at line 75 of file cp.c.

Referenced by add_file(), copy1(), file(), link1(), print1(), and rdlink().

#define S_ISLNK mode   )     (0)
 

Definition at line 72 of file cp.c.

#define symlink path1,
path2   )     (errno= ENOSYS, -1)
 

Definition at line 74 of file cp.c.

Referenced by add(), apply_add(), copy1(), extract(), link1(), and node_creat().


Typedef Documentation

typedef enum action action_t
 

typedef struct entrylist entrylist_t
 

typedef enum identity identity_t
 

typedef struct pathname pathname_t
 


Enumeration Type Documentation

enum action
 

Enumerator:
COPY 
MOVE 
REMOVE 
LINK 

Definition at line 49 of file cp.c.

enum identity
 

Enumerator:
CP 
MV 
RM 
LN 
CPDIR 
CLONE 

Definition at line 48 of file cp.c.


Function Documentation

int affirmative void   ) 
 

Definition at line 210 of file cp.c.

References c, EOF, fflush(), getchar, ok(), stderr, and stdout.

Referenced by copy(), copy1(), do1(), link1(), and remove1().

void* allocate void *  mem,
size_t  size
 

Definition at line 101 of file cp.c.

References fatal(), malloc(), nil, and realloc().

char* basename const char *  path  ) 
 

Definition at line 192 of file cp.c.

References p.

void chop_dlist entrylist_t **  dlist  ) 
 

Definition at line 851 of file cp.c.

References deallocate, entrylist::name, and entrylist::next.

Referenced by do1(), and drop_dlist().

int copy const char *  src,
const char *  dst,
struct stat srcst,
struct stat dstst
 

Definition at line 372 of file cp.c.

References utimbuf::actime, affirmative(), assert, bp, chmod, chown, CHUNK, close, conforming, COPY, EACCES, ENOENT, EPERM, errno, fatal(), fc_mask, fflag, fprintf(), fstat, iflag, utimbuf::modtime, n, nil, O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY, open, pflag, printf, prog_name, r, read, report(), S_IFREG, S_ISREG, S_IWUSR, stat::st_atime, stat::st_gid, stat::st_ino, stat::st_mode, stat::st_mtime, stat::st_uid, stderr, time, trylink(), unlink, utime, vflag, writable, and write.

void copy1 const char *  src,
const char *  dst,
struct stat srcst,
struct stat dstst
 

Definition at line 546 of file cp.c.

References utimbuf::actime, affirmative(), assert, chown, conforming, copy, EISDIR, EPERM, errno, ex_code, expand, fc_mask, fflag, fprintf(), iflag, linked(), lstat, mkfifo, mknod, utimbuf::modtime, nil, pflag, printf, prog_name, r, readlink, report(), rflag, S_ISBLK, S_ISCHR, S_ISDIR, S_ISFIFO, S_ISLNK, S_ISREG, stat::st_atime, stat::st_dev, stat::st_gid, stat::st_ino, stat::st_mode, stat::st_mtime, stat::st_rdev, stat::st_uid, stderr, symlink, time, trylink(), unlink, utime, vflag, and writable.

Referenced by do1().

void deallocate void *  mem  ) 
 

Definition at line 112 of file cp.c.

References free, and nil.

void do1 pathname_t src,
pathname_t dst,
int  depth
 

Definition at line 867 of file cp.c.

References utimbuf::actime, affirmative(), chmod, chop_dlist(), chown, conforming, COPY, copy1(), drop_dlist(), eat_dir(), EEXIST, EISDIR, ENOENT, ENOTDIR, ENOTEMPTY, EPERM, errno, ex_code, EXDEV, expand, fc_mask, fflag, flags, fprintf(), iflag, LINK, link1(), lstat, mflag, mkdir, utimbuf::modtime, nil, path_add(), path_length, path_name, path_trunc(), pflag, printf, prog_name, REMOVE, remove1(), rename, report(), report2(), rflag, rmdir, S_IRWXU, S_ISDIR, Sflag, sflag, stat::st_atime, stat::st_dev, stat::st_gid, stat::st_ino, stat::st_mode, stat::st_mtime, stat::st_uid, stderr, time, unlink, utime, vflag, writable, xdev, and xflag.

Referenced by main().

void drop_dlist entrylist_t dlist  ) 
 

Definition at line 861 of file cp.c.

References chop_dlist(), and nil.

Referenced by do1().

int eat_dir const char *  dir,
entrylist_t **  dlist
 

Definition at line 829 of file cp.c.

References allocate(), closedir, entry, nil, opendir, readdir, strcmp, strcpy(), and strlen().

Referenced by do1(), eat_dir(), and main().

void fatal const char *  label  ) 
 

Definition at line 85 of file cp.c.

References exit(), and report().

void link1 const char *  src,
const char *  dst,
struct stat srcst,
struct stat dstst
 

Definition at line 696 of file cp.c.

References affirmative(), EISDIR, errno, ex_code, EXDEV, exit(), fflag, fprintf(), iflag, link, p, path_add(), path_drop, path_init(), path_length, path_name, path_trunc(), printf, prog_name, r, readlink, report(), report2(), rflag, S_ISDIR, S_ISLNK, Sflag, sflag, stat::st_ino, stat::st_mode, stderr, sym, symlink, unlink, vflag, and xdev.

Referenced by do1().

static char* link_islink struct stat stp,
const char *  file
[static]
 

Definition at line 241 of file cp.c.

References arraylimit, close, dev, free, link::ino, lp, link::next, nil, off, and PATH_MAX.

Referenced by islink(), and trylink().

void main int  argc,
char **  argv
 

Definition at line 1199 of file cp.c.

References assert, basename, CLONE, conforming, COPY, CP, CPDIR, do1(), ex_code, exit(), expand, fc_mask, fflag, flags, fprintf(), getegid, geteuid, gid, i, iflag, isatty, istty, LINK, LN, mflag, MV, nil, path_add(), path_drop, path_init(), path_length, path_trunc(), pflag, prog_name, REMOVE, rflag, RM, S_ISDIR, Sflag, sflag, slash(), st, stat::st_mode, stat, stderr, strchr, strcmp, uid, umask, usage, vflag, and xflag.

void path_add pathname_t pp,
const char *  name
 

Definition at line 136 of file cp.c.

References allocate(), pathname::idx, pathname::lim, p, pathname::path, and strlen().

Referenced by add(), apply_differences(), apply_remove(), do1(), link1(), main(), readstate(), and traverse().

void path_init pathname_t pp  ) 
 

Definition at line 129 of file cp.c.

References allocate(), DIRSIZ, pathname::idx, pathname::lim, nil, and pathname::path.

Referenced by add(), apply_differences(), link1(), main(), readstate(), and traverse().

void path_trunc pathname_t pp,
size_t  didx
 

Definition at line 161 of file cp.c.

References pathname::idx, and pathname::path.

Referenced by apply_differences(), apply_remove(), do1(), link1(), main(), readstate(), and traverse().

void remove1 const char *  src,
struct stat srcst
 

Definition at line 682 of file cp.c.

References affirmative(), fflag, fprintf(), iflag, printf, report(), stat::st_mode, stderr, unlink, vflag, and writable.

Referenced by do1().

void report const char *  label  ) 
 

Definition at line 78 of file cp.c.

References errno, ex_code, fflag, fprintf(), prog_name, REMOVE, stderr, and strerror().

void report2 const char *  src,
const char *  dst
 

Definition at line 91 of file cp.c.

References errno, ex_code, fprintf(), prog_name, stderr, and strerror().

Referenced by do1(), and link1().

int trylink const char *  src,
const char *  dst,
struct stat srcst,
struct stat dstst
 

Definition at line 349 of file cp.c.

References COPY, expand, link, link_islink(), linked(), nil, printf, stat::st_ino, unlink, and vflag.

Referenced by copy(), and copy1().

void usage void   ) 
 

Definition at line 1164 of file cp.c.

References CLONE, CP, CPDIR, exit(), fprintf(), LN, MV, nil, prog_name, RM, and stderr.

int writable const struct stat stp  ) 
 

Definition at line 226 of file cp.c.

References gid, istty, S_IWGRP, S_IWOTH, S_IWUSR, stat::st_gid, stat::st_mode, stat::st_uid, and uid.


Variable Documentation

action_t action
 

Definition at line 52 of file cp.c.

int conforming = CONFORMING
 

Definition at line 64 of file cp.c.

Referenced by copy(), copy1(), do1(), and main().

int ex_code = 0
 

Definition at line 46 of file cp.c.

Referenced by copy1(), do1(), link1(), main(), report(), and report2().

int expand = 0
 

Definition at line 63 of file cp.c.

Referenced by copy1(), do1(), docmds1(), eval(), evalstr(), find_device(), macro(), main(), mcat(), mformat(), and trylink().

int fc_mask
 

Definition at line 66 of file cp.c.

Referenced by copy(), copy1(), do1(), and main().

int fflag = 0
 

Definition at line 55 of file cp.c.

int gid
 

Definition at line 67 of file cp.c.

Referenced by display_attrib(), do_chown(), getids(), grp_add(), main(), permissions(), test34a(), test34c(), test35c(), and writable().

identity_t identity
 

Definition at line 51 of file cp.c.

int iflag = 0
 

Definition at line 54 of file cp.c.

int istty
 

Definition at line 68 of file cp.c.

int mflag = 0
 

Definition at line 58 of file cp.c.

int pflag = 0
 

Definition at line 53 of file cp.c.

char* prog_name
 

Definition at line 45 of file cp.c.

int rflag = 0
 

Definition at line 59 of file cp.c.

int Sflag = 0
 

Definition at line 57 of file cp.c.

Referenced by do1(), link1(), and main().

int sflag = 0
 

Definition at line 56 of file cp.c.

int uid
 

Definition at line 67 of file cp.c.

Referenced by display_attrib(), do_chown(), get_homedir(), getids(), main(), permissions(), recover(), test34a(), test34c(), test35c(), usr_add(), and writable().

int vflag = 0
 

Definition at line 60 of file cp.c.

int xdev = 0
 

Definition at line 62 of file cp.c.

Referenced by do1(), link1(), and traverse().

int xflag = 0
 

Definition at line 61 of file cp.c.


Generated on Fri Apr 14 23:06:22 2006 for minix by  doxygen 1.4.6