Blame snprintf/wcio.h

Packit c04fcb
/*	$OpenBSD: wcio.h,v 1.1 2005/06/17 20:40:32 espie Exp $	*/
Packit c04fcb
/* $NetBSD: wcio.h,v 1.3 2003/01/18 11:30:00 thorpej Exp $ */
Packit c04fcb
Packit c04fcb
/*-
Packit c04fcb
 * Copyright (c)2001 Citrus Project,
Packit c04fcb
 * All rights reserved.
Packit c04fcb
 *
Packit c04fcb
 * Redistribution and use in source and binary forms, with or without
Packit c04fcb
 * modification, are permitted provided that the following conditions
Packit c04fcb
 * are met:
Packit c04fcb
 * 1. Redistributions of source code must retain the above copyright
Packit c04fcb
 *    notice, this list of conditions and the following disclaimer.
Packit c04fcb
 * 2. Redistributions in binary form must reproduce the above copyright
Packit c04fcb
 *    notice, this list of conditions and the following disclaimer in the
Packit c04fcb
 *    documentation and/or other materials provided with the distribution.
Packit c04fcb
 *
Packit c04fcb
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
Packit c04fcb
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit c04fcb
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit c04fcb
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
Packit c04fcb
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit c04fcb
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit c04fcb
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit c04fcb
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit c04fcb
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit c04fcb
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit c04fcb
 * SUCH DAMAGE.
Packit c04fcb
 *
Packit c04fcb
 * $Citrus$
Packit c04fcb
 */
Packit c04fcb
Packit c04fcb
#ifndef _WCIO_H_
Packit c04fcb
#define _WCIO_H_
Packit c04fcb
Packit c04fcb
/* minimal requirement of SUSv2 */
Packit c04fcb
#define WCIO_UNGETWC_BUFSIZE 1
Packit c04fcb
Packit c04fcb
struct wchar_io_data {
Packit c04fcb
	mbstate_t wcio_mbstate_in;
Packit c04fcb
	mbstate_t wcio_mbstate_out;
Packit c04fcb
Packit c04fcb
	wchar_t wcio_ungetwc_buf[WCIO_UNGETWC_BUFSIZE];
Packit c04fcb
	size_t wcio_ungetwc_inbuf;
Packit c04fcb
Packit c04fcb
	int wcio_mode; /* orientation */
Packit c04fcb
};
Packit c04fcb
Packit c04fcb
#define WCIO_GET(fp) \
Packit c04fcb
	(_EXT(fp) ? &(_EXT(fp)->_wcio) : (struct wchar_io_data *)0)
Packit c04fcb
Packit c04fcb
#define WCIO_GET_NONULL(fp) \
Packit c04fcb
	(&(_EXT(fp)->_wcio))
Packit c04fcb
Packit c04fcb
#define _SET_ORIENTATION(fp, mode) \
Packit c04fcb
do {\
Packit c04fcb
	struct wchar_io_data *_wcio = WCIO_GET(fp); \
Packit c04fcb
	if (_wcio && _wcio->wcio_mode == 0) \
Packit c04fcb
		_wcio->wcio_mode = (mode);\
Packit c04fcb
} while (0)
Packit c04fcb
Packit c04fcb
/*
Packit c04fcb
 * WCIO_FREE should be called by fclose
Packit c04fcb
 */
Packit c04fcb
#define WCIO_FREE(fp) \
Packit c04fcb
do {\
Packit c04fcb
	struct wchar_io_data *_wcio = WCIO_GET(fp); \
Packit c04fcb
	if (_wcio) { \
Packit c04fcb
		_wcio->wcio_mode = 0;\
Packit c04fcb
		_wcio->wcio_ungetwc_inbuf = 0;\
Packit c04fcb
	} \
Packit c04fcb
} while (0)
Packit c04fcb
Packit c04fcb
#define WCIO_FREEUB(fp) \
Packit c04fcb
do {\
Packit c04fcb
	struct wchar_io_data *_wcio = WCIO_GET(fp); \
Packit c04fcb
	if (_wcio) { \
Packit c04fcb
		_wcio->wcio_ungetwc_inbuf = 0;\
Packit c04fcb
	} \
Packit c04fcb
} while (0)
Packit c04fcb
Packit c04fcb
#define WCIO_INIT(fp) \
Packit c04fcb
	memset(WCIO_GET_NONULL(fp), 0, sizeof(struct wchar_io_data))
Packit c04fcb
Packit c04fcb
#endif /*_WCIO_H_*/