* Downscale album art files to JPEG_TN specs and cache them if we find album art at a larger resolution.

This commit is contained in:
Justin Maggard
2009-02-15 21:32:48 +00:00
parent 8614319bbe
commit 5413646e1c
7 changed files with 158 additions and 16 deletions

45
utils.c
View File

@ -24,6 +24,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
int
ends_with(const char * haystack, const char * needle)
@ -102,3 +103,47 @@ strip_ext(char * name)
if( period )
*period = '\0';
}
/* Code basically stolen from busybox */
int
make_dir(char * path, mode_t mode)
{
char * s = path;
char c;
struct stat st;
do {
c = 0;
/* Bypass leading non-'/'s and then subsequent '/'s. */
while (*s) {
if (*s == '/') {
do {
++s;
} while (*s == '/');
c = *s; /* Save the current char */
*s = 0; /* and replace it with nul. */
break;
}
++s;
}
if (mkdir(path, mode) < 0) {
/* If we failed for any other reason than the directory
* already exists, output a diagnostic and return -1.*/
if (errno != EEXIST
|| (stat(path, &st) < 0 || !S_ISDIR(st.st_mode))) {
break;
}
}
if (!c)
return 0;
/* Remove any inserted nul from the path. */
*s = c;
} while (1);
printf("make_dir: cannot create directory '%s'", path);
return -1;
}