# garmintools on FreeBSD 8.1



## slaney (Sep 6, 2010)

Hello,

I have gotten garmintools (http://code.google.com/p/garmintools/) to compile and work on FreeBSD 8.1, however I had to hard code a path in the source to make it work, and was hoping someone here might be able to give me some ideas for why the original source isn't working.

After changing the configure script to not rely on libusb-config, the source compiles and installs with a make/make install.

However it seg faults when you run `garmin_save_runs`.


```
# garmin_save_runs 
Extracting data from Garmin Forerunner305 Software Version 2.90
Segmentation fault: 11 (core dumped)
```

Firing up gdb, I can see where the problem is:


```
#4  0x000000080065de63 in garmin_save_runs (garmin=0x7fffffffea90) at run.c:219
```

That line is: 


```
printf("Files will be saved in '%s'\n",filedir);
```


The prototype, and assignment of filedir/path are:


```
char *              filedir = NULL;
  char                path[PATH_MAX];
```


```
if ( filedir == NULL ) {
    filedir = getcwd(path,sizeof(path));
  }
```

And if I set a breakpoint and attempt to dump either filedir or path, I get some weird behavior:


```
Breakpoint 1, garmin_save_runs (garmin=0x7fffffffea90) at run.c:219
219       printf("Files will be saved in '%s'\n",filedir);
(gdb) p filedir
$3 = 0xffffffffffffe230 <Error reading address 0xffffffffffffe230: Bad address>
(gdb) p path
$4 = "/root\000\000\000\001", '\0' <repeats 15 times>, "\\ZP\000\b\000\000\0002Ã©6
\n\000\000\000\000\001\000\000\000\000\000\000\0000\000S\000\b", '\0' <repeats 
15 times>, "\b\000\002\000\000\000\000\000\000\000\000\000\200Ã£Ã¿Ã¿Ã¿\177\000\000gO
\226\000\b\000\000\000Ã˜Ã£Ã¿Ã¿Ã¿\177\000\000\bÃ¤Ã¿Ã¿Ã¿\177\000\000\000\000\000\000\000
\000\000\000gO\226\000\b\000\000\000Ã¸Ã£Ã¿Ã¿Ã¿\177\000\000(Ã¤Ã¿Ã¿Ã¿\177\000\000\000
\000\000\000\000\000\000\000Ã¸Ã£Ã¿Ã¿Ã¿\177\000\000u\000\000\000\000\000\000\0000B
\227\000\b\000\000\000\001\000\000\000\000\000\000\000\001\000\000\000\000\000
\000\000 Ã§Ã¿Ã¿Ã¿\177\000\000[\203\225\000\b\000\000\000\t\000"...
```

I tried just creating a little C file that used getcwd() to see if I could get the same behavior, but I can not.

If I just comment out all that other stuff, and put 'filedir = "/tmp/foo";', it works fine. 

I am not a C programmer by any stretch, so I was hoping maybe someone here had some ideas as to what might cause this.

Thanks!


----------



## DutchDaemon (Sep 7, 2010)

[ bump, was stuck in mod queue ]


----------



## slaney (Sep 9, 2010)

I figured out how to fix it, though the reasons it works are something I am going to read up on.

Patch here:  http://gist.github.com/571781

tl;dr: needed to use unistd.h to make getcwd() behave.


----------

