From: Laurent Mazet Date: Mon, 12 Dec 2022 11:21:09 +0000 (+0100) Subject: corrections from linux gcc v11 compilation X-Git-Url: https://secure.softndesign.org/git/?p=compress.git;a=commitdiff_plain;h=d7d2982cad68c1abbf5a4bafe446dc498ae10a41 corrections from linux gcc v11 compilation --- diff --git a/compress.c b/compress.c index 713fc5b..d27f8e5 100644 --- a/compress.c +++ b/compress.c @@ -17,6 +17,10 @@ #define COMPRESS 1 #define DECOMPRESS 2 +#ifndef O_RAW +#define O_RAW 0 +#endif /* O_RAW */ + /* macros */ /* gobal variables */ @@ -356,7 +360,7 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header) char bits[(NB_BYTES - 1) + 8 + 1] = {0}; int fin, fout; int length = 0; - int i, j, nbread; + int i, j, nbread, nbwrite; byte_t *pt; VERBOSE (DEBUG, PRINTOUT ("start writting compressed file\n")); @@ -381,7 +385,14 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header) /* write header */ length = (header[3] << 8) + header[4]; VERBOSE (DEBUG, PRINTOUT ("lengh: %d\n", length)); - write (fout, header, length + 6); + nbwrite = write (fout, header, length + 6); + if (nbwrite != length + 6) { + VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n", length + 6 - nbwrite, output)); + close (fout); + close (fin); + return 1; + } + /* write file */ pt = bufout; @@ -398,7 +409,13 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header) } codcpy (bits, sizeof (code_t), bits + 8); if (pt - bufout == BUFFER_SIZE - 1) { - write (fout, bufout, BUFFER_SIZE); + nbwrite = write (fout, bufout, BUFFER_SIZE); + if (nbwrite != BUFFER_SIZE) { + VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n", BUFFER_SIZE - nbwrite, output)); + close (fout); + close (fin); + return 1; + } pt = bufout; } else { pt++; @@ -421,7 +438,13 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header) } if (pt != bufout) { VERBOSE (DEBUG, PRINTOUT ("last partial buffer written: %u\n", pt - bufout)); - write (fout, bufout, pt - bufout); + nbwrite = write (fout, bufout, pt - bufout); + if (nbwrite != pt - bufout) { + VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n", pt - bufout - nbwrite, output)); + close (fout); + close (fin); + return 1; + } } /* closing */ @@ -539,7 +562,7 @@ int write_decompress (char *output, char *input, code_t *codes) byte_t bufhea[MAX(NB_BYTES * (NB_BYTES - 1) / 2 / 8 + NB_BYTES + 6, BUFFER_SIZE)] = {0}; char bits[(NB_BYTES - 1) + 1] = {0}; int fin, fout; - int i, j, k, nb, size, rem; + int i, j, k, nb, size, nbwrite, rem; int is_found; int l = 0; byte_t *pt; @@ -577,7 +600,7 @@ int write_decompress (char *output, char *input, code_t *codes) if (fout == -1) { VERBOSE (ERROR, PRINTERR ("can't open file '%s' for writing\n", output)); close (fin); - return 2; + return 1; } VERBOSE (INFO, PRINTOUT ("file '%s' opened\n", output)); @@ -602,7 +625,13 @@ int write_decompress (char *output, char *input, code_t *codes) bits[0] = 0; if (pt - bufout == BUFFER_SIZE - 1) { VERBOSE (DEBUG, PRINTOUT ("nb buffer out: %u\n", (pt - bufout))); - write (fout, bufout, BUFFER_SIZE); + nbwrite = write (fout, bufout, BUFFER_SIZE); + if (nbwrite != BUFFER_SIZE) { + VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n'", BUFFER_SIZE - nbwrite, output)); + close (fout); + close (fin); + return 1; + } pt = bufout; } else { pt++; @@ -618,7 +647,13 @@ int write_decompress (char *output, char *input, code_t *codes) } if (pt != bufout) { VERBOSE (DEBUG, PRINTOUT ("nb buffer out: %u\n", (pt - bufout))); - write (fout, bufout, pt - bufout); + nbwrite = write (fout, bufout, pt - bufout); + if (nbwrite != pt - bufout) { + VERBOSE (ERROR, PRINTERR ("can't write %d bytes in file '%s'\n'", pt - bufout - nbwrite, output)); + close (fout); + close (fin); + return 1; + } } /* close files */ diff --git a/fprintf.c b/fprintf.c index f74189c..ff4f035 100644 --- a/fprintf.c +++ b/fprintf.c @@ -12,6 +12,7 @@ */ #include +#include #include #include "fprintf.h" @@ -19,7 +20,7 @@ int _fdout = STDOUT_FILENO; int _fderr = STDERR_FILENO; -inline unsigned int nextpow (unsigned int x, int base) { +unsigned int nextpow (unsigned int x, int base) { unsigned int n = 0; while (x) { n++; @@ -94,13 +95,14 @@ int fdprintf (int fd, const char *fmt, ...) case 'x': /* integer hexa */ if (!p) { u = va_arg (ap, unsigned int); - p = (void *)u; if (sz == 0) { sz = nextpow (u, 16); } + } else { + u = (uintptr_t)p; } for (i = sz, t = 1; i > 0; i--) { - char x = (char)(((uintptr_t)p >> (i * 4 - 4)) & 0xf); + char x = (char)((u >> (i * 4 - 4)) & 0xf); if ((t == 1) && (x == 0)) { *str++ = w; } else { @@ -124,8 +126,7 @@ int fdprintf (int fd, const char *fmt, ...) /* output string */ int n = str - buffer; if (n < (int)sizeof (buffer) - 1) { - write (fd, buffer, n); - return n; + return write (fd, buffer, n); } return 0; }