/programs/develop/libraries/newlib/stdio/siprintf.c |
---|
0,0 → 1,171 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* |
FUNCTION |
<<siprintf>>, <<fiprintf>>, <<iprintf>>, <<sniprintf>>, <<asiprintf>>, <<asniprintf>>---format output (integer only) |
INDEX |
fiprintf |
INDEX |
_fiprintf_r |
INDEX |
iprintf |
INDEX |
_iprintf_r |
INDEX |
siprintf |
INDEX |
_siprintf_r |
INDEX |
sniprintf |
INDEX |
_sniprintf_r |
INDEX |
asiprintf |
INDEX |
_asiprintf_r |
INDEX |
asniprintf |
INDEX |
_asniprintf_r |
ANSI_SYNOPSIS |
#include <stdio.h> |
int iprintf(const char *<[format]>, ...); |
int fiprintf(FILE *<[fd]>, const char *<[format]> , ...); |
int siprintf(char *<[str]>, const char *<[format]>, ...); |
int sniprintf(char *<[str]>, size_t <[size]>, const char *<[format]>, |
...); |
int asiprintf(char **<[strp]>, const char *<[format]>, ...); |
char *asniprintf(char *<[str]>, size_t *<[size]>, |
const char *<[format]>, ...); |
int _iprintf_r(struct _reent *<[ptr]>, const char *<[format]>, ...); |
int _fiprintf_r(struct _reent *<[ptr]>, FILE *<[fd]>, |
const char *<[format]>, ...); |
int _siprintf_r(struct _reent *<[ptr]>, char *<[str]>, |
const char *<[format]>, ...); |
int _sniprintf_r(struct _reent *<[ptr]>, char *<[str]>, size_t <[size]>, |
const char *<[format]>, ...); |
int _asiprintf_r(struct _reent *<[ptr]>, char **<[strp]>, |
const char *<[format]>, ...); |
char *_asniprintf_r(struct _reent *<[ptr]>, char *<[str]>, |
size_t *<[size]>, const char *<[format]>, ...); |
DESCRIPTION |
<<iprintf>>, <<fiprintf>>, <<siprintf>>, <<sniprintf>>, |
<<asiprintf>>, and <<asniprintf>> are the same as <<printf>>, |
<<fprintf>>, <<sprintf>>, <<snprintf>>, <<asprintf>>, and |
<<asnprintf>>, respectively, except that they restrict usage |
to non-floating-point format specifiers. |
<<_iprintf_r>>, <<_fiprintf_r>>, <<_asiprintf_r>>, |
<<_siprintf_r>>, <<_sniprintf_r>>, <<_asniprintf_r>> are |
simply reentrant versions of the functions above. |
RETURNS |
Similar to <<printf>>, <<fprintf>>, <<sprintf>>, <<snprintf>>, <<asprintf>>, |
and <<asnprintf>>. |
PORTABILITY |
<<iprintf>>, <<fiprintf>>, <<siprintf>>, <<sniprintf>>, <<asiprintf>>, |
and <<asniprintf>> are newlib extensions. |
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, |
<<lseek>>, <<read>>, <<sbrk>>, <<write>>. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#ifdef _HAVE_STDC |
#include <stdarg.h> |
#else |
#include <varargs.h> |
#endif |
#include <limits.h> |
#include "local.h" |
int |
#ifdef _HAVE_STDC |
_DEFUN(_siprintf_r, (ptr, str, fmt), |
struct _reent *ptr _AND |
char *str _AND |
_CONST char *fmt _DOTS) |
#else |
_siprintf_r(ptr, str, fmt, va_alist) |
struct _reent *ptr; |
char *str; |
_CONST char *fmt; |
va_dcl |
#endif |
{ |
int ret; |
va_list ap; |
FILE f; |
f._flags = __SWR | __SSTR; |
f._bf._base = f._p = (unsigned char *) str; |
f._bf._size = f._w = INT_MAX; |
f._file = -1; /* No file. */ |
#ifdef _HAVE_STDC |
va_start (ap, fmt); |
#else |
va_start (ap); |
#endif |
ret = _svfiprintf_r (ptr, &f, fmt, ap); |
va_end (ap); |
*f._p = 0; |
return (ret); |
} |
#ifndef _REENT_ONLY |
int |
#ifdef _HAVE_STDC |
_DEFUN(siprintf, (str, fmt), |
char *str _AND |
_CONST char *fmt _DOTS) |
#else |
siprintf(str, fmt, va_alist) |
char *str; |
_CONST char *fmt; |
va_dcl |
#endif |
{ |
int ret; |
va_list ap; |
FILE f; |
f._flags = __SWR | __SSTR; |
f._bf._base = f._p = (unsigned char *) str; |
f._bf._size = f._w = INT_MAX; |
f._file = -1; /* No file. */ |
#ifdef _HAVE_STDC |
va_start (ap, fmt); |
#else |
va_start (ap); |
#endif |
ret = _svfiprintf_r (_REENT, &f, fmt, ap); |
va_end (ap); |
*f._p = 0; |
return (ret); |
} |
#endif |
/programs/develop/libraries/newlib/stdio/vasniprintf.c |
---|
0,0 → 1,71 |
/* Copyright (C) 2007, 2008 Eric Blake |
* Permission to use, copy, modify, and distribute this software |
* is freely granted, provided that this notice is preserved. |
*/ |
/* This code was derived from asprintf.c */ |
/* doc in viprintf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <stdarg.h> |
#include <limits.h> |
#include <errno.h> |
#include "local.h" |
char * |
_DEFUN(_vasniprintf_r, (ptr, buf, lenp, fmt, ap), |
struct _reent *ptr _AND |
char *buf _AND |
size_t *lenp _AND |
const char *fmt _AND |
va_list ap) |
{ |
int ret; |
FILE f; |
size_t len = *lenp; |
if (buf && len) |
{ |
/* mark an existing buffer, but allow allocation of larger string */ |
f._flags = __SWR | __SSTR | __SOPT; |
} |
else |
{ |
/* mark a zero-length reallocatable buffer */ |
f._flags = __SWR | __SSTR | __SMBF; |
len = 0; |
buf = NULL; |
} |
f._bf._base = f._p = (unsigned char *) buf; |
/* For now, inherit the 32-bit signed limit of FILE._bf._size. |
FIXME - it would be nice to rewrite sys/reent.h to support size_t |
for _size. */ |
if (len > INT_MAX) |
{ |
ptr->_errno = EOVERFLOW; |
return NULL; |
} |
f._bf._size = f._w = len; |
f._file = -1; /* No file. */ |
ret = _svfiprintf_r (ptr, &f, fmt, ap); |
if (ret < 0) |
return NULL; |
*lenp = ret; |
*f._p = '\0'; |
return (char *) f._bf._base; |
} |
#ifndef _REENT_ONLY |
char * |
_DEFUN(vasniprintf, (buf, lenp, fmt, ap), |
char *buf _AND |
size_t *lenp _AND |
const char *fmt _AND |
va_list ap) |
{ |
return _vasniprintf_r (_REENT, buf, lenp, fmt, ap); |
} |
#endif /* ! _REENT_ONLY */ |
/programs/develop/libraries/newlib/stdio/vasnprintf.c |
---|
0,0 → 1,71 |
/* Copyright (C) 2007 Eric Blake |
* Permission to use, copy, modify, and distribute this software |
* is freely granted, provided that this notice is preserved. |
*/ |
/* This code was derived from asprintf.c */ |
/* doc in vfprintf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <stdarg.h> |
#include <limits.h> |
#include <errno.h> |
#include "local.h" |
char * |
_DEFUN(_vasnprintf_r, (ptr, buf, lenp, fmt, ap), |
struct _reent *ptr _AND |
char *buf _AND |
size_t *lenp _AND |
const char *fmt _AND |
va_list ap) |
{ |
int ret; |
FILE f; |
size_t len = *lenp; |
if (buf && len) |
{ |
/* mark an existing buffer, but allow allocation of larger string */ |
f._flags = __SWR | __SSTR | __SOPT; |
} |
else |
{ |
/* mark a zero-length reallocatable buffer */ |
f._flags = __SWR | __SSTR | __SMBF; |
len = 0; |
buf = NULL; |
} |
f._bf._base = f._p = (unsigned char *) buf; |
/* For now, inherit the 32-bit signed limit of FILE._bf._size. |
FIXME - it would be nice to rewrite sys/reent.h to support size_t |
for _size. */ |
if (len > INT_MAX) |
{ |
ptr->_errno = EOVERFLOW; |
return NULL; |
} |
f._bf._size = f._w = len; |
f._file = -1; /* No file. */ |
ret = _svfprintf_r (ptr, &f, fmt, ap); |
if (ret < 0) |
return NULL; |
*lenp = ret; |
*f._p = '\0'; |
return (char *) f._bf._base; |
} |
#ifndef _REENT_ONLY |
char * |
_DEFUN(vasnprintf, (buf, lenp, fmt, ap), |
char *buf _AND |
size_t *lenp _AND |
const char *fmt _AND |
va_list ap) |
{ |
return _vasnprintf_r (_REENT, buf, lenp, fmt, ap); |
} |
#endif /* ! _REENT_ONLY */ |
/programs/develop/libraries/newlib/stdio/vdiprintf.c |
---|
0,0 → 1,47 |
/* Copyright 2005, 2007 Shaun Jackman |
* Permission to use, copy, modify, and distribute this software |
* is freely granted, provided that this notice is preserved. |
*/ |
/* doc in diprintf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <stdarg.h> |
#include "local.h" |
int |
_DEFUN(_vdiprintf_r, (ptr, fd, format, ap), |
struct _reent *ptr _AND |
int fd _AND |
const char *format _AND |
va_list ap) |
{ |
char *p; |
char buf[512]; |
size_t n = sizeof buf; |
_REENT_SMALL_CHECK_INIT (ptr); |
p = _vasniprintf_r (ptr, buf, &n, format, ap); |
if (!p) |
return -1; |
n = _write_r (ptr, fd, p, n); |
if (p != buf) |
_free_r (ptr, p); |
return n; |
} |
#ifndef _REENT_ONLY |
int |
_DEFUN(vdiprintf, (fd, format, ap), |
int fd _AND |
const char *format _AND |
va_list ap) |
{ |
return _vdiprintf_r (_REENT, fd, format, ap); |
} |
#endif /* ! _REENT_ONLY */ |
/programs/develop/libraries/newlib/stdio/vdprintf.c |
---|
0,0 → 1,47 |
/* Copyright 2005, 2007 Shaun Jackman |
* Permission to use, copy, modify, and distribute this software |
* is freely granted, provided that this notice is preserved. |
*/ |
/* doc in dprintf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <stdarg.h> |
#include "local.h" |
int |
_DEFUN(_vdprintf_r, (ptr, fd, format, ap), |
struct _reent *ptr _AND |
int fd _AND |
const char *format _AND |
va_list ap) |
{ |
char *p; |
char buf[512]; |
size_t n = sizeof buf; |
_REENT_SMALL_CHECK_INIT (ptr); |
p = _vasnprintf_r (ptr, buf, &n, format, ap); |
if (!p) |
return -1; |
n = _write_r (ptr, fd, p, n); |
if (p != buf) |
_free_r (ptr, p); |
return n; |
} |
#ifndef _REENT_ONLY |
int |
_DEFUN(vdprintf, (fd, format, ap), |
int fd _AND |
const char *format _AND |
va_list ap) |
{ |
return _vdprintf_r (_REENT, fd, format, ap); |
} |
#endif /* ! _REENT_ONLY */ |