basically coping the java version to c (naturally this does not compile)

Signed-off-by: Mattias Andrée <maandree@operamail.com>