Skip to content

Commit

Permalink
Mark and reindent util, with some exceptions.
Browse files Browse the repository at this point in the history
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23455 dc483132-0cff-0310-8789-dd5450dbe970
  • Loading branch information
tlyu committed Dec 7, 2009
1 parent 959e235 commit cdc8105
Show file tree
Hide file tree
Showing 53 changed files with 3,472 additions and 3,413 deletions.
13 changes: 10 additions & 3 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ INDENTDIRS = \
prototype \
slave \
tests \
util/support
util

BSDFILES = \
kadmin/cli/strftime.c \
Expand All @@ -687,7 +687,10 @@ BSDFILES = \
lib/krb5/krb/strptime.c \
slave/kpropd_rpc.c \
util/support/mkstemp.c \
util/support/strlcpy.c
util/support/strlcpy.c \
util/windows/getopt.c \
util/windows/getopt.h \
util/windows/getopt_long.c

OTHEREXCLUDES = \
include/iprop.h \
Expand All @@ -714,7 +717,11 @@ OTHEREXCLUDES = \
tests/asn.1/utility.h \
tests/gss-threads/gss-misc.c \
tests/gss-threads/gss-misc.h \
tests/hammer/kdc5_hammer.c
tests/hammer/kdc5_hammer.c \
util/et/com_err.h \
util/profile/prof_int.h \
util/profile/profile.hin \
util/profile/profile_tcl.c

EXCLUDES = `for i in $(BSDFILES) $(OTHEREXCLUDES); do echo $$i; done | $(AWK) '{ print "-path", $$1, "-o" }'` -path /dev/null

Expand Down
155 changes: 78 additions & 77 deletions src/util/et/com_err.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 1997 by Massachusetts Institute of Technology
*
Expand Down Expand Up @@ -35,79 +36,79 @@ k5_mutex_t com_err_hook_lock = K5_MUTEX_PARTIAL_INITIALIZER;

#if defined(_WIN32)
BOOL isGuiApp() {
DWORD mypid;
HANDLE myprocess;
mypid = GetCurrentProcessId();
myprocess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, mypid);
return GetGuiResources(myprocess, 1) > 0;
}
DWORD mypid;
HANDLE myprocess;
mypid = GetCurrentProcessId();
myprocess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, mypid);
return GetGuiResources(myprocess, 1) > 0;
}
#endif

static void default_com_err_proc (const char *whoami, errcode_t code,
const char *fmt, va_list ap)
const char *fmt, va_list ap)
{
#if defined(_WIN32)

char errbuf[1024] = "";

if (whoami) {
errbuf[sizeof(errbuf) - 1] = '\0';
strncat (errbuf, whoami, sizeof(errbuf) - 1 - strlen(errbuf));
strncat (errbuf, ": ", sizeof(errbuf) - 1 - strlen(errbuf));
}
if (code) {
errbuf[sizeof(errbuf) - 1] = '\0';
strncat (errbuf, error_message(code), sizeof(errbuf) - 1 - strlen(errbuf));
strncat (errbuf, " ", sizeof(errbuf) - 1 - strlen(errbuf));
}
if (fmt)
/* ITS4: ignore vsprintf */
vsprintf (errbuf + strlen (errbuf), fmt, ap);
errbuf[sizeof(errbuf) - 1] = '\0';

if (_isatty(_fileno(stderr)) || !isGuiApp()) {
fputs(errbuf, stderr);
fputc('\r', stderr);
fputc('\n', stderr);
fflush(stderr);
} else
MessageBox ((HWND)NULL, errbuf, "Kerberos", MB_ICONEXCLAMATION);
char errbuf[1024] = "";

if (whoami) {
errbuf[sizeof(errbuf) - 1] = '\0';
strncat (errbuf, whoami, sizeof(errbuf) - 1 - strlen(errbuf));
strncat (errbuf, ": ", sizeof(errbuf) - 1 - strlen(errbuf));
}
if (code) {
errbuf[sizeof(errbuf) - 1] = '\0';
strncat (errbuf, error_message(code), sizeof(errbuf) - 1 - strlen(errbuf));
strncat (errbuf, " ", sizeof(errbuf) - 1 - strlen(errbuf));
}
if (fmt)
/* ITS4: ignore vsprintf */
vsprintf (errbuf + strlen (errbuf), fmt, ap);
errbuf[sizeof(errbuf) - 1] = '\0';

if (_isatty(_fileno(stderr)) || !isGuiApp()) {
fputs(errbuf, stderr);
fputc('\r', stderr);
fputc('\n', stderr);
fflush(stderr);
} else
MessageBox ((HWND)NULL, errbuf, "Kerberos", MB_ICONEXCLAMATION);

#else /* !_WIN32 */

if (whoami) {
fputs(whoami, stderr);
fputs(": ", stderr);
}
if (code) {
fputs(error_message(code), stderr);
fputs(" ", stderr);
}
if (fmt) {
vfprintf(stderr, fmt, ap);
}
/* should do this only on a tty in raw mode */
putc('\r', stderr);
putc('\n', stderr);
fflush(stderr);
if (whoami) {
fputs(whoami, stderr);
fputs(": ", stderr);
}
if (code) {
fputs(error_message(code), stderr);
fputs(" ", stderr);
}
if (fmt) {
vfprintf(stderr, fmt, ap);
}
/* should do this only on a tty in raw mode */
putc('\r', stderr);
putc('\n', stderr);
fflush(stderr);

#endif
}

void KRB5_CALLCONV com_err_va(const char *whoami,
errcode_t code,
const char *fmt,
va_list ap)
errcode_t code,
const char *fmt,
va_list ap)
{
int err;
et_old_error_hook_func p;

err = com_err_finish_init();
if (err)
goto best_try;
goto best_try;
err = k5_mutex_lock(&com_err_hook_lock);
if (err)
goto best_try;
goto best_try;
p = com_err_hook ? com_err_hook : default_com_err_proc;
(*p)(whoami, code, fmt, ap);
k5_mutex_unlock(&com_err_hook_lock);
Expand All @@ -121,23 +122,23 @@ void KRB5_CALLCONV com_err_va(const char *whoami,
there's a good chance it has to do with failed initialization
of the caller. */
if (!com_err_hook)
default_com_err_proc(whoami, code, fmt, ap);
default_com_err_proc(whoami, code, fmt, ap);
else
(com_err_hook)(whoami, code, fmt, ap);
(com_err_hook)(whoami, code, fmt, ap);
assert(err == 0);
abort();
}


void KRB5_CALLCONV_C com_err(const char *whoami,
errcode_t code,
const char *fmt, ...)
errcode_t code,
const char *fmt, ...)
{
va_list ap;
va_list ap;

va_start(ap, fmt);
com_err_va(whoami, code, fmt, ap);
va_end(ap);
va_start(ap, fmt);
com_err_va(whoami, code, fmt, ap);
va_end(ap);
}

/* Make a separate function because the assert invocations below
Expand All @@ -150,26 +151,26 @@ static int com_err_lock_hook_handle(void)

et_old_error_hook_func set_com_err_hook (et_old_error_hook_func new_proc)
{
et_old_error_hook_func x;

/* Broken initialization? What can we do? */
assert(com_err_finish_init() == 0);
assert(com_err_lock_hook_handle() == 0);
x = com_err_hook;
com_err_hook = new_proc;
k5_mutex_unlock(&com_err_hook_lock);
return x;
et_old_error_hook_func x;

/* Broken initialization? What can we do? */
assert(com_err_finish_init() == 0);
assert(com_err_lock_hook_handle() == 0);
x = com_err_hook;
com_err_hook = new_proc;
k5_mutex_unlock(&com_err_hook_lock);
return x;
}

et_old_error_hook_func reset_com_err_hook ()
{
et_old_error_hook_func x;

/* Broken initialization? What can we do? */
assert(com_err_finish_init() == 0);
assert(com_err_lock_hook_handle() == 0);
x = com_err_hook;
com_err_hook = NULL;
k5_mutex_unlock(&com_err_hook_lock);
return x;
et_old_error_hook_func x;

/* Broken initialization? What can we do? */
assert(com_err_finish_init() == 0);
assert(com_err_lock_hook_handle() == 0);
x = com_err_hook;
com_err_hook = NULL;
k5_mutex_unlock(&com_err_hook_lock);
return x;
}
Loading

0 comments on commit cdc8105

Please sign in to comment.