diff -r da7c6dcafb43 -r 49362b34116c src/shared/util.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/shared/util.c Mon Dec 28 20:36:29 2009 +0200 @@ -0,0 +1,35 @@ +#include "util.h" + +#include + +int chfext (char *buf, size_t len, const char *newext) +{ + char *ext; + + // find .ext + if ((ext = strrchr(buf, '.')) == NULL) + return -1; + + // check length + if (ext + strlen(newext) >= buf + len) + return -1; + + // change to .foo + strcpy(ext, newext); + + // ok + return 0; +} + +int path_with_fext (const char *path, char *buf, size_t len, const char *newext) +{ + // verify length + if (strlen(path) > len) + return -1; + + // copy filename + strcpy(buf, path); + + // change fext + return chfext(buf, len, newext); +}