/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* k5buf.c
*
* Copyright 2008 Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Implement the k5buf string buffer module.
*/
which builds after this directory. */
#include "k5buf-int.h"
#include <assert.h>
/*
* Structure invariants:
*
* buftype is BUFTYPE_FIXED, BUFTYPE_DYNAMIC, or BUFTYPE_ERROR
* if buftype is not BUFTYPE_ERROR:
* space > 0
* space <= floor(SIZE_MAX / 2) (to fit within ssize_t)
* len < space
* data[len] = '\0'
*/
/* Make sure there is room for LEN more characters in BUF, in addition
to the null terminator and what's already in there. Return true on
success. On failure, set the error flag and return false. */
{
char *new_data;
return 0;
return 1;
goto error_exit;
new_space *= 2;
goto error_exit;
goto error_exit;
return 1;
}
return 0;
}
{
}
{
return;
}
}
{
}
{
return;
}
{
int r;
char *tmp;
return;
/* Format the data directly into the fixed buffer. */
if (SNPRINTF_OVERFLOW(r, remaining))
else
return;
}
/* Optimistically format the data directly into the dynamic buffer. */
if (!SNPRINTF_OVERFLOW(r, remaining)) {
return;
}
if (r >= 0) {
/* snprintf correctly told us how much space is required. */
if (!ensure_space(buf, r))
return;
else
return;
}
/* It's a pre-C99 snprintf implementation, or something else went
wrong. Fall back to asprintf. */
if (r < 0) {
return;
}
if (ensure_space(buf, r)) {
/* Copy the temporary string into buf, including terminator. */
}
}
{
return;
}
{
}
{
}
{
return;
}