utils/files.c
int copy_file(char* src, char* dst)
{
    /* Used variables */
    int input, output, flags, ret = 1;
    mode_t perms;
    ssize_t size;
    char buf[1024];
 
    /* Open input */
    input = open(src, O_RDONLY);
    if (input == -1) return -1;
 
    /* Set flags */
    flags = O_CREAT | O_WRONLY | O_TRUNC;
    perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;

    /* Open output */
    output = open(dst, flags, perms);
    if (output != -1) 
    {
        while ((size = read(input, buf, 1024)) > 0) 
        {
            if (write(output, buf, size) != size) 
            {
                ret = 0;
                break;
            }
        }

        if (size == -1) ret = 0;
        close(output);
    }
    close(input);
 
    return ret;
}
/* 
 * copy_file - Copy file from source to destination. Argument src is path of 
 * source file which we want to copy and argument dst is destination path of 
 * new file. On success return walue is 1, otherwise function returns -1 if 
 * can not open source file and 0 if can not copy to destination file..
 */
Copy file from source to destination. Argument src is path of
source file which we want to copy and argument dst is destination path of
new file. On success return walue is 1, otherwise function returns -1 if
can not open source file and 0 if can not copy to destination file
Copy file from source to destination . Argument src is path of source file which we want to copy and argument dst is destination path of new file . On success return walue is 1 otherwise function returns - 1 if can not open source file and 0 if can not copy to destination file
int copy_file(char* src, char* dst)
{
    int input, output, flags, ret = 1;
    mode_t perms;
    ssize_t size;
    char buf[1024];
    input = open(src, O_RDONLY);
    if (input == -1) return -1;
    flags = O_CREAT | O_WRONLY | O_TRUNC;
    perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
    output = open(dst, flags, perms);
    if (output != -1) 
    {
        while ((size = read(input, buf, 1024)) > 0) 
        {
            if (write(output, buf, size) != size) 
            {
                ret = 0;
                break;
            }
        }
        if (size == -1) ret = 0;
        close(output);
    }
    close(input);
    return ret;
}
int copy_file ( char * src , char * dst ) { int input , output , flags , ret = 1 ; mode_t perms ; ssize_t size ; char buf [ 1024 ] ; input = open ( src , O_RDONLY ) ; if ( input == -1 ) return -1 ; flags = O_CREAT | O_WRONLY | O_TRUNC ; perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH ; output = open ( dst , flags , perms ) ; if ( output != -1 ) { while ( ( size = read ( input , buf , 1024 ) ) > 0 ) { if ( write ( output , buf , size ) != size ) { ret = 0 ; break ; } } if ( size == -1 ) ret = 0 ; close ( output ) ; } close ( input ) ; return ret ; }
copy_file - Copy file from source to destination.
copy_file - Copy file from source to destination .
/* Used variables */ /* Open input */ /* Set flags */ /* Open output */