2 * Copyright Droids Corporation (2007)
3 * Olivier MATZ <zer0@droids-corp.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Revision : $Id: cirbuf_align.c,v 1.1.2.2 2007-09-12 17:52:20 zer0 Exp $
28 __cirbuf_shift_left(struct cirbuf * cbuf)
31 char tmp = cbuf->buf[cbuf->start];
33 for (i=0 ; i<cbuf->len ; i++) {
34 cbuf->buf[(cbuf->start+i)%cbuf->maxlen] =
35 cbuf->buf[(cbuf->start+i+1)%cbuf->maxlen];
37 cbuf->buf[(cbuf->start-1+cbuf->maxlen)%cbuf->maxlen] = tmp;
38 cbuf->start += (cbuf->maxlen - 1);
39 cbuf->start %= cbuf->maxlen;
40 cbuf->end += (cbuf->maxlen - 1);
41 cbuf->end %= cbuf->maxlen;
45 __cirbuf_shift_right(struct cirbuf * cbuf)
48 char tmp = cbuf->buf[cbuf->end];
50 for (i=0 ; i<cbuf->len ; i++) {
51 cbuf->buf[(cbuf->end+cbuf->maxlen-i)%cbuf->maxlen] =
52 cbuf->buf[(cbuf->end+cbuf->maxlen-i-1)%cbuf->maxlen];
54 cbuf->buf[(cbuf->end+1)%cbuf->maxlen] = tmp;
56 cbuf->start %= cbuf->maxlen;
58 cbuf->end %= cbuf->maxlen;
61 /* XXX we could do a better algorithm here... */
62 void cirbuf_align_left(struct cirbuf * cbuf)
64 if (cbuf->start < cbuf->maxlen/2) {
65 while (cbuf->start != 0) {
66 __cirbuf_shift_left(cbuf);
70 while (cbuf->start != 0) {
71 __cirbuf_shift_right(cbuf);
76 /* XXX we could do a better algorithm here... */
77 void cirbuf_align_right(struct cirbuf * cbuf)
79 if (cbuf->start >= cbuf->maxlen/2) {
80 while (cbuf->end != cbuf->maxlen-1) {
81 __cirbuf_shift_left(cbuf);
85 while (cbuf->start != cbuf->maxlen-1) {
86 __cirbuf_shift_right(cbuf);