Changeset 17602 in niluje


Ignore:
Timestamp:
Jul 30, 2020, 7:27:57 PM (12 days ago)
Author:
NiLuJe
Message:

MobiCover:

  • Get rid of split_fullpath, use dirname() instead
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Configs/trunk/Kindle/Touch_Hacks/MobiCover/LibMobi/mobicover.c

    r17598 r17602  
    1616// $Revision$
    1717
     18#define _GNU_SOURCE    // Because Linux.
    1819#include <errno.h>
    1920#include <getopt.h>
     21#include <libgen.h>
    2022#include <limits.h>
    2123#include <stdio.h>
     
    7779}
    7880
    79 static const char separator = '/';
    80 /**
    81  @brief Parse file name into file path and base name.
    82         Dirname or basename can be skipped by setting to NULL.
    83         All buffers must have FILENAME_MAX size.
    84  @param[in] fullpath Full file path
    85  @param[in,out] dirname Will be set to full dirname
    86  @param[in,out] basename Will be set to file basename
    87  */
    88 static void
    89     split_fullpath(const char* fullpath, char* dirname, char* basename)
    90 {
    91         char* p = strrchr(fullpath, separator);
    92         if (p) {
    93                 p += 1;
    94                 if (dirname) {
    95                         strncpy(dirname, fullpath, (size_t)(p - fullpath));
    96                         dirname[p - fullpath] = '\0';
    97                 }
    98                 if (basename) {
    99                         strcpy(basename, p);
    100                 }
    101         } else {
    102                 if (dirname) {
    103                         dirname[0] = '\0';
    104                 }
    105                 if (basename) {
    106                         strcpy(basename, fullpath);
    107                 }
    108         }
    109         if (basename) {
    110                 p = strrchr(basename, '.');
    111                 if (p) {
    112                         *p = '\0';
    113                 }
    114         }
    115 }
    116 
    11781// Actual tools/mobitool.c stuff
    11882
     
    217181        }
    218182
    219         char dirname[FILENAME_MAX];
    220         split_fullpath(fullpath, dirname, NULL);
     183        // dirname() is clunky, unlike basename(), there's no GNU variant, so it will modify its arg, hence the copy.
     184        char* dirc       = strdupa(fullpath);
     185        char* outdirname = dirname(dirc);
    221186
    222187        char* asin   = mobi_meta_get_asin(m);
     
    248213                snprintf(cover_path, sizeof(cover_path), "%s/cover_raw_%s.%s", outdir, cdekey, ext);
    249214        } else {
    250                 // NOTE: split_fullpath should mostly guarantee dirname already ends with a /
    251                 snprintf(cover_path, sizeof(cover_path), "%s/cover_raw_%s.%s", dirname, cdekey, ext);
     215                snprintf(cover_path, sizeof(cover_path), "%s/cover_raw_%s.%s", outdirname, cdekey, ext);
    252216        }
    253217        free(asin);
Note: See TracChangeset for help on using the changeset viewer.