printf("Restlicher Platz in Bytes(%s): %lld (%lld %c)\n", output, splitgroesse, humanread, einheit);
}
-int cmpfunc(const void * a, const void * b)
+struct file_size
{
- if(*(long long unsigned int*)a < *(long long unsigned int*)b)
+ char name[255];
+ long long unsigned int fsize;
+};
+
+int cmpfunc(const void * filea, const void * fileb)
+{
+ long long unsigned int a = ((const struct file_size*)filea)->fsize;
+ long long unsigned int b = ((const struct file_size*)fileb)->fsize;
+ if(a < b)
return 1;
- if(*(long long unsigned int*)a > *(long long unsigned int*)b)
+ if(a > b)
return -1;
- if(*(long long unsigned int*)a == *(long long unsigned int*)b)
+ if(a == b)
return 0;
}
-long long unsigned int * filesize_sort(const char *input, const char *output)
+void filesize_sort(const char *input, const char *output)
{
FILE *in; FILE *out;
char pfad[255];
int lines = 0;
in = fopen(input, "r");
+ out = fopen(output, "w");
while(fscanf(in, "%[^\n]\n", pfad) == 1)
{
lines++;
}
fseek(in, 0L, SEEK_SET);
- long long unsigned int fsize[lines];
+ struct file_size fs[lines -1];
lines = 0;
while(fscanf(in, "%[^\n]\n", pfad) == 1)
{
stat(pfad, &st);
- fsize[lines++] = st.st_size;
+ strcpy(fs[lines].name, pfad);
+ fs[lines++].fsize = st.st_size;
+ }
+ qsort(fs, lines, sizeof(struct file_size), cmpfunc);
+ int i;
+ for(i = 0; i < lines; i++)
+ {
+ fprintf(out, "%s\n", fs[i].name);
}
- qsort(fsize, lines, sizeof(unsigned long long), cmpfunc);
- return fsize;
+ fclose(in);
+ fclose(out);
}
void usage()
}
}
- long long unsigned int *fsort = filesize_sort(input, rest);
- filecopy(input, rest);
+ filesize_sort(input, rest);
while(exists(rest) == 0)
{
sprintf(outname, "%s%03d",output , num++);