ReactOS
0.4.15-dev-8612-g0707475
jssnprintf.c
Go to the documentation of this file.
1
/* @(#)jssnprintf.c 1.14 17/08/03 Copyright 1985, 1995-2017 J. Schilling */
2
/*
3
* Copyright (c) 1985, 1995-2017 J. Schilling
4
*/
5
/*
6
* The contents of this file are subject to the terms of the
7
* Common Development and Distribution License, Version 1.0 only
8
* (the "License"). You may not use this file except in compliance
9
* with the License.
10
*
11
* See the file CDDL.Schily.txt in this distribution for details.
12
* A copy of the CDDL is also available via the Internet at
13
* http://www.opensource.org/licenses/cddl1.txt
14
*
15
* When distributing Covered Code, include this CDDL HEADER in each
16
* file and include the License file CDDL.Schily.txt from this distribution.
17
*/
18
19
#include <
schily/mconfig.h
>
20
#include <
schily/unistd.h
>
/* include <sys/types.h> try to get size_t */
21
#include <
schily/stdio.h
>
/* Try again for size_t */
22
#include <
schily/stdlib.h
>
/* Try again for size_t */
23
#include <
schily/varargs.h
>
24
#include <
schily/standard.h
>
25
#include <
schily/schily.h
>
26
27
EXPORT
int
js_snprintf
__PR
((
char
*,
size_t
maxcnt,
const
char
*, ...));
28
29
typedef
struct
{
30
char
*
ptr
;
31
int
count
;
32
} *
BUF
,
_BUF
;
33
34
#ifdef PROTOTYPES
35
static
void
36
_cput
(
char
c
,
void
*
l
)
37
#else
38
static
void
39
_cput
(
c
,
l
)
40
char
c
;
41
void
*
l
;
42
#endif
43
{
44
register
BUF
bp = (
BUF
)
l
;
45
46
if
(--bp->
count
> 0) {
47
*bp->
ptr
++ =
c
;
48
}
else
{
49
/*
50
* Make sure that there will never be a negative overflow.
51
*/
52
bp->
count
++;
53
}
54
}
55
56
/* VARARGS2 */
57
#ifdef PROTOTYPES
58
EXPORT
int
59
js_snprintf
(
char
*
buf
,
size_t
maxcnt,
const
char
*
form
, ...)
60
#else
61
EXPORT
int
62
js_snprintf
(
buf
, maxcnt,
form
, va_alist)
63
char
*
buf
;
64
unsigned
maxcnt;
65
char
*
form
;
66
va_dcl
67
#endif
68
{
69
va_list
args
;
70
int
cnt;
71
_BUF
bb;
72
73
bb.
ptr
=
buf
;
74
bb.
count
= maxcnt;
75
76
#ifdef PROTOTYPES
77
va_start
(
args
,
form
);
78
#else
79
va_start
(
args
);
80
#endif
81
cnt =
format
(
_cput
, &bb,
form
,
args
);
82
va_end
(
args
);
83
if
(maxcnt > 0)
84
*(bb.
ptr
) =
'\0'
;
85
if
(bb.
count
< 0)
86
return
(-1);
87
88
return
(cnt);
89
}
va_list
char * va_list
Definition:
acmsvcex.h:78
va_end
#define va_end(ap)
Definition:
acmsvcex.h:90
va_start
#define va_start(ap, A)
Definition:
acmsvcex.h:91
l
r l[0]
Definition:
byte_order.h:168
form
int form
Definition:
main.c:89
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition:
gl.h:1546
c
const GLubyte * c
Definition:
glext.h:8905
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition:
glext.h:7751
_BUF
struct BUF _BUF
_cput
static void _cput(char c, void *l)
Definition:
jssnprintf.c:39
js_snprintf
EXPORT int js_snprintf(char *buf, unsigned maxcnt, char *form, va_alist)
Definition:
jssnprintf.c:62
c
#define c
Definition:
ke_i.h:80
mconfig.h
__PR
#define __PR(a)
Definition:
prototyp.h:106
schily.h
args
#define args
Definition:
format.c:66
standard.h
BUF
Definition:
jssnprintf.c:29
BUF::count
int count
Definition:
jssnprintf.c:31
BUF::ptr
char * ptr
Definition:
jssnprintf.c:30
EXPORT
Definition:
spec2def.c:21
args
Definition:
match.c:390
stdio.h
stdlib.h
unistd.h
varargs.h
sdk
tools
mkisofs
schilytools
libschily
jssnprintf.c
Generated on Fri Sep 6 2024 06:14:04 for ReactOS by
1.9.6