diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2012-02-18 08:19:59 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2012-02-18 13:37:45 -0800 |
commit | d1714a57c59173837fc3d9c027e18ad6a1b6fc52 (patch) | |
tree | f736eec5f2ba78a228e4486627051e5ca79f8854 /gzread.c | |
parent | 455adc302965e0fc0e8b084c204d055ae3d66606 (diff) | |
download | zlib-d1714a57c59173837fc3d9c027e18ad6a1b6fc52.tar.gz zlib-d1714a57c59173837fc3d9c027e18ad6a1b6fc52.tar.bz2 zlib-d1714a57c59173837fc3d9c027e18ad6a1b6fc52.zip |
Replace use of memmove() with a simple copy for portability.
SunOS 4.1 doesn't have memmove(), and there may be others. memcpy()
should not be used for overlapping copies, so here a simple copy is
implemented that works for the particular direction of the overlap,
which is where the destination precedes the source.
Diffstat (limited to 'gzread.c')
-rw-r--r-- | gzread.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -57,8 +57,13 @@ local int gz_avail(state) | |||
57 | if (state->err != Z_OK && state->err != Z_BUF_ERROR) | 57 | if (state->err != Z_OK && state->err != Z_BUF_ERROR) |
58 | return -1; | 58 | return -1; |
59 | if (state->eof == 0) { | 59 | if (state->eof == 0) { |
60 | if (strm->avail_in) | 60 | if (strm->avail_in) { /* copy what's there to the start */ |
61 | memmove(state->in, strm->next_in, strm->avail_in); | 61 | unsigned char *p = state->in, *q = strm->next_in; |
62 | unsigned n = strm->avail_in; | ||
63 | do { | ||
64 | *p++ = *q++; | ||
65 | } while (--n); | ||
66 | } | ||
62 | if (gz_load(state, state->in + strm->avail_in, | 67 | if (gz_load(state, state->in + strm->avail_in, |
63 | state->size - strm->avail_in, &got) == -1) | 68 | state->size - strm->avail_in, &got) == -1) |
64 | return -1; | 69 | return -1; |
@@ -340,7 +345,7 @@ int ZEXPORT gzread(file, buf, len) | |||
340 | /* get more output, looking for header if required */ | 345 | /* get more output, looking for header if required */ |
341 | if (gz_fetch(state) == -1) | 346 | if (gz_fetch(state) == -1) |
342 | return -1; | 347 | return -1; |
343 | continue; /* no progress yet -- go back to memcpy() above */ | 348 | continue; /* no progress yet -- go back to copy above */ |
344 | /* the copy above assures that we will leave with space in the | 349 | /* the copy above assures that we will leave with space in the |
345 | output buffer, allowing at least one gzungetc() to succeed */ | 350 | output buffer, allowing at least one gzungetc() to succeed */ |
346 | } | 351 | } |