2007-08-01 04:48:17 +08:00
|
|
|
/* smallprint.cc: small print routines for WIN32
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2007-08-01 04:48:17 +08:00
|
|
|
#include "ntdll.h"
|
2012-02-15 23:33:56 +08:00
|
|
|
#include "sync.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2008-03-15 04:43:28 +08:00
|
|
|
#include <wchar.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2018-03-03 01:09:35 +08:00
|
|
|
/*
|
|
|
|
Meaning of format conversion specifiers. If 'l' isn't explicitely mentioned,
|
|
|
|
it's ignored!
|
|
|
|
|
|
|
|
0 modifier: pad with zero instead of spaces
|
|
|
|
0-9 modifier: field length
|
|
|
|
+ modifier: always add sign
|
|
|
|
l modifier to d, o, R, u, x, y: 4 byte on 32 bit, 8 byte on 64 bit
|
|
|
|
l modifier to s, S, W: non-ASCII tweaking
|
|
|
|
_ modifier: print lower case hex chars a-f instead of A-F
|
|
|
|
|
|
|
|
c char
|
|
|
|
C WCHAR/wchar_t
|
|
|
|
d signed int, 4 byte
|
|
|
|
D signed long long, 8 byte
|
|
|
|
E GetLastError
|
|
|
|
o octal unsigned int, 4 byte
|
|
|
|
O octal unsigned long long, 8 byte
|
|
|
|
p address
|
|
|
|
P process name
|
|
|
|
R return value, 4 byte.
|
|
|
|
s char *
|
|
|
|
S PUNICODE_STRING
|
|
|
|
u unsigned int, 4 byte
|
|
|
|
U unsigned long long, 8 byte
|
|
|
|
W PWCHAR/wchar_t *
|
|
|
|
x hex unsigned int, 4 byte
|
|
|
|
X hex unsigned long long, 8 byte
|
|
|
|
y 0x hex unsigned int, 4 byte
|
|
|
|
Y 0x hex unsigned long long, 8 byte
|
|
|
|
*/
|
|
|
|
|
2005-02-01 03:52:03 +08:00
|
|
|
#define LLMASK (0xffffffffffffffffULL)
|
|
|
|
#define LMASK (0xffffffff)
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
#define rnarg(dst, base, dosign, len, pad) __rn ((dst), (base), (dosign), va_arg (ap, int32_t), len, pad, LMASK)
|
|
|
|
#define rnargLL(dst, base, dosign, len, pad) __rn ((dst), (base), (dosign), va_arg (ap, uint64_t), len, pad, LLMASK)
|
2005-02-01 03:52:03 +08:00
|
|
|
|
2018-03-03 01:09:35 +08:00
|
|
|
static const char hex_str_upper[] = "0123456789ABCDEF";
|
|
|
|
static const char hex_str_lower[] = "0123456789abcdef";
|
2009-10-30 17:02:30 +08:00
|
|
|
|
2012-02-15 23:33:56 +08:00
|
|
|
class tmpbuf
|
|
|
|
{
|
|
|
|
static WCHAR buf[NT_MAX_PATH];
|
|
|
|
static muto lock;
|
|
|
|
bool locked;
|
|
|
|
public:
|
|
|
|
operator WCHAR * ()
|
|
|
|
{
|
|
|
|
if (!locked)
|
|
|
|
{
|
|
|
|
lock.init ("smallprint_buf")->acquire ();
|
|
|
|
locked = true;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
operator char * () {return (char *) ((WCHAR *) *this);}
|
|
|
|
|
|
|
|
tmpbuf (): locked (false) {};
|
|
|
|
~tmpbuf ()
|
|
|
|
{
|
|
|
|
if (locked)
|
|
|
|
lock.release ();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WCHAR tmpbuf::buf[NT_MAX_PATH];
|
2018-03-13 05:13:20 +08:00
|
|
|
NO_COPY muto tmpbuf::lock;
|
2012-02-15 23:33:56 +08:00
|
|
|
|
2022-08-20 03:52:45 +08:00
|
|
|
static char *
|
2005-02-01 03:52:03 +08:00
|
|
|
__rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned long long mask)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-02-23 02:22:24 +08:00
|
|
|
/* longest number is ULLONG_MAX, 18446744073709551615, 20 digits */
|
2005-02-01 03:52:03 +08:00
|
|
|
unsigned long long uval = 0;
|
2002-02-23 02:22:24 +08:00
|
|
|
char res[20];
|
2000-02-18 03:38:33 +08:00
|
|
|
int l = 0;
|
2018-03-03 01:09:35 +08:00
|
|
|
const char *hex_str;
|
|
|
|
|
|
|
|
if (base < 0)
|
|
|
|
{
|
|
|
|
base = -base;
|
|
|
|
hex_str = hex_str_lower;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hex_str = hex_str_upper;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (dosign && val < 0)
|
|
|
|
{
|
|
|
|
*dst++ = '-';
|
|
|
|
uval = -val;
|
|
|
|
}
|
|
|
|
else if (dosign > 0 && val > 0)
|
|
|
|
{
|
|
|
|
*dst++ = '+';
|
|
|
|
uval = val;
|
|
|
|
}
|
|
|
|
else
|
2005-02-01 03:52:03 +08:00
|
|
|
uval = val;
|
|
|
|
|
|
|
|
uval &= mask;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-10-30 17:02:30 +08:00
|
|
|
res[l++] = hex_str[uval % base];
|
2000-02-18 03:38:33 +08:00
|
|
|
uval /= base;
|
|
|
|
}
|
|
|
|
while (uval);
|
|
|
|
|
2005-02-01 04:55:33 +08:00
|
|
|
while (len-- > l)
|
2000-02-18 03:38:33 +08:00
|
|
|
*dst++ = pad;
|
|
|
|
|
|
|
|
while (l > 0)
|
2005-02-01 04:55:33 +08:00
|
|
|
*dst++ = res[--l];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2020-05-25 19:10:41 +08:00
|
|
|
extern "C" int
|
2000-02-18 03:38:33 +08:00
|
|
|
__small_vsprintf (char *dst, const char *fmt, va_list ap)
|
|
|
|
{
|
2012-02-15 23:33:56 +08:00
|
|
|
tmpbuf tmp;
|
2000-02-18 03:38:33 +08:00
|
|
|
char *orig = dst;
|
|
|
|
const char *s;
|
2007-08-01 15:39:21 +08:00
|
|
|
PWCHAR w;
|
|
|
|
UNICODE_STRING uw, *us;
|
2013-04-23 17:44:36 +08:00
|
|
|
int base = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2006-10-27 18:41:51 +08:00
|
|
|
DWORD err = GetLastError ();
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
intptr_t Rval = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
while (*fmt)
|
|
|
|
{
|
|
|
|
int i, n = 0x7fff;
|
2009-10-30 17:02:30 +08:00
|
|
|
bool l_opt = false;
|
2018-03-03 01:09:35 +08:00
|
|
|
/* set to -1 on '_', indicates upper (1)/lower(-1) case */
|
|
|
|
int h_opt = 1;
|
|
|
|
const char *hex_str = hex_str_upper;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (*fmt != '%')
|
|
|
|
*dst++ = *fmt++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
char pad = ' ';
|
|
|
|
int addsign = -1;
|
|
|
|
|
|
|
|
switch (*++fmt)
|
|
|
|
{
|
|
|
|
case '+':
|
|
|
|
addsign = 1;
|
|
|
|
fmt++;
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
*dst++ = *fmt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char c = *fmt++;
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case '0':
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
pad = '0';
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2018-03-03 01:09:35 +08:00
|
|
|
case '1' ... '9':
|
2000-02-18 03:38:33 +08:00
|
|
|
len = len * 10 + (c - '0');
|
|
|
|
continue;
|
|
|
|
case 'l':
|
2009-10-30 17:02:30 +08:00
|
|
|
l_opt = true;
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
2018-03-03 01:09:35 +08:00
|
|
|
case '_':
|
|
|
|
h_opt = -1;
|
|
|
|
hex_str = hex_str_lower;
|
|
|
|
continue;
|
2000-02-18 03:38:33 +08:00
|
|
|
case 'c':
|
2012-07-30 05:42:10 +08:00
|
|
|
{
|
2012-08-17 07:34:45 +08:00
|
|
|
unsigned char c = (va_arg (ap, int) & 0xff);
|
2012-07-30 05:42:10 +08:00
|
|
|
if (isprint (c) || pad != '0')
|
|
|
|
*dst++ = c;
|
|
|
|
else
|
2012-08-17 07:34:45 +08:00
|
|
|
{
|
|
|
|
*dst++ = '0';
|
|
|
|
*dst++ = 'x';
|
2018-03-03 01:09:35 +08:00
|
|
|
dst = __rn (dst, h_opt * 16, 0, c, len, pad, LMASK);
|
2012-08-17 07:34:45 +08:00
|
|
|
}
|
2012-07-30 05:42:10 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2007-08-01 04:48:17 +08:00
|
|
|
case 'C':
|
|
|
|
{
|
|
|
|
WCHAR wc = (WCHAR) va_arg (ap, int);
|
2017-10-10 00:57:58 +08:00
|
|
|
char buf[MB_LEN_MAX+1] = "", *c;
|
|
|
|
sys_wcstombs (buf, MB_LEN_MAX+1, &wc, 1);
|
2007-08-01 04:48:17 +08:00
|
|
|
for (c = buf; *c; ++c)
|
2012-05-17 10:18:41 +08:00
|
|
|
*dst++ = *c;
|
2007-08-01 04:48:17 +08:00
|
|
|
}
|
2014-05-19 18:42:04 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
case 'E':
|
|
|
|
strcpy (dst, "Win32 error ");
|
2006-10-27 18:41:51 +08:00
|
|
|
dst = __rn (dst + sizeof ("Win32 error"), 10, 0, err, len, pad, LMASK);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2011-12-04 05:43:27 +08:00
|
|
|
case 'R':
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
if (l_opt)
|
|
|
|
Rval = va_arg (ap, int64_t);
|
|
|
|
else
|
|
|
|
Rval = va_arg (ap, int32_t);
|
|
|
|
dst = __rn (dst, 10, addsign, Rval, len, pad, LMASK);
|
2011-12-04 05:43:27 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2013-04-23 17:44:36 +08:00
|
|
|
case 'd':
|
|
|
|
base = 10;
|
|
|
|
if (l_opt)
|
|
|
|
goto gen_decimalLL;
|
|
|
|
goto gen_decimal;
|
2000-02-18 03:38:33 +08:00
|
|
|
case 'u':
|
2013-04-23 17:44:36 +08:00
|
|
|
base = 10;
|
|
|
|
addsign = 0;
|
|
|
|
if (l_opt)
|
|
|
|
goto gen_decimalLL;
|
|
|
|
goto gen_decimal;
|
2002-05-23 14:00:49 +08:00
|
|
|
case 'o':
|
2013-04-23 17:44:36 +08:00
|
|
|
base = 8;
|
|
|
|
addsign = 0;
|
|
|
|
if (l_opt)
|
|
|
|
goto gen_decimalLL;
|
|
|
|
goto gen_decimal;
|
|
|
|
case 'y':
|
2000-02-18 03:38:33 +08:00
|
|
|
*dst++ = '0';
|
|
|
|
*dst++ = 'x';
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2000-02-18 03:38:33 +08:00
|
|
|
case 'x':
|
2013-04-23 17:44:36 +08:00
|
|
|
base = 16;
|
|
|
|
addsign = 0;
|
|
|
|
if (l_opt)
|
|
|
|
goto gen_decimalLL;
|
|
|
|
gen_decimal:
|
2018-03-03 01:09:35 +08:00
|
|
|
dst = rnarg (dst, h_opt * base, addsign, len, pad);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2013-04-23 17:44:36 +08:00
|
|
|
case 'D':
|
|
|
|
base = 10;
|
|
|
|
goto gen_decimalLL;
|
|
|
|
case 'U':
|
|
|
|
base = 10;
|
|
|
|
addsign = 0;
|
|
|
|
goto gen_decimalLL;
|
|
|
|
case 'O':
|
|
|
|
base = 8;
|
|
|
|
addsign = 0;
|
|
|
|
goto gen_decimalLL;
|
|
|
|
case 'Y':
|
|
|
|
*dst++ = '0';
|
|
|
|
*dst++ = 'x';
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2002-02-23 02:22:24 +08:00
|
|
|
case 'X':
|
2013-04-23 17:44:36 +08:00
|
|
|
base = 16;
|
|
|
|
addsign = 0;
|
|
|
|
gen_decimalLL:
|
2018-03-03 01:09:35 +08:00
|
|
|
dst = rnargLL (dst, h_opt * base, addsign, len, pad);
|
2013-04-23 17:44:36 +08:00
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
*dst++ = '0';
|
|
|
|
*dst++ = 'x';
|
2018-03-03 01:09:35 +08:00
|
|
|
dst = rnargLL (dst, h_opt * 16, 0, len, pad);
|
2002-02-23 02:22:24 +08:00
|
|
|
break;
|
2007-08-01 15:39:21 +08:00
|
|
|
case '.':
|
|
|
|
n = strtol (fmt, (char **) &fmt, 10);
|
|
|
|
if (*fmt++ != 's')
|
|
|
|
goto endfor;
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2007-08-01 15:39:21 +08:00
|
|
|
case 's':
|
|
|
|
s = va_arg (ap, char *);
|
|
|
|
if (s == NULL)
|
|
|
|
s = "(null)";
|
|
|
|
fillin:
|
|
|
|
for (i = 0; *s && i < n; i++)
|
2009-10-30 17:02:30 +08:00
|
|
|
if (l_opt && ((*(unsigned char *)s <= 0x1f && *s != '\n')
|
|
|
|
|| *(unsigned char *)s >= 0x7f))
|
|
|
|
{
|
2011-06-06 13:02:13 +08:00
|
|
|
*dst++ = '\\';
|
2009-10-30 17:02:30 +08:00
|
|
|
*dst++ = 'x';
|
|
|
|
*dst++ = hex_str[*(unsigned char *)s >> 4];
|
|
|
|
*dst++ = hex_str[*(unsigned char *)s++ & 0xf];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*dst++ = *s++;
|
2007-08-01 15:39:21 +08:00
|
|
|
break;
|
2015-07-20 04:38:30 +08:00
|
|
|
case 'P':
|
|
|
|
RtlInitUnicodeString (us = &uw, global_progname);
|
|
|
|
goto wfillin;
|
2007-08-01 15:39:21 +08:00
|
|
|
case 'W':
|
|
|
|
w = va_arg (ap, PWCHAR);
|
2009-03-23 23:48:16 +08:00
|
|
|
RtlInitUnicodeString (us = &uw, w ?: L"(null)");
|
2007-08-01 15:39:21 +08:00
|
|
|
goto wfillin;
|
2007-08-01 04:48:17 +08:00
|
|
|
case 'S':
|
2007-08-01 15:39:21 +08:00
|
|
|
us = va_arg (ap, PUNICODE_STRING);
|
2009-03-23 23:48:16 +08:00
|
|
|
if (!us)
|
|
|
|
RtlInitUnicodeString (us = &uw, L"(null)");
|
2007-08-01 15:39:21 +08:00
|
|
|
wfillin:
|
2009-10-30 17:02:30 +08:00
|
|
|
if (l_opt)
|
|
|
|
{
|
|
|
|
for (USHORT i = 0; i < us->Length / sizeof (WCHAR); ++i)
|
|
|
|
{
|
|
|
|
WCHAR w = us->Buffer[i];
|
|
|
|
if ((w <= 0x1f && w != '\n') || w >= 0x7f)
|
|
|
|
{
|
|
|
|
*dst++ = '\\';
|
|
|
|
*dst++ = 'x';
|
|
|
|
*dst++ = hex_str[(w >> 12) & 0xf];
|
|
|
|
*dst++ = hex_str[(w >> 8) & 0xf];
|
|
|
|
*dst++ = hex_str[(w >> 4) & 0xf];
|
|
|
|
*dst++ = hex_str[w & 0xf];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*dst++ = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sys_wcstombs (tmp, NT_MAX_PATH, us->Buffer,
|
|
|
|
us->Length / sizeof (WCHAR)))
|
|
|
|
{
|
|
|
|
s = tmp;
|
|
|
|
goto fillin;
|
|
|
|
}
|
2007-08-01 04:48:17 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
default:
|
|
|
|
*dst++ = '?';
|
|
|
|
*dst++ = fmt[-1];
|
|
|
|
}
|
|
|
|
endfor:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-04 05:43:27 +08:00
|
|
|
if (Rval < 0)
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
dst = stpcpy (dst, ", errno ");
|
2011-12-04 05:43:27 +08:00
|
|
|
dst = __rn (dst, 10, false, get_errno (), 0, 0, LMASK);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
*dst = 0;
|
2006-10-27 18:41:51 +08:00
|
|
|
SetLastError (err);
|
2000-02-18 03:38:33 +08:00
|
|
|
return dst - orig;
|
|
|
|
}
|
|
|
|
|
2020-05-25 19:10:41 +08:00
|
|
|
extern "C" int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
__small_sprintf (char *dst, const char *fmt, ...)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
r = __small_vsprintf (dst, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-01-03 13:12:22 +08:00
|
|
|
void
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
small_printf (const char *fmt, ...)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-08-23 01:50:22 +08:00
|
|
|
char buf[16384];
|
2000-02-18 03:38:33 +08:00
|
|
|
va_list ap;
|
|
|
|
DWORD done;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
#if 0 /* Turn on to force console errors */
|
|
|
|
extern SECURITY_ATTRIBUTES sec_none;
|
|
|
|
HANDLE h = CreateFileA ("CONOUT$", GENERIC_READ|GENERIC_WRITE,
|
|
|
|
FILE_SHARE_WRITE | FILE_SHARE_WRITE, &sec_none,
|
|
|
|
OPEN_EXISTING, 0, 0);
|
|
|
|
if (h)
|
|
|
|
SetStdHandle (STD_ERROR_HANDLE, h);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
count = __small_vsprintf (buf, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
2001-08-23 01:50:22 +08:00
|
|
|
WriteFile (GetStdHandle (STD_ERROR_HANDLE), buf, count, &done, NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
FlushFileBuffers (GetStdHandle (STD_ERROR_HANDLE));
|
|
|
|
}
|
2001-08-23 01:50:22 +08:00
|
|
|
|
|
|
|
#ifdef DEBUGGING
|
|
|
|
static HANDLE NO_COPY console_handle = NULL;
|
2009-01-03 13:12:22 +08:00
|
|
|
void
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
console_printf (const char *fmt, ...)
|
2001-08-23 01:50:22 +08:00
|
|
|
{
|
|
|
|
char buf[16384];
|
|
|
|
va_list ap;
|
|
|
|
DWORD done;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (!console_handle)
|
2001-09-10 03:06:50 +08:00
|
|
|
console_handle = CreateFileA ("CON", GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
|
|
|
|
if (console_handle == INVALID_HANDLE_VALUE)
|
|
|
|
console_handle = GetStdHandle (STD_ERROR_HANDLE);
|
|
|
|
|
2001-08-23 01:50:22 +08:00
|
|
|
va_start (ap, fmt);
|
|
|
|
count = __small_vsprintf (buf, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
WriteFile (console_handle, buf, count, &done, NULL);
|
|
|
|
FlushFileBuffers (console_handle);
|
|
|
|
}
|
|
|
|
#endif
|
2008-03-15 04:43:28 +08:00
|
|
|
|
|
|
|
#define wrnarg(dst, base, dosign, len, pad) __wrn ((dst), (base), (dosign), va_arg (ap, long), len, pad, LMASK)
|
|
|
|
#define wrnargLL(dst, base, dosign, len, pad) __wrn ((dst), (base), (dosign), va_arg (ap, unsigned long long), len, pad, LLMASK)
|
|
|
|
|
2022-08-20 03:52:45 +08:00
|
|
|
static PWCHAR
|
2008-03-15 04:43:28 +08:00
|
|
|
__wrn (PWCHAR dst, int base, int dosign, long long val, int len, int pad, unsigned long long mask)
|
|
|
|
{
|
|
|
|
/* longest number is ULLONG_MAX, 18446744073709551615, 20 digits */
|
|
|
|
unsigned long long uval = 0;
|
|
|
|
WCHAR res[20];
|
|
|
|
int l = 0;
|
2018-03-03 01:09:35 +08:00
|
|
|
const char *hex_str;
|
|
|
|
|
|
|
|
if (base < 0)
|
|
|
|
{
|
|
|
|
base = -base;
|
|
|
|
hex_str = hex_str_lower;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hex_str = hex_str_upper;
|
2008-03-15 04:43:28 +08:00
|
|
|
|
|
|
|
if (dosign && val < 0)
|
|
|
|
{
|
|
|
|
*dst++ = L'-';
|
|
|
|
uval = -val;
|
|
|
|
}
|
|
|
|
else if (dosign > 0 && val > 0)
|
|
|
|
{
|
|
|
|
*dst++ = L'+';
|
|
|
|
uval = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
uval = val;
|
|
|
|
|
|
|
|
uval &= mask;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-10-30 17:02:30 +08:00
|
|
|
res[l++] = hex_str[uval % base];
|
2008-03-15 04:43:28 +08:00
|
|
|
uval /= base;
|
|
|
|
}
|
|
|
|
while (uval);
|
|
|
|
|
|
|
|
while (len-- > l)
|
|
|
|
*dst++ = pad;
|
|
|
|
|
|
|
|
while (l > 0)
|
|
|
|
*dst++ = res[--l];
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2009-01-03 13:12:22 +08:00
|
|
|
int
|
2008-03-15 04:43:28 +08:00
|
|
|
__small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap)
|
|
|
|
{
|
2012-02-15 23:33:56 +08:00
|
|
|
tmpbuf tmp;
|
2008-03-15 04:43:28 +08:00
|
|
|
PWCHAR orig = dst;
|
|
|
|
const char *s;
|
|
|
|
PWCHAR w;
|
|
|
|
UNICODE_STRING uw, *us;
|
2013-04-23 17:44:36 +08:00
|
|
|
int base = 0;
|
2008-03-15 04:43:28 +08:00
|
|
|
|
|
|
|
DWORD err = GetLastError ();
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
intptr_t Rval = 0;
|
2008-03-15 04:43:28 +08:00
|
|
|
while (*fmt)
|
|
|
|
{
|
|
|
|
unsigned int n = 0x7fff;
|
2013-04-23 17:44:36 +08:00
|
|
|
bool l_opt = false;
|
2018-03-03 01:09:35 +08:00
|
|
|
/* set to -1 on '_', indicates upper (1)/lower(-1) case */
|
|
|
|
int h_opt = 1;
|
2008-03-15 04:43:28 +08:00
|
|
|
if (*fmt != L'%')
|
|
|
|
*dst++ = *fmt++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
WCHAR pad = L' ';
|
|
|
|
int addsign = -1;
|
|
|
|
|
|
|
|
switch (*++fmt)
|
|
|
|
{
|
|
|
|
case L'+':
|
|
|
|
addsign = 1;
|
|
|
|
fmt++;
|
|
|
|
break;
|
|
|
|
case L'%':
|
|
|
|
*dst++ = *fmt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char c = *fmt++;
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case L'0':
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
pad = L'0';
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2008-03-15 04:43:28 +08:00
|
|
|
case L'1' ... L'9':
|
|
|
|
len = len * 10 + (c - L'0');
|
|
|
|
continue;
|
|
|
|
case L'l':
|
2013-04-23 17:44:36 +08:00
|
|
|
l_opt = true;
|
2008-03-15 04:43:28 +08:00
|
|
|
continue;
|
2018-03-03 01:09:35 +08:00
|
|
|
case '_':
|
|
|
|
h_opt = -1;
|
|
|
|
continue;
|
2008-03-15 04:43:28 +08:00
|
|
|
case L'c':
|
|
|
|
case L'C':
|
2012-05-17 10:18:41 +08:00
|
|
|
*dst++ = va_arg (ap, unsigned);
|
2008-03-15 04:43:28 +08:00
|
|
|
break;
|
|
|
|
case L'E':
|
|
|
|
wcscpy (dst, L"Win32 error ");
|
|
|
|
dst = __wrn (dst + sizeof ("Win32 error"), 10, 0, err, len, pad, LMASK);
|
|
|
|
break;
|
2013-04-23 17:44:36 +08:00
|
|
|
case 'R':
|
|
|
|
{
|
|
|
|
if (l_opt)
|
|
|
|
Rval = va_arg (ap, int64_t);
|
|
|
|
else
|
|
|
|
Rval = va_arg (ap, int32_t);
|
|
|
|
dst = __wrn (dst, 10, addsign, Rval, len, pad, LMASK);
|
|
|
|
}
|
2008-03-15 04:43:28 +08:00
|
|
|
break;
|
2013-04-23 17:44:36 +08:00
|
|
|
case L'd':
|
|
|
|
base = 10;
|
|
|
|
if (l_opt)
|
|
|
|
goto gen_decimalLL;
|
|
|
|
goto gen_decimal;
|
|
|
|
case 'u':
|
|
|
|
base = 10;
|
|
|
|
addsign = 0;
|
|
|
|
if (l_opt)
|
|
|
|
goto gen_decimalLL;
|
|
|
|
goto gen_decimal;
|
|
|
|
case 'o':
|
|
|
|
base = 8;
|
|
|
|
addsign = 0;
|
|
|
|
if (l_opt)
|
|
|
|
goto gen_decimalLL;
|
|
|
|
goto gen_decimal;
|
|
|
|
case 'y':
|
|
|
|
*dst++ = '0';
|
|
|
|
*dst++ = 'x';
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2013-04-23 17:44:36 +08:00
|
|
|
case 'x':
|
|
|
|
base = 16;
|
|
|
|
addsign = 0;
|
|
|
|
if (l_opt)
|
|
|
|
goto gen_decimalLL;
|
|
|
|
gen_decimal:
|
2018-03-03 01:09:35 +08:00
|
|
|
dst = wrnarg (dst, h_opt * base, addsign, len, pad);
|
2008-03-15 04:43:28 +08:00
|
|
|
break;
|
2013-04-23 17:44:36 +08:00
|
|
|
case 'D':
|
|
|
|
base = 10;
|
|
|
|
goto gen_decimalLL;
|
|
|
|
case 'U':
|
|
|
|
base = 10;
|
|
|
|
addsign = 0;
|
|
|
|
goto gen_decimalLL;
|
|
|
|
case 'O':
|
|
|
|
base = 8;
|
|
|
|
addsign = 0;
|
|
|
|
goto gen_decimalLL;
|
|
|
|
case 'Y':
|
|
|
|
*dst++ = '0';
|
|
|
|
*dst++ = 'x';
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2013-04-23 17:44:36 +08:00
|
|
|
case 'X':
|
|
|
|
base = 16;
|
|
|
|
addsign = 0;
|
|
|
|
gen_decimalLL:
|
2018-03-03 01:09:35 +08:00
|
|
|
dst = wrnargLL (dst, h_opt * base, addsign, len, pad);
|
2008-03-15 04:43:28 +08:00
|
|
|
break;
|
|
|
|
case L'p':
|
|
|
|
*dst++ = L'0';
|
|
|
|
*dst++ = L'x';
|
2018-03-03 01:09:35 +08:00
|
|
|
dst = wrnargLL (dst, h_opt * 16, 0, len, pad);
|
2008-03-15 04:43:28 +08:00
|
|
|
break;
|
|
|
|
case L'P':
|
2015-07-20 04:38:30 +08:00
|
|
|
RtlInitUnicodeString (us = &uw, global_progname);
|
2008-03-15 04:43:28 +08:00
|
|
|
goto fillin;
|
|
|
|
case L'.':
|
|
|
|
n = wcstoul (fmt, (wchar_t **) &fmt, 10);
|
|
|
|
if (*fmt++ != L's')
|
|
|
|
goto endfor;
|
2020-08-06 03:58:22 +08:00
|
|
|
fallthrough;
|
2008-03-15 04:43:28 +08:00
|
|
|
case L's':
|
|
|
|
s = va_arg (ap, char *);
|
|
|
|
if (s == NULL)
|
|
|
|
s = "(null)";
|
2008-04-21 20:46:58 +08:00
|
|
|
sys_mbstowcs (tmp, NT_MAX_PATH, s, n < 0x7fff ? (int) n : -1);
|
2008-03-15 04:43:28 +08:00
|
|
|
RtlInitUnicodeString (us = &uw, tmp);
|
|
|
|
goto fillin;
|
|
|
|
break;
|
|
|
|
case L'W':
|
|
|
|
w = va_arg (ap, PWCHAR);
|
2009-03-23 23:48:16 +08:00
|
|
|
RtlInitUnicodeString (us = &uw, w ?: L"(null)");
|
2008-03-15 04:43:28 +08:00
|
|
|
goto fillin;
|
|
|
|
case L'S':
|
|
|
|
us = va_arg (ap, PUNICODE_STRING);
|
2009-03-23 23:48:16 +08:00
|
|
|
if (!us)
|
|
|
|
RtlInitUnicodeString (us = &uw, L"(null)");
|
2008-03-15 04:43:28 +08:00
|
|
|
fillin:
|
|
|
|
if (us->Length / sizeof (WCHAR) < n)
|
|
|
|
n = us->Length / sizeof (WCHAR);
|
2008-04-01 02:03:25 +08:00
|
|
|
w = us->Buffer;
|
2008-03-15 04:43:28 +08:00
|
|
|
for (unsigned int i = 0; i < n; i++)
|
|
|
|
*dst++ = *w++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*dst++ = L'?';
|
|
|
|
*dst++ = fmt[-1];
|
|
|
|
}
|
|
|
|
endfor:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-11 20:36:41 +08:00
|
|
|
if (Rval < 0)
|
2013-04-23 17:44:36 +08:00
|
|
|
{
|
|
|
|
dst = wcpcpy (dst, L", errno ");
|
|
|
|
dst = __wrn (dst, 10, false, get_errno (), 0, 0, LMASK);
|
|
|
|
}
|
2008-03-15 04:43:28 +08:00
|
|
|
*dst = L'\0';
|
|
|
|
SetLastError (err);
|
|
|
|
return dst - orig;
|
|
|
|
}
|
|
|
|
|
2009-01-03 13:12:22 +08:00
|
|
|
int
|
2008-03-15 04:43:28 +08:00
|
|
|
__small_swprintf (PWCHAR dst, const WCHAR *fmt, ...)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
r = __small_vswprintf (dst, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
return r;
|
|
|
|
}
|