VirtualBox

Changeset 95819 in vbox


Ignore:
Timestamp:
Jul 25, 2022 2:49:09 PM (3 years ago)
Author:
vboxsync
Message:

libs/zlib: In IPRT_NO_CRT mode don't try use CRT for reading & writing files, use IPRT. bugref:10261

Location:
trunk/src/libs/zlib-1.2.12
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/zlib-1.2.12/Makefile.kmk

    r76178 r95819  
    4545VBox-zlib-static_TEMPLATE = VBoxR3StaticNonPedantic
    4646VBox-zlib-static_DEFS = $(VBox-zlib_DEFS)
     47ifdef VBOX_WITH_NOCRT_STATIC
     48VBox-zlib-static_DEFS += IPRT_NO_CRT_FOR_3RD_PARTY
     49endif
    4750VBox-zlib-static_SOURCES = $(VBox-zlib_SOURCES)
    4851
  • trunk/src/libs/zlib-1.2.12/gzguts.h

    r95239 r95819  
    1919#endif
    2020
     21#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    2122#include <stdio.h>
     23#endif                                                                                                  /* VBox */
    2224#include "zlib.h"
    2325#ifdef STDC
     
    3032#  define _POSIX_SOURCE
    3133#endif
     34#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    3235#include <fcntl.h>
    33 
     36#endif
     37                                                                                                        /* VBox */
    3438#ifdef _WIN32
    3539#  include <stddef.h>
    3640#endif
    3741
     42#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    3843#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
    3944#  include <io.h>
    4045#endif
    41 
     46#else                                                                                                   /* VBox */
     47#  include <iprt/file.h>                                                                                /* VBox */
     48#  include <iprt/errcore.h>                                                                             /* VBox */
     49#endif                                                                                                  /* VBox */
     50
     51#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    4252#if defined(_WIN32)
    4353#  define WIDECHAR
     54#endif                                                                                                  /* VBox */
    4455#endif
    4556
     
    5465#  define NO_GZCOMPRESS
    5566#endif
     67
     68#ifdef IPRT_NO_CRT                                                                                      /* VBox */
     69#  include <iprt/string.h>                                                                              /* VBox */
     70#  define HAVE_VSNPRINTF                                                                                /* VBox */
     71#  define snprintf  RTStrPrintf                                                                         /* VBox */
     72#  define vsnprintf RTStrPrintfV                                                                        /* VBox */
     73#else  /* !IPRT_NO_CRT */                                                                               /* VBox */
    5674
    5775#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
     
    110128#  define snprintf _snprintf
    111129#endif
     130                                                                                                        /* VBox */
     131#endif /* !IPRT_NO_CRT */                                                                               /* VBox */
    112132
    113133#ifndef local
     
    125145
    126146/* get errno and strerror definition */
    127 #if defined UNDER_CE
     147#if defined UNDER_CE || (defined(IPRT_NO_CRT) && defined(RT_OS_WINDOWS))
    128148#  include <windows.h>
    129149#  define zstrerror() gz_strwinerror((DWORD)GetLastError())
     
    176196        /* used for both reading and writing */
    177197    int mode;               /* see gzip modes above */
     198#ifndef IPRT_NO_CRT
    178199    int fd;                 /* file descriptor */
     200#else
     201    RTFILE fd;                 /* file descriptor */
     202#endif
    179203    char *path;             /* path or fd for error messages */
    180204    unsigned size;          /* buffer size, zero if not allocated yet */
     
    205229/* shared functions */
    206230void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
    207 #if defined UNDER_CE
     231#if defined UNDER_CE || (defined(IPRT_NO_CRT) && defined(RT_OS_WINDOWS))
    208232char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
    209233#endif
  • trunk/src/libs/zlib-1.2.12/gzlib.c

    r95239 r95819  
    9898    gz_statep state;
    9999    z_size_t len;
     100#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    100101    int oflag;
     102#else                                                                                                   /* VBox */
     103    uint64_t fOpen;                                                                                     /* VBox */
     104    int rc;                                                                                             /* VBox */
     105# define O_CLOEXEC                                                                                      /* VBox */
     106# define O_EXCL                                                                                         /* VBox */
     107#endif                                                                                                  /* VBox */
    101108#ifdef O_CLOEXEC
    102109    int cloexec = 0;
     
    220227
    221228    /* compute the flags for open() */
     229#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    222230    oflag =
    223231#ifdef O_LARGEFILE
     
    239247           O_TRUNC :
    240248           O_APPEND)));
     249#else  /* IPRT_NO_CRT */                                                                                /* VBox */
     250    fOpen = RTFILE_O_DENY_NONE                                                                          /* VBox */
     251          | (0666 << RTFILE_O_CREATE_MODE_SHIFT)                                                        /* VBox */
     252          | (cloexec ? 0 : RTFILE_O_INHERIT)                                                            /* VBox */
     253          | (state->mode == GZ_READ                                                                     /* VBox */
     254             ? RTFILE_O_READ | RTFILE_O_OPEN                                                            /* VBox */
     255             : RTFILE_O_WRITE                                                                           /* VBox */
     256               | (exclusive                                                                             /* VBox */
     257                  ? RTFILE_O_CREATE                                                                     /* VBox */
     258                  : state->mode == GZ_WRITE                                                             /* VBox */
     259                    ? RTFILE_O_CREATE_REPLACE                                                           /* VBox */
     260                    : RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND)                                           /* VBox */
     261            );                                                                                          /* VBox */
     262#endif /* IPRT_NO_CRT */                                                                                /* VBox */
    241263
    242264    /* open the file with the appropriate flags (or just use fd) */
     265#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    243266    state->fd = fd > -1 ? fd : (
    244267#ifdef WIDECHAR
     
    247270        open((const char *)path, oflag, 0666));
    248271    if (state->fd == -1) {
     272#else  /* IPRT_NO_CRT */
     273    rc = RTFileOpen(&state->fd, path, fOpen);
     274    if (RT_FAILURE(rc)) {
     275#endif /* IPRT_NO_CRT */
    249276        free(state->path);
    250277        free(state);
     
    252279    }
    253280    if (state->mode == GZ_APPEND) {
     281#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    254282        LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
     283#else
     284        RTFileSeek(state->fd, 0, RTFILE_SEEK_END, NULL);
     285#endif
    255286        state->mode = GZ_WRITE;         /* simplify later checks */
    256287    }
     
    258289    /* save the current position for rewinding (only if reading) */
    259290    if (state->mode == GZ_READ) {
     291#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    260292        state->start = LSEEK(state->fd, 0, SEEK_CUR);
     293#else
     294        state->start = RTFileTell(state->fd);
     295#endif
    261296        if (state->start == -1) state->start = 0;
    262297    }
     
    359394
    360395    /* back up and start over */
     396#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    361397    if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
     398#else
     399    if (RT_FAILURE(RTFileSeek(state->fd, state->start, RTFILE_SEEK_CURRENT, NULL)))
     400#endif
    362401        return -1;
    363402    gz_reset(state);
     
    400439    if (state->mode == GZ_READ && state->how == COPY &&
    401440            state->x.pos + offset >= 0) {
     441#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    402442        ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
    403443        if (ret == -1)
     444#else
     445        ret = RTFileSeek(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR, NULL);
     446        if (RT_FAILURE(ret))
     447#endif
    404448            return -1;
    405449        state->x.have = 0;
     
    496540
    497541    /* compute and return effective offset in file */
     542#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    498543    offset = LSEEK(state->fd, 0, SEEK_CUR);
    499544    if (offset == -1)
     545#else
     546    offset = RTFileTell(state->fd);
     547    if ((uint64_t)offset == UINT64_MAX)
     548#endif
    500549        return -1;
    501550    if (state->mode == GZ_READ)             /* reading */
  • trunk/src/libs/zlib-1.2.12/gzread.c

    r95239 r95819  
    3333        if (get > max)
    3434            get = max;
     35#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    3536        ret = read(state->fd, buf + *have, get);
    3637        if (ret <= 0)
    3738            break;
     39#else                                                                                                   /* VBox */
     40        {                                                                                               /* VBox */
     41            size_t cbRead;                                                                              /* VBox */
     42            ret = RTFileRead(state->fd, buf + *have, get, &cbRead);                                     /* VBox */
     43            if (RT_SUCCESS(ret))                                                                        /* VBox */
     44                ret = (int)cbRead;                                                                      /* VBox */
     45            else                                                                                        /* VBox */
     46            {                                                                                           /* VBox */
     47                char szDefine[80];                                                                      /* VBox */
     48                RTErrQueryDefine(ret, szDefine, sizeof(szDefine), false);                               /* VBox */
     49                gz_error(state, Z_ERRNO, szDefine);                                                     /* VBox */
     50                return -1;                                                                              /* VBox */
     51            }                                                                                           /* VBox */
     52        }                                                                                               /* VBox */
     53#endif                                                                                                  /* VBox */
    3854        *have += (unsigned)ret;
    3955    } while (*have < len);
     56#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    4057    if (ret < 0) {
    4158        gz_error(state, Z_ERRNO, zstrerror());
    4259        return -1;
    4360    }
     61#endif                                                                                                  /* VBox */
    4462    if (ret == 0)
    4563        state->eof = 1;
     
    647665    gz_error(state, Z_OK, NULL);
    648666    free(state->path);
     667#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    649668    ret = close(state->fd);
     669#else                                                                                                   /* VBox */
     670    ret = RTFileClose(state->fd);                                                                       /* VBox */
     671    if (RT_SUCCESS(ret))                                                                                /* VBox */
     672        ret = 0;                                                                                        /* VBox */
     673#endif                                                                                                  /* VBox */
    650674    free(state);
    651675    return ret ? Z_ERRNO : err;
  • trunk/src/libs/zlib-1.2.12/gzwrite.c

    r95239 r95819  
    6565}
    6666
     67#ifdef IPRT_NO_CRT                                                                                      /* VBox */
     68DECLINLINE(int) gz_write_wrap(gz_statep state, void const *pvSrc, size_t cbToWrite)                     /* VBox */
     69{                                                                                                       /* VBox */
     70    size_t cbWritten;                                                                                   /* VBox */
     71    int ret = RTFileWrite(state->fd, pvSrc, cbToWrite, &cbWritten);                                     /* VBox */
     72    if (RT_SUCCESS(ret))                                                                                /* VBox */
     73        ret = (int)cbWritten;                                                                           /* VBox */
     74    else {                                                                                              /* VBox */
     75        char szDefine[80];                                                                              /* VBox */
     76        RTErrQueryDefine(ret, szDefine, sizeof(szDefine), false);                                       /* VBox */
     77        gz_error(state, Z_ERRNO, szDefine);                                                             /* VBox */
     78        ret = -1;                                                                                       /* VBox */
     79    }                                                                                                   /* VBox */
     80    return ret;                                                                                         /* VBox */
     81}                                                                                                       /* VBox */
     82#endif /* IPRT_NO_CRT */                                                                                /* VBox */
     83
    6784/* Compress whatever is at avail_in and next_in and write to the output file.
    6885   Return -1 if there is an error writing to the output file or if gz_init()
     
    87104        while (strm->avail_in) {
    88105            put = strm->avail_in > max ? max : strm->avail_in;
     106#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    89107            writ = write(state->fd, strm->next_in, put);
    90108            if (writ < 0) {
     
    92110                return -1;
    93111            }
     112#else                                                                                                   /* VBox */
     113            writ = gz_write_wrap(state, strm->next_in, put);                                            /* VBox */
     114            if (writ < 0)                                                                               /* VBox */
     115                return -1;                                                                              /* VBox */
     116#endif                                                                                                  /* VBox */
    94117            strm->avail_in -= (unsigned)writ;
    95118            strm->next_in += writ;
     
    117140                put = strm->next_out - state->x.next > (int)max ? max :
    118141                      (unsigned)(strm->next_out - state->x.next);
     142#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    119143                writ = write(state->fd, state->x.next, put);
    120144                if (writ < 0) {
     
    122146                    return -1;
    123147                }
     148#else                                                                                                   /* VBox */
     149                writ = gz_write_wrap(state, state->x.next, put);                                        /* VBox */
     150                if (writ < 0)                                                                           /* VBox */
     151                    return -1;                                                                          /* VBox */
     152#endif                                                                                                  /* VBox */
    124153                state->x.next += writ;
    125154            }
     
    671700    gz_error(state, Z_OK, NULL);
    672701    free(state->path);
     702#ifndef IPRT_NO_CRT                                                                                     /* VBox */
    673703    if (close(state->fd) == -1)
     704#else                                                                                                   /* VBox */
     705    if (RT_FAILURE(RTFileClose(state->fd)))                                                             /* VBox */
     706#endif                                                                                                  /* VBox */
    674707        ret = Z_ERRNO;
    675708    free(state);
  • trunk/src/libs/zlib-1.2.12/zutil.h

    r95239 r95819  
    257257#endif
    258258
     259#ifdef IPRT_NO_CRT                                                                                      /* VBox */
     260#  undef Assert                                                                                         /* VBox */
     261#  include <iprt/assert.h>                                                                              /* VBox */
     262#  undef Assert                                                                                         /* VBox */
     263#  ifdef ZLIB_DEBUG                                                                                     /* VBox */
     264#     define Assert(cond, msg) AssertMsg(cond, (msg))                                                   /* VBox */
     265#  else                                                                                                 /* VBox */
     266#     define Assert(cond, msg) do {} while (0)                                                          /* VBox */
     267#  endif                                                                                                /* VBox */
     268#endif                                                                                                  /* VBox */
     269
    259270#ifndef Z_SOLO
    260271   voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette