libite
Functions
copyfile.c File Reference
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include "lite.h"
Include dependency graph for copyfile.c:

Functions

ssize_t copyfile (const char *src, const char *dst, int len, int opt)
 Copy a file to another. More...
 
int movefile (const char *src, const char *dst)
 Move a file to another location. More...
 
int fcopyfile (FILE *src, FILE *dst)
 Copy between FILE *fp. More...
 

Detailed Description

Author
Claudio Matsuoka
Date
2008

Function Documentation

◆ copyfile()

ssize_t copyfile ( const char *  src,
const char *  dst,
int  len,
int  opt 
)

Copy a file to another.

Parameters
srcFull path name to source file.
dstFull path name to target file.
lenNumber of bytes to copy, zero (0) for entire file.
optAn option mask of LITE_FOPT_COPYFILE_SYM, LITE_FOPT_KEEP_MTIME

This is a C implementation of the command line cp(1) utility. It is one of the classic missing links in the UNIX C library. This version is from the finit project, http://helllabs.org/finit/, which is a reimplementation of fastinit for the Asus EeePC.

The opt field replaces the sym argument in previous releases and works as follows. To maintain backwards compatibility with sym the LITE_FOPT_COPYFILE_SYM has a value of 1. Supported option flags are:

Returns
The number of bytes copied, or zero, which may be an error (check errno, see Exceptions below), but it may also indicate that src was empty. See exceptions, below.
Exceptions
EISDIRif src is a directory, since copyfile() is not recursive.

◆ fcopyfile()

int fcopyfile ( FILE *  src,
FILE *  dst 
)

Copy between FILE *fp.

Parameters
srcSource FILE.
dstDestination FILE.
Returns
POSIX OK(0), or non-zero with errno set on error.

◆ movefile()

int movefile ( const char *  src,
const char *  dst 
)

Move a file to another location.

Parameters
srcSource file.
dstTarget file, or location.

This is a C implementation of the command line mv(1) utility. Usually the rename() API is sufficient, but not when moving across file system boundaries.

The src argument must include the full path to the source file, whereas the dst argument may only be a directory, in which case the same file name from src is used.

Returns
POSIX OK(0), or non-zero with errno set.