Changeset 17603 in niluje


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

MobiCover:

  • Minor realpath cleanups Can't use realpath on a path that doesn't exist yet ;).
File:
1 edited

Legend:

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

    r17602 r17603  
    192192                // Use the sha1 of the full path, like the Kindle
    193193                char     abspath[PATH_MAX];
    194                 uint8_t* p = (uint8_t*) realpath(fullpath, abspath);
    195                 if (p == NULL) {
     194                if (realpath(fullpath, abspath) == NULL) {
    196195                        fprintf(stderr, "Unable to resolve input file's path (realpath: %m)!\n");
    197196                        return ERRCODE(EXIT_FAILURE);
     
    201200                uint8_t         digest[SHA1_DIGEST_SIZE];
    202201                sha1_init(&sha1);
    203                 sha1_update(&sha1, strlen(abspath), p);
     202                sha1_update(&sha1, strlen(abspath), (uint8_t*) abspath);
    204203                sha1_digest(&sha1, SHA1_DIGEST_SIZE, digest);
    205204
     
    216215        }
    217216        free(asin);
    218         // Resolve final path (mainly for cosmetic reasons ;p)
    219         char  abspath[PATH_MAX];
    220         char* p = realpath(cover_path, abspath);
    221         if (p == NULL) {
    222                 fprintf(stderr, "Unable to resolve output cover path (realpath: %m)!\n");
    223                 return ERRCODE(EXIT_FAILURE);
    224         }
    225 
    226         fprintf(stderr, "Saving cover to %s\n", p);
     217
     218        fprintf(stderr, "Saving cover to %s\n", cover_path);
    227219        errno      = 0;
    228         FILE* file = fopen(p, "wb");
     220        FILE* file = fopen(cover_path, "wb");
    229221        if (file == NULL) {
    230                 fprintf(stderr, "Could not open file for writing: %s (fopen: %m)\n", p);
     222                fprintf(stderr, "Could not open file for writing: %s (fopen: %m)\n", cover_path);
    231223                return ERRCODE(EXIT_FAILURE);
    232224        }
    233225        size_t count = fwrite(record->data, 1, record->size, file);
    234226        if (count != record->size) {
    235                 fprintf(stderr, "Error writing to file: %s (fwrite: %m)\n", p);
     227                fprintf(stderr, "Error writing to file: %s (fwrite: %m)\n", cover_path);
    236228                fclose(file);
    237229                return ERRCODE(EXIT_FAILURE);
Note: See TracChangeset for help on using the changeset viewer.