The following is a copy routine that can be used in gcc to copy a file or directory to another location while running a compile. I have this routine embedded in a .cpp file (alloc.cpp – this is just for testing to make sure the routine works) the routine will be used later in the compile that takes about 1 hour to build. I've defined “out” and now need to plug in the values for src_path =argv[1]; and dst_path = argv[2]; I've been unable to come up with the correct values for argv[1&2] and get the error indicated below. For testing purposes I'm using F:\4.0.37\testcopy for the destination path and F:\4.0.37\include\testfile.txt for the file to be copied.
Here is the routine in alloc.cpp:
* Header Files *
*******************************************************************************/
#define RTMEM_NO_WRAP_TO_EF_APIS
#define exit
#include <iprt/mem.h>
#include "internal/iprt.h"
#include <iprt/assert.h>
#include <iprt/string.h>
#include <stdio.h>
int main(int argn, char * argv[]) {
int src_fd, dst_fd, n, err;
unsigned char buffer[4096];
char * src_path, dst_path;
// Assume that the program takes two arguments the source path followed
// by the destination path.
if (argn != 3) {
printf("Wrong argument count.\n");
exit(1);
}
src_path = argv[1];
dst_path = /testcopy;
src_fd = open(src_path, O_RDONLY);
dst_fd = open(dst_path, O_CREAT | O_WRONLY);
while (1) {
err = read(src_fd, buffer, 4096);
if (err == -1) {
printf("Error reading file.\n");
exit(1);
}
n = err;
if (n == 0) break;
err = write(dst_fd, buffer, n);
if (err == -1) {
printf("Error writing to file.\n");
exit(1);
}
}
close(src_fd);
close(dst_fd);
}
RTDECL(void *) RTMemDupTag(const void *pvSrc, size_t cb, const char *pszTag) RT_NO_THROW
{
And here is the error output:
kBuild: Compiling filesplitter - F:/4.0.37/src/bldprogs/filesplitter.cpp
kBuild: Compiling RuntimeBldProg - F:/4.0.37/src/VBox/Runtime/common/alloc/alloc.
cpp
F:/4.0.37/src/VBox/Runtime/common/alloc/alloc.cpp: In function 'int main(int, cha
r**)':
F:/4.0.37/src/VBox/Runtime/common/alloc/alloc.cpp:59:22: error: invalid conversio
n from 'char*' to 'char' [-fpermissive]
dst_path = argv[2];
^
F:/4.0.37/src/VBox/Runtime/common/alloc/alloc.cpp:61:29: error: 'O_RDONLY' was no
t declared in this scope
src_fd = open(src_path, O_RDONLY);
Thanks in advance for any help
klipp