📄 queue.c
字号:
/* * queue.c * * a byte queue, for buffering keystream and other data * * David A. McGrew * Cisco Systems, Inc. * */#include "err.h"/* * An octet_queue_t is a circular buffer holding some data. There * are four pointers: * * start the start of the buffer * end the end of the buffer * input the position of the next data to be input to the queue * output the position of the next data to be output from the queue * * Here's a diagram, with Xs indicating data in the buffer: * * +---------------+--------------------------------+---------------+ * |XXXXXXXXXXXXXXX| |XXXXXXXXXXXXXXX| * +---------------+--------------------------------+---------------+ * ^ ^ ^ ^ * | | | | * start input output end * * * Any number of octets can be output, but at least QUEUE_INPUT_MIN * octets must be entered at a time. * * */typedef struct { octet_t *start, *end, *input, *output; int length, data;} octet_queue_t;err_status_toctet_queue_alloc(octet_queue_t **queue, int len_octets) { octet_t *pointer; octet_queue_t *q; pointer = malloc(len_octets + sizeof(octet_queue_t)); if (!pointer) return err_status_alloc_err; q = (octet_queue_t *)pointer; q->start = pointer + sizeof(octet_queue_t); q->end = q->start + len_octets; q->input = q->start; q->output = NULL; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -