diff --git a/dist/ubuntu-env.sh b/dist/ubuntu-env.sh index 837c68a..170222b 100755 --- a/dist/ubuntu-env.sh +++ b/dist/ubuntu-env.sh @@ -1,6 +1,6 @@ #!/bin/bash -export HHVERSION="1.9.1" +export HHVERSION="1.9.10" export HHFULLVERSION=${HHVERSION}-0ubuntu1 export HH=hh_${HHVERSION} export HHRELEASE=hh_${HHFULLVERSION} @@ -9,10 +9,10 @@ export NOW=`date +%Y-%m-%d--%H-%M-%S` export HHBUILD=hstr-${NOW} ## https://wiki.ubuntu.com/Releases -export UBUNTUVERSION=precise +#export UBUNTUVERSION=precise #export UBUNTUVERSION=quantal #export UBUNTUVERSION=saucy -#export UBUNTUVERSION=trusty +export UBUNTUVERSION=trusty export HHBZRMSG="Favorites - favorite commands can be bookmarked and shown in a new view!" diff --git a/src/hstr_favorites.c b/src/hstr_favorites.c index 0a0fc4e..39a39b6 100644 --- a/src/hstr_favorites.c +++ b/src/hstr_favorites.c @@ -11,12 +11,12 @@ #include #include #include + #include "include/hstr_favorites.h" +#include "include/hstr_utils.h" #define FAVORITE_SEGMENT_SIZE 10 -extern char *strdup(const char *s); - void favorites_init(FavoriteItems *favorites) { favorites->items=NULL; @@ -68,7 +68,7 @@ void favorites_get(FavoriteItems *favorites) while(pe!=NULL) { favorites->items[i]=pb; *pe=0; - favorites->items[i]=(char *)strdup(pb); + favorites->items[i]=hstr_strdup(pb); pb=pe+1; pe=strchr(pb, '\n'); i++; @@ -115,11 +115,11 @@ void favorites_add(FavoriteItems *favorites, char *newFavorite) { if(favorites->count) { favorites->items=realloc(favorites->items, sizeof(char *) * ++favorites->count); - favorites->items[favorites->count-1]=strdup(newFavorite); + favorites->items[favorites->count-1]=hstr_strdup(newFavorite); favorites_choose(favorites, newFavorite); } else { favorites->items=malloc(sizeof(char*)); - favorites->items[0]=strdup(newFavorite); + favorites->items[0]=hstr_strdup(newFavorite); favorites->count=1; } diff --git a/src/hstr_utils.c b/src/hstr_utils.c index 7346be8..0589f74 100644 --- a/src/hstr_utils.c +++ b/src/hstr_utils.c @@ -8,11 +8,21 @@ */ #include "include/hstr_utils.h" + #include #define DEFAULT_COMMAND "pwd" #define PROC_HOSTNAME "/proc/sys/kernel/hostname" +// strdup() not in ISO C +char *hstr_strdup(const char * s) +{ + size_t len = 1+strlen(s); + char *p = malloc(len); + + return p ? memcpy(p, s, len) : NULL; +} + void tiocsti() { char buf[] = DEFAULT_COMMAND; diff --git a/src/include/hstr_utils.h b/src/include/hstr_utils.h index a4c7d48..2fd7a94 100644 --- a/src/include/hstr_utils.h +++ b/src/include/hstr_utils.h @@ -20,6 +20,7 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) +char *hstr_strdup(const char * s); void tiocsti(); void fill_terminal_input(char* cmd, bool padding); void reverse_char_pointer_array(char **array, unsigned length); diff --git a/tests/src/test_hashset.c b/tests/src/test_hashset.c index 6676938..4e6f70a 100644 --- a/tests/src/test_hashset.c +++ b/tests/src/test_hashset.c @@ -8,6 +8,7 @@ */ #include "../src/include/hashset.h" +#include "../src/include/hstr_utils.h" void testBlacklist() { const char* commandBlacklist[] = { }; @@ -19,7 +20,7 @@ void testBlacklist() { } for (i = 0; i < 5; i++) { printf("match %d\n", - hashset_contains(&blacklist, strdup(commandBlacklist[i]))); + hashset_contains(&blacklist, hstr_strdup(commandBlacklist[i]))); } }