--- a/src/shared/util.c Tue Dec 29 15:38:31 2009 +0200
+++ b/src/shared/util.c Tue Dec 29 16:44:48 2009 +0200
@@ -1,18 +1,23 @@
#include "util.h"
#include <string.h>
+#include <errno.h>
int chfext (char *buf, size_t len, const char *newext)
{
char *ext;
// find .ext
- if ((ext = strrchr(buf, '.')) == NULL)
+ if ((ext = strrchr(buf, '.')) == NULL) {
+ errno = EINVAL;
return -1;
+ }
// check length
- if (ext + strlen(newext) >= buf + len)
+ if (ext + strlen(newext) >= buf + len) {
+ errno = ENAMETOOLONG;
return -1;
+ }
// change to .foo
strcpy(ext, newext);
@@ -24,8 +29,10 @@
int path_with_fext (const char *path, char *buf, size_t len, const char *newext)
{
// verify length
- if (strlen(path) > len)
+ if (strlen(path) > len) {
+ errno = ENAMETOOLONG;
return -1;
+ }
// copy filename
strcpy(buf, path);