int pakfire_path_match(const char* p, const char* s);
+#define pakfire_path_replace_extension(path, extension) \
+ __pakfire_path_replace_extension(path, sizeof(path), extension)
+int __pakfire_path_replace_extension(char* path, const size_t length, const char* extension);
+
#endif /* PAKFIRE_PATH_H */
int pakfire_path_exists(const char* path);
time_t pakfire_path_age(const char* path);
-int pakfire_path_strip_extension(char* path);
-
-#define pakfire_path_replace_extension(path, extension) \
- __pakfire_path_replace_extension(path, sizeof(path), extension)
-int __pakfire_path_replace_extension(char* path, const size_t length, const char* extension);
-
char* pakfire_remove_trailing_newline(char* str);
int pakfire_read_file_into_buffer(FILE* f, char** buffer, size_t* len);
// We reached the end of the string and all characters matched
return 1;
}
+
+static int pakfire_path_strip_extension(char* path) {
+ if (!path)
+ return -EINVAL;
+
+ // Find the extension
+ char* ext = strrchr(path, '.');
+
+ // If . could not be found, we return an error.
+ if (!ext)
+ return 1;
+
+ // Otherwise, we will terminate the string
+ *ext = '\0';
+ return 0;
+}
+
+int __pakfire_path_replace_extension(char* path, const size_t length, const char* extension) {
+ char buffer[PATH_MAX];
+ int r;
+
+ // Copy path to buffer
+ r = pakfire_string_set(buffer, path);
+ if (r < 0)
+ return r;
+
+ // Strip any old extension
+ r = pakfire_path_strip_extension(buffer);
+ if (r)
+ return r;
+
+ // Compose the new string
+ return __pakfire_string_format(path, length, "%s.%s", buffer, extension);
+}
return -1;
}
-int pakfire_path_strip_extension(char* path) {
- char* ext = strrchr(path, '.');
-
- // If . could not be found, we return an error.
- if (!ext)
- return 1;
-
- // Otherwise, we will terminate the string
- *ext = '\0';
-
- return 0;
-}
-
-int __pakfire_path_replace_extension(char* path, const size_t length, const char* extension) {
- char buffer[PATH_MAX];
- int r;
-
- // Copy path to buffer
- r = pakfire_string_set(buffer, path);
- if (r)
- return r;
-
- // Strip any old extension
- r = pakfire_path_strip_extension(buffer);
- if (r)
- return r;
-
- // Compose the new string
- return __pakfire_string_format(path, length, "%s.%s", buffer, extension);
-}
-
int pakfire_file_write(struct pakfire* pakfire, const char* path,
uid_t owner, gid_t group, mode_t mode, const char* format, ...) {
va_list args;