1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/****************************************************************
* *
* Copyright (c) 2010-2018 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
* the license, please stop and do not read further. *
* *
****************************************************************/
#include "mdef.h"
#include "have_crit.h"
#include "eintr_wrappers.h"
#include "gtm_stdio.h"
#include "gtm_signal.h"
#include <stdarg.h>
#include <errno.h>
/* Collection of eintr wrapper routines for gtm_stdio.h declared routines. Since all of the routines have variable
* length parameter lists, it is not possible to do the wrappers using macros. Some routines may also have additional
* signal blocking implemented to prevent the routines from being re-entered due to signals (known to cause issues on
* some platforms.
*
* Note for the routines that utilize signal blocks, blocksig_initialized may not be set at this point for a variety of
* cases such one as the following:
* 1) If the current image is "dbcertify"
* 2) At startup of GTCM_SERVER or GTCM_GNP_SERVER
* 3) At startup of GT.M (e.g. bad command line "mumps -bad")
* Because of this, we dont have an assert(blocksig_initialized) that similar code in dollarh.c has.
*
* Routines implemented:
* gtm_printf()
* gtm_fprintf()
* gtm_sprintf()
* gtm_snprintf()
* gtm_scanf()
* gtm_fscanf()
* gtm_sscanf()
*/
GBLREF boolean_t blocksig_initialized;
GBLREF sigset_t block_sigsent;
/* Wrapper for printf() */
int gtm_printf(const char *format, ...)
{
va_list printargs;
int retval;
va_start(printargs, format);
VPRINTF(format, printargs, retval);
retval = (-1 == retval) ? errno : 0;
va_end(printargs);
return retval;
}
/* Wrapper for fprintf() */
int gtm_fprintf(FILE *stream, const char *format, ...)
{
va_list printargs, pa_copy;
size_t retval, buflen;
sigset_t savemask;
intrpt_state_t prev_intrpt_state;
retval = 0;
va_start(printargs, format);
VAR_COPY(pa_copy, printargs);
VSNPRINTF(NULL, 0, format, pa_copy, buflen); /* C99: NULL string just returns size */
va_end(pa_copy);
{
char buf[buflen + 1]; /* C99: Variable Length Array, avoids malloc. */
VSNPRINTF(buf, SIZEOF(buf), format, printargs, buflen);
GTM_FWRITE(buf, buflen, 1, stream, buflen, retval);
}
va_end(printargs);
assert(-1 != retval);
return retval;
}
/* Wrapper for sprintf() - unneeded / unwanted as it is not safe */
/* Wrapper for snprintf() */
int gtm_snprintf(char *str, size_t size, const char *format, ...)
{
va_list printargs;
int retval;
va_start(printargs, format);
VSNPRINTF(str, size, format, printargs, retval);
va_end(printargs);
assert(-1 != retval);
return retval;
}
/* Note these functions do not exist on TRU64 (OSF1) */
#ifndef __osf__
/* Wrapper for scanf() */
int gtm_scanf(const char *format, ...)
{
va_list scanargs;
int retval;
va_start(scanargs, format);
VSCANF(format, scanargs, retval);
va_end(scanargs);
return retval;
}
/* Wrapper for fscanf() */
int gtm_fscanf(FILE *stream, const char *format, ...)
{
va_list scanargs;
int retval;
va_start(scanargs, format);
VFSCANF(stream, format, scanargs, retval);
va_end(scanargs);
return retval;
}
/* Wrapper for sscanf() */
int gtm_sscanf(char *str, const char *format, ...)
{
va_list scanargs;
int retval;
va_start(scanargs, format);
VSSCANF(str, format, scanargs, retval);
va_end(scanargs);
return retval;
}
#endif
|