int lame_vsprintf(char *str, const char *format, va_list ap) { bool in_control_code = false; char *current = str; for(; *format; format++) { if(!in_control_code) { if(*format == '%') in_control_code = true; else *current++ = *format; } else { switch(*format) { case 'x': case 'X': { unsigned val = va_arg(ap, unsigned); current = write_hex(current, val); break; } case 'd': { unsigned val = va_arg(ap, unsigned); current = write_dec(current, val); break; } case 'p': { void *val = va_arg(ap, void *); current = write_ptr(current, val); break; } case 's': { const char *val = va_arg(ap, const char *); current = write_str(current, val); break; } default: *current++ = *format; break; } in_control_code = false; } } *current++ = '\0'; return current - str; }
ResizeableBuffer& ResizeableBuffer::write(const char* str) { return write_ptr(str,strlen(str)); }
int shared_blk::write( void* p , int sz ) { int write_sz = std::min( sz , static_cast<int>(space())); memcpy( write_ptr() , p , write_sz ); write_skip( write_sz ); return write_sz; }
void save_ns_dbase(void) { dbFILE *f; int i; NickInfo *ni; char **access; static time_t lastwarn = 0; if (!(f = open_db(s_NickServ, NickDBName, "w"))) return; for (ni = firstnick(); ni; ni = nextnick()) { SAFE(write_int8(1, f)); SAFE(write_buffer(ni->nick, f)); SAFE(write_buffer(ni->pass, f)); SAFE(write_string(ni->url, f)); SAFE(write_string(ni->email, f)); SAFE(write_string(ni->last_usermask, f)); SAFE(write_string(ni->last_realname, f)); SAFE(write_string(ni->last_quit, f)); SAFE(write_int32(ni->time_registered, f)); SAFE(write_int32(ni->last_seen, f)); SAFE(write_int16(ni->status, f)); if (ni->link) { SAFE(write_string(ni->link->nick, f)); SAFE(write_int16(ni->linkcount, f)); SAFE(write_int16(ni->channelcount, f)); } else { SAFE(write_string(NULL, f)); SAFE(write_int16(ni->linkcount, f)); SAFE(write_int32(ni->flags, f)); SAFE(write_ptr(ni->suspendinfo, f)); if (ni->suspendinfo) { SAFE(write_buffer(ni->suspendinfo->who, f)); SAFE(write_string(ni->suspendinfo->reason, f)); SAFE(write_int32(ni->suspendinfo->suspended, f)); SAFE(write_int32(ni->suspendinfo->expires, f)); } SAFE(write_int16(ni->accesscount, f)); for (i=0, access=ni->access; i<ni->accesscount; i++, access++) SAFE(write_string(*access, f)); SAFE(write_int16(ni->channelcount, f)); SAFE(write_int16(ni->channelmax, f)); SAFE(write_int16(ni->language, f)); } } /* for (ni) */ { /* This is an UGLY HACK but it simplifies loading. It will go away * in the next file version */ static char buf[256]; SAFE(write_buffer(buf, f)); } close_db(f); return; fail: restore_db(f); log_perror("Write error on %s", NickDBName); if (time(NULL) - lastwarn > WarningTimeout) { wallops(NULL, "Write error on %s: %s", NickDBName, strerror(errno)); lastwarn = time(NULL); } }