All pastes #868245 Raw Edit

kestaz

public c v1 · immutable
#868245 ·published 2008-01-22 08:33 UTC
rendered paste body
/*kestaz:~ kestaz$ ./hacked_cp freedos.img /Users/kestaz/namas.ppc 163840||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||Finishednot tested use by your own ...*/#include <stdio.h>#include <sys/stat.h>#include <math.h>/* my simple implementation of cp */ typedef unsigned char uchar ;unsigned long get_file_size(char *) ; int main(int argc, char **argv){    FILE *fd ;     FILE *dd ;     uchar buffer[1024] ;         unsigned long size = 0 ;     if (argc == 3)    {        if ((fd = fopen(argv[1], "r")))        {            size = get_file_size(argv[1]) ;             printf("%d\n", size) ;              dd = fopen(argv[2], "w") ;                         double t= size / 1024.0 / 100.0  ;                         long k = round(t) ;             if (dd)            {                int i = 0 ;                 while (fread(buffer, sizeof(buffer), 1,fd))                {                    if (i % k == 0) printf("|") ;                    fwrite(buffer, sizeof(buffer), 1, dd)  ;                    ++i;                  }                printf("\nFinished\n") ;                close(dd) ;                close(fd) ;             }        }            else printf("file open error\n") ;            }     else printf("use two arguments\n") ;     return 0  ; }unsigned long get_file_size(char *s) {    struct stat file ;    if (!stat(s, &file)) return file.st_size ; }