Skip to content

Commit

Permalink
Fixed some things and allowed more than one file/folder to be zipped
Browse files Browse the repository at this point in the history
  • Loading branch information
krystalgamer committed Jun 8, 2015
1 parent 2d09ac4 commit 89b21c3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*.i*86
*.x86_64
*.hex
realzip

# Debug files
*.dSYM/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = gcc
LIBS = -lz
CFLAGS = -Wall
CFLAGS = -Wall -std=gnu99
CFLAGS64 = -D_LARGEFILE64_SOURCE $(CFLAGS)
#all: main.o
# $(CC) $(CFLAGS64) -o final main.o zip.o ioapi.o $(LIBS)
Expand Down
6 changes: 4 additions & 2 deletions Makefile~
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = gcc
LIBS = -lz
CFLAGS = -Wall
CFLAGS = -Wall -std=c99
CFLAGS64 = -D_LARGEFILE64_SOURCE $(CFLAGS)
#all: main.o
# $(CC) $(CFLAGS64) -o final main.o zip.o ioapi.o $(LIBS)
Expand All @@ -15,4 +15,6 @@ create: ioapi.o zip.o main.o

%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS64) $(LIBS)


clean:
rm -rf *.o
51 changes: 35 additions & 16 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void *buffer; //The buffer used to read files
struct stat s;


uint32_t GetFileSize(FILE* fp)
uint64_t GetFileSize(FILE* fp)
{
uint32_t tmp;
uint64_t tmp;
fseeko64(fp, 0, SEEK_END);
tmp = ftello64(fp);
rewind(fp);
Expand All @@ -34,8 +34,8 @@ uint32_t GetFileSize(FILE* fp)

void ZipTheFile(zipFile* zf, char *filename)
{
int size_read = 1; // Ammount of bytes read
ull_int flsize = 0;
uint64_t size_read = 1; // Ammount of bytes read
uint64_t flsize = 0;
int written = 0;
FILE* fp;

Expand Down Expand Up @@ -96,7 +96,7 @@ void ZipTheFile(zipFile* zf, char *filename)

}

void RealZip(zipFile *zp, DIR **dir, char* filen)
void RealZipDir(zipFile *zp, DIR **dir, char* filen)
{
struct dirent *ent;
DIR* tmp;
Expand All @@ -120,7 +120,7 @@ void RealZip(zipFile *zp, DIR **dir, char* filen)
tmp = opendir(name);
if(tmp != NULL)
{
RealZip(zp, &tmp, name);//Recursive if finds another dir
RealZipDir(zp, &tmp, name);//Recursive if finds another dir
}


Expand Down Expand Up @@ -150,7 +150,7 @@ int main (int argc, char *argv[])
char path[256];


if(argc != 3)
if(argc < 3)
{
puts("HELL NO");
exit(2);
Expand All @@ -164,18 +164,37 @@ int main (int argc, char *argv[])
exit(1);
}

dir = opendir(argv[2]);
if(dir == NULL)
for(int i = 2; i<argc;i++)
{
#ifdef DEBUG

#else
printf("Error opening dir %s\n",argv[2]);
#endif
if( stat(argv[i],&s) == 0 )
{
if( s.st_mode & S_IFDIR )
{
dir = opendir(argv[i]);
if(dir != NULL)
{
strcpy(path, argv[i]);
RealZipDir(&zf, &dir, path);

}
else
{
#ifdef DEBUG
#else
printf("Error opening dir %s\n",argv[2]);
#endif
}
}
else
{

ZipTheFile(&zf, argv[i]);//Zip that shit up
}
}
}


strcpy(path, argv[2]);
RealZip(&zf, &dir, path);


closeZip(zf);
free(buffer);
Expand Down
51 changes: 35 additions & 16 deletions main.c~
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void *buffer; //The buffer used to read files
struct stat s;


uint32_t GetFileSize(FILE* fp)
uint64_t GetFileSize(FILE* fp)
{
uint32_t tmp;
uint64_t tmp;
fseeko64(fp, 0, SEEK_END);
tmp = ftello64(fp);
rewind(fp);
Expand All @@ -34,8 +34,8 @@ uint32_t GetFileSize(FILE* fp)

void ZipTheFile(zipFile* zf, char *filename)
{
int size_read = 1; // Ammount of bytes read
ull_int flsize = 0;
uint64_t size_read = 1; // Ammount of bytes read
uint64_t flsize = 0;
int written = 0;
FILE* fp;

Expand Down Expand Up @@ -96,8 +96,8 @@ void ZipTheFile(zipFile* zf, char *filename)

}

void RealZip(zipFile *zp, DIR **dir, char* filen)
{ printf("DD");
void RealZipDir(zipFile *zp, DIR **dir, char* filen)
{
struct dirent *ent;
DIR* tmp;
while((ent = readdir(*dir)))
Expand All @@ -120,7 +120,7 @@ void RealZip(zipFile *zp, DIR **dir, char* filen)
tmp = opendir(name);
if(tmp != NULL)
{
RealZip(zp, &tmp, name);//Recursive if finds another dir
RealZipDir(zp, &tmp, name);//Recursive if finds another dir
}


Expand Down Expand Up @@ -164,18 +164,37 @@ int main (int argc, char *argv[])
exit(1);
}

dir = opendir(argv[2]);
if(dir == NULL)
for(int i = 2; i<argc;i++)
{
#ifdef DEBUG

#else
printf("Error opening dir %s\n",argv[2]);
#endif
if( stat(argv[i],&s) == 0 )
{
if( s.st_mode & S_IFDIR )
{
dir = opendir(argv[i]);
if(dir != NULL)
{
strcpy(path, argv[i]);
RealZipDir(&zf, &dir, path);

}
else
{
#ifdef DEBUG
#else
printf("Error opening dir %s\n",argv[2]);
#endif
}
}
else
{

ZipTheFile(&zf, argv[i]);//Zip that shit up
}
}
}


strcpy(path, argv[2]);
RealZip(&zf, &dir, path);


closeZip(zf);
free(buffer);
Expand Down
Binary file modified realzip
Binary file not shown.

0 comments on commit 89b21c3

Please sign in to comment.