terom@4: #include "util.h" terom@4: terom@4: #include terom@4: terom@4: int chfext (char *buf, size_t len, const char *newext) terom@4: { terom@4: char *ext; terom@4: terom@4: // find .ext terom@4: if ((ext = strrchr(buf, '.')) == NULL) terom@4: return -1; terom@4: terom@4: // check length terom@4: if (ext + strlen(newext) >= buf + len) terom@4: return -1; terom@4: terom@4: // change to .foo terom@4: strcpy(ext, newext); terom@4: terom@4: // ok terom@4: return 0; terom@4: } terom@4: terom@4: int path_with_fext (const char *path, char *buf, size_t len, const char *newext) terom@4: { terom@4: // verify length terom@4: if (strlen(path) > len) terom@4: return -1; terom@4: terom@4: // copy filename terom@4: strcpy(buf, path); terom@4: terom@4: // change fext terom@4: return chfext(buf, len, newext); terom@4: }