003 File Manager
Current Path:
/usr/src/contrib/libxo/libxo
usr
/
src
/
contrib
/
libxo
/
libxo
/
📁
..
📄
Makefile.am
(1.9 KB)
📄
add.man.in
(523 B)
📄
gen-wide.sh
(1.01 KB)
📄
libxo.3
(8.18 KB)
📄
libxo.c
(205.77 KB)
📄
xo.h
(18.36 KB)
📄
xo_attr.3
(1.88 KB)
📄
xo_buf.h
(3.54 KB)
📄
xo_create.3
(1.59 KB)
📄
xo_emit.3
(2.92 KB)
📄
xo_emit_err.3
(2 KB)
📄
xo_emit_f.3
(3.27 KB)
📄
xo_encoder.c
(8.97 KB)
📄
xo_encoder.h
(5.46 KB)
📄
xo_err.3
(1.97 KB)
📄
xo_error.3
(1.06 KB)
📄
xo_explicit.h
(2.1 KB)
📄
xo_finish.3
(1.05 KB)
📄
xo_flush.3
(1.01 KB)
📄
xo_format.5
(33.64 KB)
📄
xo_humanize.h
(5.02 KB)
📄
xo_message.3
(2.02 KB)
📄
xo_no_setlocale.3
(1.12 KB)
📄
xo_open_container.3
(4.85 KB)
📄
xo_open_list.3
(4.77 KB)
📄
xo_open_marker.3
(3.22 KB)
📄
xo_options.7
(4.06 KB)
📄
xo_parse_args.3
(3.77 KB)
📄
xo_set_allocator.3
(1.33 KB)
📄
xo_set_flags.3
(3.48 KB)
📄
xo_set_info.3
(2.61 KB)
📄
xo_set_options.3
(944 B)
📄
xo_set_style.3
(1.47 KB)
📄
xo_set_syslog_enterprise_id.3
(1.06 KB)
📄
xo_set_version.3
(1.09 KB)
📄
xo_set_writer.3
(1.48 KB)
📄
xo_syslog.3
(2.32 KB)
📄
xo_syslog.c
(19.3 KB)
📄
xo_wcwidth.h
(13.69 KB)
Editing: xo_buf.h
/* * Copyright (c) 2015, Juniper Networks, Inc. * All rights reserved. * This SOFTWARE is licensed under the LICENSE provided in the * ../Copyright file. By downloading, installing, copying, or otherwise * using the SOFTWARE, you agree to be bound by the terms of that * LICENSE. * Phil Shafer, August 2015 */ /* * This file is an _internal_ part of the libxo plumbing, not suitable * for external use. It is not considered part of the libxo API and * will not be a stable part of that API. Mine, not your's, dude... * The real hope is that something like this will become a standard part * of libc and I can kill this off. */ #ifndef XO_BUF_H #define XO_BUF_H #define XO_BUFSIZ (8*1024) /* Initial buffer size */ #define XO_BUF_HIGH_WATER (XO_BUFSIZ - 512) /* When to auto-flush */ /* * xo_buffer_t: a memory buffer that can be grown as needed. We * use them for building format strings and output data. */ typedef struct xo_buffer_s { char *xb_bufp; /* Buffer memory */ char *xb_curp; /* Current insertion point */ ssize_t xb_size; /* Size of buffer */ } xo_buffer_t; /* * Initialize the contents of an xo_buffer_t. */ static inline void xo_buf_init (xo_buffer_t *xbp) { xbp->xb_size = XO_BUFSIZ; xbp->xb_bufp = xo_realloc(NULL, xbp->xb_size); xbp->xb_curp = xbp->xb_bufp; } /* * Reset the buffer to empty */ static inline void xo_buf_reset (xo_buffer_t *xbp) { xbp->xb_curp = xbp->xb_bufp; } /* * Return the number of bytes left in the buffer */ static inline int xo_buf_left (xo_buffer_t *xbp) { return xbp->xb_size - (xbp->xb_curp - xbp->xb_bufp); } /* * See if the buffer to empty */ static inline int xo_buf_is_empty (xo_buffer_t *xbp) { return (xbp->xb_curp == xbp->xb_bufp); } /* * Return the current offset */ static inline ssize_t xo_buf_offset (xo_buffer_t *xbp) { return xbp ? (xbp->xb_curp - xbp->xb_bufp) : 0; } static inline char * xo_buf_data (xo_buffer_t *xbp, ssize_t offset) { if (xbp == NULL) return NULL; return xbp->xb_bufp + offset; } static inline char * xo_buf_cur (xo_buffer_t *xbp) { if (xbp == NULL) return NULL; return xbp->xb_curp; } /* * Initialize the contents of an xo_buffer_t. */ static inline void xo_buf_cleanup (xo_buffer_t *xbp) { if (xbp->xb_bufp) xo_free(xbp->xb_bufp); bzero(xbp, sizeof(*xbp)); } /* * Does the buffer have room for the given number of bytes of data? * If not, realloc the buffer to make room. If that fails, we * return 0 to tell the caller they are in trouble. */ static inline int xo_buf_has_room (xo_buffer_t *xbp, ssize_t len) { if (xbp->xb_curp + len >= xbp->xb_bufp + xbp->xb_size) { /* * Find out how much new space we need, round it up to XO_BUFSIZ */ ssize_t sz = (xbp->xb_curp + len) - xbp->xb_bufp; sz = (sz + XO_BUFSIZ - 1) & ~(XO_BUFSIZ - 1); char *bp = xo_realloc(xbp->xb_bufp, sz); if (bp == NULL) return 0; xbp->xb_curp = bp + (xbp->xb_curp - xbp->xb_bufp); xbp->xb_bufp = bp; xbp->xb_size = sz; } return 1; } /* * Append the given string to the given buffer */ static inline void xo_buf_append (xo_buffer_t *xbp, const char *str, ssize_t len) { if (str == NULL || len == 0 || !xo_buf_has_room(xbp, len)) return; memcpy(xbp->xb_curp, str, len); xbp->xb_curp += len; } /* * Append the given NUL-terminated string to the given buffer */ static inline void xo_buf_append_str (xo_buffer_t *xbp, const char *str) { ssize_t len = strlen(str); if (!xo_buf_has_room(xbp, len)) return; memcpy(xbp->xb_curp, str, len); xbp->xb_curp += len; } #endif /* XO_BUF_H */
Upload File
Create Folder