Skip to content

Commit

Permalink
memset for icu plus backup
Browse files Browse the repository at this point in the history
  • Loading branch information
jayridge committed Dec 20, 2012
1 parent f350ab1 commit d889aa1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ LIBSIMPLEHTTP ?= ../simplehttp
UNAME := $(shell uname)

CFLAGS = -I$(LIBEVENT)/include -Wall -g -O0
LIBS = -L$(LIBEVENT)/lib -levent -lm -lpthread -ljson -licui18n -licuuc -licudata
LIBS = -L$(LIBEVENT)/lib -ljson -licui18n -licuuc -licudata -levent -ljson -lpthread -lm -ldl -lstdc++

ifeq ($(UNAME), Linux)
LIBS += -static
LIBS += -lrt
endif


Expand All @@ -20,3 +20,4 @@ install:

clean:
rm -rf *.a *.o autocomplete *.dSYM test_output test.db

11 changes: 7 additions & 4 deletions autocomplete.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,13 @@ char *utf8_tolower(char *s, char *locale)
UChar *buf = NULL;
char *buf2 = NULL;
UErrorCode err = U_ZERO_ERROR;
int32_t len, len2;
int32_t len = 0, len2 = 0;

u_strFromUTF8(NULL, 0, &len, s, -1, &err);
buf = malloc(sizeof(UChar) * len+1);
memset(buf, 0, sizeof(UChar) * len+1);
err = U_ZERO_ERROR;
u_strFromUTF8(buf, len+1, &len, s, -1, &err);
u_strFromUTF8(buf, len+1, NULL, s, -1, &err);
if (U_FAILURE(err)) {
fprintf(stderr, "u_strFromUTF8 failed: %s: %s\n", s, u_errorName(err));
free(buf);
Expand All @@ -237,7 +238,8 @@ char *utf8_tolower(char *s, char *locale)
err = U_ZERO_ERROR;
len2 = u_strToLower(NULL, 0, (UChar *)buf, -1, locale, &err);
if (len2 > len) {
buf = realloc(buf, len2+1);
buf = realloc(buf, sizeof(UChar *) * len2+1);
memset(buf, 0, sizeof(UChar) * len2+1);
}
err = U_ZERO_ERROR;
u_strToLower(buf, len2+1, (UChar *)buf, -1, locale, &err);
Expand All @@ -249,7 +251,8 @@ char *utf8_tolower(char *s, char *locale)

err = U_ZERO_ERROR;
u_strToUTF8(NULL, 0, &len, buf, -1, &err);
buf2 = malloc(sizeof(char) * len+1);
buf2 = malloc(sizeof(char *) * len+1);
memset(buf2, 0, sizeof(char *) * len+1);
err = U_ZERO_ERROR;
u_strToUTF8(buf2, len+1, &len, (UChar *)buf, -1, &err);
if (U_FAILURE(err)) {
Expand Down
27 changes: 27 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

if [ "$#" -lt 2 ]; then
echo "usage: $0 db_root backup_root [nsmhdw]"
echo "n shhdw as -atime in find"
exit 1
fi

DBROOT=$1
BACKUPROOT=$2
MTIME=false
if [ "$#" -gt 2 ]; then
MTIME=true
INTERVAL=$3
fi

DATESTAMP=`date +%Y%m%d_%H%M`
BACKUPFILE=autocomplete.$DATESTAMP.$INTERVAL.tgz

mkdir -p $BACKUPROOT

if $MTIME; then
find $DBROOT -mtime $INTERVAL | tar -cjvf $BACKUPROOT/$BACKUPFILE
else
tar -cjvf $BACKUPROOT/$BACKUPFILE
fi

0 comments on commit d889aa1

Please sign in to comment.