#define COMPRESS 1
#define DECOMPRESS 2
+#ifndef O_RAW
+#define O_RAW 0
+#endif /* O_RAW */
+
/* macros */
/* gobal variables */
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"));
/* 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;
}
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++;
}
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 */
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;
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));
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++;
}
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 */
*/
#include <stdarg.h>
+#include <stdint.h>
#include <unistd.h>
#include "fprintf.h"
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++;
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 {
/* 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;
}