make copy_file() globally available
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
de14570aea
commit
a205b87fa2
|
@ -26,66 +26,11 @@
|
||||||
*/
|
*/
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <fs.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <xfuncs.h>
|
#include <xfuncs.h>
|
||||||
#include <linux/stat.h>
|
#include <linux/stat.h>
|
||||||
#include <libbb.h>
|
#include <libbb.h>
|
||||||
|
#include <fs.h>
|
||||||
#define RW_BUF_SIZE (ulong)4096
|
#include <malloc.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* @param[in] src FIXME
|
|
||||||
* @param[out] dst FIXME
|
|
||||||
*/
|
|
||||||
static int copy_file(const char *src, const char *dst)
|
|
||||||
{
|
|
||||||
char *rw_buf = NULL;
|
|
||||||
int srcfd = 0, dstfd = 0;
|
|
||||||
int r, w;
|
|
||||||
int ret = 1;
|
|
||||||
|
|
||||||
rw_buf = xmalloc(RW_BUF_SIZE);
|
|
||||||
|
|
||||||
srcfd = open(src, O_RDONLY);
|
|
||||||
if (srcfd < 0) {
|
|
||||||
printf("could not open %s: %s\n", src, errno_str());
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
dstfd = open(dst, O_WRONLY | O_CREAT);
|
|
||||||
if (dstfd < 0) {
|
|
||||||
printf("could not open %s: %s\n", dst, errno_str());
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
r = read(srcfd, rw_buf, RW_BUF_SIZE);
|
|
||||||
if (r < 0) {
|
|
||||||
perror("read");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
if (!r)
|
|
||||||
break;
|
|
||||||
w = write(dstfd, rw_buf, r);
|
|
||||||
if (w < 0) {
|
|
||||||
perror("write");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
out:
|
|
||||||
free(rw_buf);
|
|
||||||
if (srcfd > 0)
|
|
||||||
close(srcfd);
|
|
||||||
if (dstfd > 0)
|
|
||||||
close(dstfd);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param[in] cmdtp FIXME
|
* @param[in] cmdtp FIXME
|
||||||
|
|
|
@ -26,4 +26,6 @@ int recursive_action(const char *fileName, unsigned flags,
|
||||||
|
|
||||||
char * safe_strncpy(char *dst, const char *src, size_t size);
|
char * safe_strncpy(char *dst, const char *src, size_t size);
|
||||||
|
|
||||||
|
int copy_file(const char *src, const char *dst);
|
||||||
|
|
||||||
#endif /* __LIBBB_H */
|
#endif /* __LIBBB_H */
|
||||||
|
|
|
@ -27,4 +27,4 @@ obj-$(CONFIG_GLOB) += fnmatch.o
|
||||||
obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
|
obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
|
||||||
obj-y += glob.o
|
obj-y += glob.o
|
||||||
obj-y += notifier.o
|
obj-y += notifier.o
|
||||||
|
obj-y += copy_file.o
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include <common.h>
|
||||||
|
#include <fs.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#define RW_BUF_SIZE (ulong)4096
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param[in] src FIXME
|
||||||
|
* @param[out] dst FIXME
|
||||||
|
*/
|
||||||
|
int copy_file(const char *src, const char *dst)
|
||||||
|
{
|
||||||
|
char *rw_buf = NULL;
|
||||||
|
int srcfd = 0, dstfd = 0;
|
||||||
|
int r, w;
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
|
rw_buf = xmalloc(RW_BUF_SIZE);
|
||||||
|
|
||||||
|
srcfd = open(src, O_RDONLY);
|
||||||
|
if (srcfd < 0) {
|
||||||
|
printf("could not open %s: %s\n", src, errno_str());
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
dstfd = open(dst, O_WRONLY | O_CREAT);
|
||||||
|
if (dstfd < 0) {
|
||||||
|
printf("could not open %s: %s\n", dst, errno_str());
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
r = read(srcfd, rw_buf, RW_BUF_SIZE);
|
||||||
|
if (r < 0) {
|
||||||
|
perror("read");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (!r)
|
||||||
|
break;
|
||||||
|
w = write(dstfd, rw_buf, r);
|
||||||
|
if (w < 0) {
|
||||||
|
perror("write");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
out:
|
||||||
|
free(rw_buf);
|
||||||
|
if (srcfd > 0)
|
||||||
|
close(srcfd);
|
||||||
|
if (dstfd > 0)
|
||||||
|
close(dstfd);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue