Skip to content

Commit

Permalink
Merge pull request #2 from syoyo/master
Browse files Browse the repository at this point in the history
Fix for windows from syoyo
  • Loading branch information
nrpatel committed Apr 8, 2012
2 parents cadc6ed + 367e738 commit da91a17
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ CC = gcc
CFLAGS = -O3 -Wall
LDFLAGS =

# gcc only
CCMACHINE = $(shell $(CC) -dumpmachine)

# On windows + mingw, link winsock2 lib.
ifeq ($(findstring mingw32, $(CCMACHINE)), mingw32)
LDFLAGS += -lws2_32
endif

.PHONY: all
all: lfpsplitter

Expand Down
5 changes: 5 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ the component jpgs.
Saved IMG_0001-stk_2.jpg
Saved IMG_0001-stk_3.jpg


On Windows + MinGW gcc compiler, you need to compile lfpsplitter with,

gcc.exe -o lfpspilitter.exe -O3 -Wall lfpsplitter.c -lwsock32

19 changes: 14 additions & 5 deletions lfpsplitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <winsock.h>
typedef unsigned int uint32_t;
#else
#include <arpa/inet.h>
#endif
#include "lfpsplitter.h"

#define SHA1_LENGTH 45
#define MAGIC_LENGTH 12
#define BLANK_LENGTH 35
#define STRING_LENGTH 256

#ifdef _MSC_VER
#define snprintf _snprintf
#endif

// TODO: read directly from the file instead of copying to a string
// since camera backup files can be in the hundreds of megabytes
static lfp_file_p lfp_create(const char *filename)
Expand All @@ -37,14 +46,14 @@ static lfp_file_p lfp_create(const char *filename)
return NULL;
}

if (!(fp = fopen(filename, "r"))) {
if (!(fp = fopen(filename, "rb"))) {
return NULL;
}

fseek(fp, 0, SEEK_END);
lfp->len = ftell(fp);
fseek(fp, 0, SEEK_SET);
lfp->data = malloc(lfp->len);
lfp->data = (char*)malloc(lfp->len);

lfp->len = fread(lfp->data, 1, lfp->len, fp);
fclose(fp);
Expand Down Expand Up @@ -115,7 +124,7 @@ static char *depth_string(const char *data, int *datalen, int len)
{
// make sure there is enough space for the ascii formatted floats
int filelen = 20*len/4;
char *depth = malloc(filelen);
char *depth = (char*)malloc(filelen);
char *start = depth;
int i = 0;

Expand All @@ -140,7 +149,7 @@ static char *converted_image(const unsigned char *data, int *datalen, int len)
{
int filelen = 4*len/3;
const unsigned char *ptr = data;
unsigned short *image = malloc(filelen*sizeof(short));
unsigned short *image = (unsigned short*)malloc(filelen*sizeof(short));
unsigned short *start = image;

if (!image) return NULL;
Expand Down Expand Up @@ -183,7 +192,7 @@ static void lfp_identify_section(lfp_file_p lfp, lfp_section_p section)
char jpeg[10] = {0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46};
char *ptr = NULL;
int quotecount = 0;
section->name = malloc(STRING_LENGTH);
section->name = (char*)malloc(STRING_LENGTH);

// Find the sha1 in the table of contents
if ((ptr = strstr(lfp->table->data, section->sha1))) {
Expand Down

0 comments on commit da91a17

Please sign in to comment.