Open SCAP Library
|
00001 /* 00002 * Copyright 2009 Red Hat Inc., Durham, North Carolina. 00003 * All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * Authors: 00020 * "Daniel Kopecek" <dkopecek@redhat.com> 00021 */ 00022 00023 #pragma once 00024 #ifndef STRBUF_H 00025 #define STRBUF_H 00026 00027 #include <stddef.h> 00028 #include <unistd.h> 00029 #include <stdio.h> 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif 00034 00035 #define SEAP_STRBUF_MAX 8192 00036 00037 struct strblk { 00038 struct strblk *next; 00039 size_t size; 00040 char data[]; 00041 }; 00042 00043 typedef struct { 00044 struct strblk *beg; 00045 struct strblk *lbo; 00046 size_t blkmax; 00047 size_t blkoff; 00048 size_t size; 00049 } strbuf_t; 00050 00051 strbuf_t *strbuf_new (size_t max); 00052 void strbuf_free (strbuf_t *buf); 00053 00054 int strbuf_add (strbuf_t *buf, const char *str, size_t len); 00055 int strbuf_addf (strbuf_t *buf, char *str, size_t len); 00056 int strbuf_add0 (strbuf_t *buf, const char *str); 00057 int strbuf_add0f (strbuf_t *buf, char *str); 00058 int strbuf_addc (strbuf_t *buf, char ch); 00059 00060 size_t strbuf_size (strbuf_t *buf); 00061 int strbuf_trunc (strbuf_t *buf, size_t len); 00062 size_t strbuf_length (strbuf_t *buf); 00063 00064 char *strbuf_cstr (strbuf_t *buf); 00065 char *strbuf_cstr_r (strbuf_t *buf, char *str, size_t len); 00066 char *strbuf_copy (strbuf_t *buf, void *dst, size_t len); 00067 00068 size_t strbuf_fwrite (FILE *fp, strbuf_t *buf); 00069 ssize_t strbuf_write (strbuf_t *buf, int fd); 00070 00071 #ifdef __cplusplus 00072 } 00073 #endif 00074 00075 #endif /* STRBUF_H */