"Fossies" - the Fresh Open Source Software Archive

Member "minidlna-1.3.0/utils.h" (24 Nov 2020, 3263 Bytes) of package /linux/privat/minidlna-1.3.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "utils.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.2.1_vs_1.3.0.

    1 /* Utility functions
    2  *
    3  * Project : minidlna
    4  * Website : http://sourceforge.net/projects/minidlna/
    5  * Author  : Justin Maggard
    6  *
    7  * MiniDLNA media server
    8  * Copyright (C) 2008-2017  Justin Maggard
    9  *
   10  * This file is part of MiniDLNA.
   11  *
   12  * MiniDLNA is free software; you can redistribute it and/or modify
   13  * it under the terms of the GNU General Public License version 2 as
   14  * published by the Free Software Foundation.
   15  *
   16  * MiniDLNA is distributed in the hope that it will be useful,
   17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19  * GNU General Public License for more details.
   20  *
   21  * You should have received a copy of the GNU General Public License
   22  * along with MiniDLNA. If not, see <http://www.gnu.org/licenses/>.
   23  */
   24 #ifndef __UTILS_H__
   25 #define __UTILS_H__
   26 
   27 #include <stdarg.h>
   28 #include <dirent.h>
   29 #include <sys/param.h>
   30 
   31 #include "minidlnatypes.h"
   32 
   33 /* String functions */
   34 /* We really want this one inlined, since it has a major performance impact */
   35 static inline int
   36 __attribute__((__format__ (__printf__, 2, 3)))
   37 strcatf(struct string_s *str, const char *fmt, ...)
   38 {
   39     int ret;
   40     int size;
   41     va_list ap;
   42 
   43     if (str->off >= str->size)
   44         return 0;
   45 
   46     va_start(ap, fmt);
   47     size = str->size - str->off;
   48     ret = vsnprintf(str->data + str->off, size, fmt, ap);
   49     str->off += MIN(ret, size);
   50     va_end(ap);
   51 
   52     return ret;
   53 }
   54 static inline void strncpyt(char *dst, const char *src, size_t len)
   55 {
   56     strncpy(dst, src, --len);
   57     dst[len] = '\0';
   58 }
   59 static inline int is_reg(const struct dirent *d)
   60 {
   61 #if HAVE_STRUCT_DIRENT_D_TYPE
   62     return (d->d_type == DT_REG);
   63 #else
   64     return -1;
   65 #endif
   66 }
   67 static inline int is_dir(const struct dirent *d)
   68 {
   69 #if HAVE_STRUCT_DIRENT_D_TYPE
   70     return (d->d_type == DT_DIR);
   71 #else
   72     return -1;
   73 #endif
   74 }
   75 int xasprintf(char **strp, char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
   76 int ends_with(const char * haystack, const char * needle);
   77 char *trim(char *str);
   78 char *strstrc(const char *s, const char *p, const char t);
   79 char *strcasestrc(const char *s, const char *p, const char t);
   80 char *modifyString(char *string, const char *before, const char *after, int noalloc);
   81 char *escape_tag(const char *tag, int force_alloc);
   82 char *unescape_tag(const char *tag, int force_alloc);
   83 char *duration_str(int msec);
   84 char *strip_ext(char *name);
   85 
   86 /* Metadata functions */
   87 int is_video(const char * file);
   88 int is_audio(const char * file);
   89 int is_image(const char * file);
   90 int is_playlist(const char * file);
   91 int is_caption(const char * file);
   92 #define is_nfo(file) ends_with(file, ".nfo")
   93 media_types get_media_type(const char *file);
   94 media_types valid_media_types(const char *path);
   95 
   96 int is_album_art(const char * name);
   97 int resolve_unknown_type(const char * path, media_types dir_type);
   98 const char *mime_to_ext(const char * mime);
   99 
  100 /* Others */
  101 int make_dir(char * path, mode_t mode);
  102 unsigned int DJBHash(uint8_t *data, int len);
  103 
  104 /* Timeval manipulations */
  105 void    timevaladd(struct timeval *t1, const struct timeval *t2);
  106 void    timevalsub(struct timeval *t1, const struct timeval *t2);
  107 #define timevalcmp(tvp, uvp, cmp)                   \
  108     (((tvp)->tv_sec == (uvp)->tv_sec) ?             \
  109         ((tvp)->tv_usec cmp (uvp)->tv_usec) :           \
  110         ((tvp)->tv_sec cmp (uvp)->tv_sec))
  111 
  112 #endif