/* * Texte -> Compresseur -> 8bits * @param file : Fichier sortie * @param code : Code du caractère * @param taille : Taille du code * @param buffer : Buffer contenant le reste auquel le code suivant sera ajouté * @param k : Le nombre de bit à écrire pour completer l'octet */ void write_c(FILE* file,unsigned int code, unsigned int taille, int* buffer, int* reste){ if(*reste != (taille-RW_SIZE) && code != _EOF){ *buffer = *buffer | (code); unsigned char mot = *buffer >> (taille - *reste); write_b(file, mot); *buffer = *buffer << taille; *reste = *reste -1; }else if (code == _EOF && *reste != (taille-RW_SIZE)){
static char *write_key(char *p, char *ebuf, const char *key) { if(ebuf - p < 32) return NULL; p[0] = '"'; p++; p = write_b(p, ebuf, key, strlen(key)); if(p != NULL) { if(ebuf - p < 32) return NULL; p[0] = '"'; p++; p[0] = ':'; p++; p[0] = ' '; p++; } return p; }
int read_and_send(int in_fd, int out_sock, ssize_t bufsize) { unsigned char buf[bufsize]; ssize_t len; ssize_t read_bytes = 0; int ret; while (1) { len = read(in_fd, buf, bufsize); if (len == 0) { break; } if (len == -1) { int e = errno; DUMP0("Read error: %s(%d)", strerror(e), e); return -1; } ret = write_b(out_sock, buf, len); read_bytes += len; } return read_bytes; }
bool Color::write(yarp::os::idl::WireWriter& writer) { if (!write_r(writer)) return false; if (!write_g(writer)) return false; if (!write_b(writer)) return false; return !writer.isError(); }
static void ntrace(CTX ctx, const char *event, int pe, const knh_ldata2_t *d) { char buf[EBUFSIZ], *p = buf, *ebuf = p + (EBUFSIZ - 4); int logtype = LOG_NOTICE; p = write_b(p, ebuf, ctx->trace, strlen(ctx->trace)); p[0] = '+'; p++; p = write_d(p, ebuf, ctx->seq); ((kcontext_t*)ctx)->seq += 1; p[0] = ' '; p++; p = write_b(p, ebuf, event, strlen(event)); if(pe % 2 == 1) { p = write_b(p, ebuf, "*FAILED* ", strlen("*FAILED* ")); logtype = LOG_ERR; } else { p[0] = ' '; p++; } p[0] = '{'; p++; if(pe % 2 == 1 && ((pe & FLAG_TRACE_ERRNO) == FLAG_TRACE_ERRNO)) { int errno_ = errno; if(errno_ > 0) { p = write_key(p, ebuf, "errno"); p = write_d(p, ebuf, errno_); p[0] = ','; p++; p[0] = ' '; p++; knh_ldata2_t d[1]; d[0].svalue = strerror(errno_); if(d[0].svalue != NULL) { p = write_key(p, ebuf, "msg"); p = write_s(p, ebuf, d); p[0] = ','; p++; p[0] = ' '; p++; } } } while(d->type != 0) { char *p2 = write_key(p, ebuf, d[1].key); if(p2 != NULL) { if(d->type == LOGT_sfp) { // TODO d+=2; continue; } DBG_ASSERT(d->type <= LOGT_o); p2 = writeldata[d->type](p2, ebuf, d+2); if(p2 != NULL) { p = write_comma(p2, ebuf, d+3); } } d += 3; } p[0] = '}'; p++; p[0] = 0; knh_syslog(logtype, (const char*)buf); if(isVerbose) { fputs(LOG__(logtype), stderr); fputs(" ", stderr); fputs(buf, stderr); fputs(K_OSLINEFEED, stderr); fflush(stderr); } // if(pe % 2 == 1) { // // } }