+
+ old_logsize = msgbufp->msg_size;
+ old_logdata = msgbufp->msg_bufc;
+ old_bufr = msgbufp->msg_bufr;
+ old_bufx = msgbufp->msg_bufx;
+
+ LOG_SETSIZE_DEBUG("log_setsize(%d): old_logdata %p old_logsize %d old_bufr %d old_bufx %d\n",
+ size, old_logdata, old_logsize, old_bufr, old_bufx);
+
+ /* start "new_logsize" bytes before the write pointer */
+ if (new_logsize <= old_bufx) {
+ count = new_logsize;
+ p = old_logdata + old_bufx - count;
+ } else {
+ /*
+ * if new buffer is bigger, copy what we have and let the
+ * bzero above handle the difference
+ */
+ count = MIN(new_logsize, old_logsize);
+ p = old_logdata + old_logsize - (count - old_bufx);
+ }
+ for (i = 0; i < count; i++) {
+ if (p >= old_logdata + old_logsize)
+ p = old_logdata;
+
+ ch = *p++;
+ new_logdata[i] = ch;
+ }
+
+ new_bufx = i;
+ if (new_bufx >= new_logsize)
+ new_bufx = 0;
+ msgbufp->msg_bufx = new_bufx;
+
+ new_bufr = old_bufx - old_bufr; /* how much were we trailing bufx by? */
+ if (new_bufr < 0)
+ new_bufr += old_logsize;
+ new_bufr = new_bufx - new_bufr; /* now relative to oldest data in new buffer */
+ if (new_bufr < 0)
+ new_bufr += new_logsize;
+ msgbufp->msg_bufr = new_bufr;
+
+ msgbufp->msg_size = new_logsize;
+ msgbufp->msg_bufc = new_logdata;
+
+ LOG_SETSIZE_DEBUG("log_setsize(%d): new_logdata %p new_logsize %d new_bufr %d new_bufx %d\n",
+ size, new_logdata, new_logsize, new_bufr, new_bufx);
+
+ LOG_UNLOCK();
+