cc tscopy.c dont work
/hdd # ./tscopy
./tscopy: ./tscopy: 1: Syntax error: "(" unexpected
/hdd #
Code: Alles auswählen
#include "tscopy.h"
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
int copyfile(const char *q, const char *z)
{
FILE *fpq, *fpz;
char buf[4096];
off_t zpos;
int count;
if (!(fpz = fopen(z, "ab")))
{
printf("Error whilst generating the Destination File: %s\n", z);
return 0;
}
fseeko(fpz, (off_t) 0, SEEK_CUR);
zpos = ftello(fpz);
fpq = fopen(q, "rb");
fseeko(fpq, zpos, SEEK_SET);
printf("Write %s from Position %lld\n", z, zpos);
while (!feof(fpq))
{
count = fread(buf, 1, sizeof(buf), fpq);
fwrite(buf, count, 1, fpz);
}
fclose(fpq); fclose(fpz);
return 0;
}
int main(int argc, char* argv[])
{
if (argc < 3)
{
printf("Call via %s <Originating Directory> <Destination Directory>\n", argv[0]);
return 1;
}
DIR *dir;
struct dirent *entry;
struct stat fpstat;
char arg1[1024];
char arg2[1024];
char a1tmp[1024];
char a2tmp[1024];
int l1, l2;
if (!(dir=opendir(argv[1])))
{
printf("Error whilst accessing the originating Directory: %s\n", argv[1]);
return 2;
}
strcpy(arg1, argv[1]);
strcpy(arg2, argv[2]);
l1 = strlen(arg1); l2 = strlen(arg2);
if (strcmp(&arg1[l1-1], "/") != 0) strcat(arg1, "/");
if (strcmp(&arg2[l2-1], "/") != 0) strcat(arg2, "/");
strcpy(a1tmp, arg1); strcpy(a2tmp, arg2);
do
{
if (entry = readdir(dir))
{
stat(strcat(arg1, entry->d_name), &fpstat);
if ((fpstat.st_mode & S_IFMT) == S_IFREG)
copyfile(arg1, strcat(arg2,entry->d_name));
strcpy(arg1, a1tmp); strcpy(arg2, a2tmp);
}
} while (entry);
closedir(dir);
return 0;
}