From 34cb08928c4ec9ecf0d8aa38f3d3dd3fc5a9e148 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Wed, 14 May 2014 17:53:25 -0700 Subject: [PATCH] portability: add support for Illumos This still won't work on older Solaris systems, but modern Illumos at least should build and run now. --- albumart.c | 26 +++++++++++++------------- configure.ac | 1 + getifaddr.c | 10 ++++++++-- minidlna.c | 1 + scanner.c | 22 +++++++++++++--------- tagutils/tagutils-asf.c | 8 ++------ upnpglobalvars.c | 1 + upnphttp.c | 1 + utils.c | 1 + utils.h | 17 +++++++++++++++++ 10 files changed, 58 insertions(+), 30 deletions(-) diff --git a/albumart.c b/albumart.c index da1b58a..20ed14e 100644 --- a/albumart.c +++ b/albumart.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -127,23 +128,22 @@ update_if_album_art(const char *path) return; while ((dp = readdir(dh)) != NULL) { - switch( dp->d_type ) + if (is_reg(dp) == 1) { - case DT_REG: - type = TYPE_FILE; - break; - case DT_LNK: - case DT_UNKNOWN: - snprintf(file, sizeof(file), "%s/%s", dir, dp->d_name); - type = resolve_unknown_type(file, ALL_MEDIA); - break; - default: - type = TYPE_UNKNOWN; - break; + type = TYPE_FILE; + } + else if (is_dir(dp) == 1) + { + type = TYPE_DIR; + } + else + { + snprintf(file, sizeof(file), "%s/%s", dir, dp->d_name); + type = resolve_unknown_type(file, ALL_MEDIA); } if( type != TYPE_FILE ) continue; - if( (*(dp->d_name) != '.') && + if( (dp->d_name[0] != '.') && (is_video(dp->d_name) || is_audio(dp->d_name)) && (album_art || strncmp(dp->d_name, match, ncmp) == 0) ) { diff --git a/configure.ac b/configure.ac index e1ccf8a..3a8a54c 100644 --- a/configure.ac +++ b/configure.ac @@ -59,6 +59,7 @@ m4_ifdef([AC_TYPE_INT32_T], [AC_TYPE_INT32_T]) m4_ifdef([AC_TYPE_UINT32_T], [AC_TYPE_UINT32_T]) m4_ifdef([AC_TYPE_UINT64_T], [AC_TYPE_UINT64_T]) m4_ifdef([AC_TYPE_SSIZE_T], [AC_TYPE_SSIZE_T]) +AC_STRUCT_DIRENT_D_TYPE AC_STRUCT_ST_BLOCKS AC_HEADER_STDBOOL AC_C_BIGENDIAN diff --git a/getifaddr.c b/getifaddr.c index 429b35a..329a96b 100644 --- a/getifaddr.c +++ b/getifaddr.c @@ -173,7 +173,7 @@ getsyshwaddr(char *buf, int len) { unsigned char mac[6]; int ret = -1; -#if defined(HAVE_GETIFADDRS) && !defined (__linux__) +#if defined(HAVE_GETIFADDRS) && !defined (__linux__) && !defined (__sun__) struct ifaddrs *ifap, *p; struct sockaddr_in *addr_in; uint8_t a; @@ -191,7 +191,7 @@ getsyshwaddr(char *buf, int len) a = (htonl(addr_in->sin_addr.s_addr) >> 0x18) & 0xFF; if (a == 127) continue; -#ifdef __linux__ +#if defined(__linux__) struct ifreq ifr; int fd; fd = socket(AF_INET, SOCK_DGRAM, 0); @@ -242,9 +242,15 @@ getsyshwaddr(char *buf, int len) continue; if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) continue; +#ifdef __sun__ + if (MACADDR_IS_ZERO(ifr.ifr_addr.sa_data)) + continue; + memcpy(mac, ifr.ifr_addr.sa_data, 6); +#else if (MACADDR_IS_ZERO(ifr.ifr_hwaddr.sa_data)) continue; memcpy(mac, ifr.ifr_hwaddr.sa_data, 6); +#endif ret = 0; break; } diff --git a/minidlna.c b/minidlna.c index 6b25a2a..c8eed5b 100644 --- a/minidlna.c +++ b/minidlna.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include diff --git a/scanner.c b/scanner.c index 4fee7cb..5ae5612 100644 --- a/scanner.c +++ b/scanner.c @@ -604,10 +604,14 @@ filter_hidden(scan_filter *d) static int filter_type(scan_filter *d) { +#if HAVE_STRUCT_DIRENT_D_TYPE return ( (d->d_type == DT_DIR) || (d->d_type == DT_LNK) || (d->d_type == DT_UNKNOWN) ); +#else + return 1; +#endif } static int @@ -615,7 +619,7 @@ filter_a(scan_filter *d) { return ( filter_hidden(d) && (filter_type(d) || - ((d->d_type == DT_REG) && + (is_reg(d) && (is_audio(d->d_name) || is_playlist(d->d_name)))) ); @@ -626,7 +630,7 @@ filter_av(scan_filter *d) { return ( filter_hidden(d) && (filter_type(d) || - ((d->d_type == DT_REG) && + (is_reg(d) && (is_audio(d->d_name) || is_video(d->d_name) || is_playlist(d->d_name)))) @@ -638,7 +642,7 @@ filter_ap(scan_filter *d) { return ( filter_hidden(d) && (filter_type(d) || - ((d->d_type == DT_REG) && + (is_reg(d) && (is_audio(d->d_name) || is_image(d->d_name) || is_playlist(d->d_name)))) @@ -650,7 +654,7 @@ filter_v(scan_filter *d) { return ( filter_hidden(d) && (filter_type(d) || - (d->d_type == DT_REG && + (is_reg(d) && is_video(d->d_name))) ); } @@ -660,7 +664,7 @@ filter_vp(scan_filter *d) { return ( filter_hidden(d) && (filter_type(d) || - ((d->d_type == DT_REG) && + (is_reg(d) && (is_video(d->d_name) || is_image(d->d_name)))) ); @@ -671,7 +675,7 @@ filter_p(scan_filter *d) { return ( filter_hidden(d) && (filter_type(d) || - (d->d_type == DT_REG && + (is_reg(d) && is_image(d->d_name))) ); } @@ -681,7 +685,7 @@ filter_avp(scan_filter *d) { return ( filter_hidden(d) && (filter_type(d) || - ((d->d_type == DT_REG) && + (is_reg(d) && (is_audio(d->d_name) || is_image(d->d_name) || is_video(d->d_name) || @@ -754,11 +758,11 @@ ScanDirectory(const char *dir, const char *parent, media_types dir_types) type = TYPE_UNKNOWN; snprintf(full_path, PATH_MAX, "%s/%s", dir, namelist[i]->d_name); name = escape_tag(namelist[i]->d_name, 1); - if( namelist[i]->d_type == DT_DIR ) + if( is_dir(namelist[i]) == 1 ) { type = TYPE_DIR; } - else if( namelist[i]->d_type == DT_REG ) + else if( is_reg(namelist[i]) == 1 ) { type = TYPE_FILE; } diff --git a/tagutils/tagutils-asf.c b/tagutils/tagutils-asf.c index 114032e..fca0597 100644 --- a/tagutils/tagutils-asf.c +++ b/tagutils/tagutils-asf.c @@ -375,9 +375,9 @@ _asf_load_string(FILE *fp, int type, int size, char *buf, int len) unsigned char data[2048]; uint16_t wc; int i, j; + int16_t *wd16; int32_t *wd32; int64_t *wd64; - int16_t *wd16; i = 0; if(size && (size <= sizeof(data)) && (size == fread(data, 1, size, fp))) @@ -413,11 +413,7 @@ _asf_load_string(FILE *fp, int type, int size, char *buf, int len) if(size >= 8) { wd64 = (int64_t *) &data[0]; -#if __WORDSIZE == 64 - i = snprintf(buf, len, "%ld", le64_to_cpu(*wd64)); -#else - i = snprintf(buf, len, "%lld", le64_to_cpu(*wd64)); -#endif + i = snprintf(buf, len, "%lld", (long long)le64_to_cpu(*wd64)); } break; case ASF_VT_WORD: diff --git a/upnpglobalvars.c b/upnpglobalvars.c index 73ceeca..fff02c8 100644 --- a/upnpglobalvars.c +++ b/upnpglobalvars.c @@ -49,6 +49,7 @@ #include #include #include +#include #include "config.h" #include "upnpglobalvars.h" diff --git a/upnphttp.c b/upnphttp.c index fddad6d..5834b03 100644 --- a/upnphttp.c +++ b/upnphttp.c @@ -61,6 +61,7 @@ #include #include #include +#include #include "config.h" #include "upnpglobalvars.h" diff --git a/utils.c b/utils.c index 4213faf..d728136 100644 --- a/utils.c +++ b/utils.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/utils.h b/utils.h index a15a7ae..433179e 100644 --- a/utils.h +++ b/utils.h @@ -25,6 +25,7 @@ #define __UTILS_H__ #include +#include #include #include "minidlnatypes.h" @@ -55,6 +56,22 @@ static inline void strncpyt(char *dst, const char *src, size_t len) strncpy(dst, src, len); dst[len-1] = '\0'; } +static inline int is_reg(const struct dirent *d) +{ +#if HAVE_STRUCT_DIRENT_D_TYPE + return (d->d_type == DT_REG); +#else + return -1; +#endif +} +static inline int is_dir(const struct dirent *d) +{ +#if HAVE_STRUCT_DIRENT_D_TYPE + return (d->d_type == DT_DIR); +#else + return -1; +#endif +} int xasprintf(char **strp, char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3))); int ends_with(const char * haystack, const char * needle); char *trim(char *str);