ReactOS 0.4.15-dev-7788-g1ad9096
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
27EXPORT int js_snprintf __PR((char *, size_t maxcnt, const char *, ...));
28
29typedef struct {
30 char *ptr;
31 int count;
33
34#ifdef PROTOTYPES
35static void
36_cput(char c, void *l)
37#else
38static void
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
58EXPORT int
59js_snprintf(char *buf, size_t maxcnt, const char *form, ...)
60#else
61EXPORT int
62js_snprintf(buf, maxcnt, form, va_alist)
63 char *buf;
64 unsigned maxcnt;
65 char *form;
66 va_dcl
67#endif
68{
70 int cnt;
71 _BUF bb;
72
73 bb.ptr = buf;
74 bb.count = maxcnt;
75
76#ifdef PROTOTYPES
78#else
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}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
r l[0]
Definition: byte_order.h:168
int form
Definition: main.c:89
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
const GLubyte * c
Definition: glext.h:8905
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
struct BUF _BUF
static void _cput(char c, void *l)
Definition: jssnprintf.c:39
EXPORT int js_snprintf(char *buf, unsigned maxcnt, char *form, va_alist)
Definition: jssnprintf.c:62
#define c
Definition: ke_i.h:80
#define __PR(a)
Definition: prototyp.h:106
#define args
Definition: format.c:66
Definition: jssnprintf.c:29
int count
Definition: jssnprintf.c:31
char * ptr
Definition: jssnprintf.c:30
Definition: match.c:390