virtual - 2004-11-03

Hi,

I've met some problems while using dev-cpp(4.9.9.0): this piece of code didn't seem work correctly.

/*
* $0: copy file from @src to @dst, acording flag @flag
* @dst: dst position.
* @src: src position.
* flag: -
* retval: 0 on success, otherwise error
/

static int copy_file(const char dst, const char src, int flag)
{
int fd1, fd2, n = 0;
char buf[BUFSIZ + 1];
mode_t mode;
struct stat st;

    fd1 = open(src, O_RDONLY);
    if(fd1 < 0){
            return -1;
    }

    if(access(dst, F_OK) == 0){
            if(!(flag & CF_OVERWRITE)){
                    return 0;
            }
    }

    if(stat(src, &st) < 0){
            return -2;
    }

    mode = st.st_mode & 0777;

    fd2 = open(dst, O_WRONLY|O_CREAT|O_TRUNC, mode);

    if(fd2 < 0){
            return -3;
    }

    while((n = read(fd1, buf, BUFSIZ))){
            if(n < 0){
                    if(errno == EINTR)
                            continue;
                    break;
            }
            write(fd2, buf, n);
    }

    close(fd1);
    close(fd2);

    verbose("%36s <----- %36s\n", dst, src);

    return 0;

}

It worked fine under Linux(gcc), but while under Windoze dev-cpp(, gcc.exe(3.4.1) upgraded from dev-cpp's packman(2.2.5)), the file @dst & @src differ! no matter they are binary files or not. Would you please check it out please?

Thanks in advance!

p.s.

>c:\Dev-Cpp\bin\gcc.exe -v
Reading specs from c:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.1/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable
-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --e
nable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-ja
va-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchroniz
ation --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.1 (mingw special)