summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/keytab/t_keytab.c
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2007-06-20 01:09:10 +0000
committerKen Raeburn <raeburn@mit.edu>2007-06-20 01:09:10 +0000
commitd275e06d0cb0f248aa54a6f134a59f84aa563e14 (patch)
tree908926aa3d5f3be981ceb9b6d6081d07d9f65cef /src/lib/krb5/keytab/t_keytab.c
parent4711fe7c1cd4761c893c371b84757d6bfcda82e8 (diff)
downloadkrb5-d275e06d0cb0f248aa54a6f134a59f84aa563e14.tar.gz
krb5-d275e06d0cb0f248aa54a6f134a59f84aa563e14.tar.xz
krb5-d275e06d0cb0f248aa54a6f134a59f84aa563e14.zip
provide asprintf functionality for internal use
I plan to use asprintf in some gssapi error-message management routines, so let's make sure we have the functionality available, implementing it locally if necessary. This implementation assumes vsnprintf is available, an assumption that the support library is already making at the moment. Since this implementation requires calling vsnprintf potentially multiple times with the same va_list, use va_copy if it's available, or provide a hack version (which should work okay if va_list is a scalar or array type that requires no other special handling, and if va_end does nothing interesting, which is usually the case) if the compiler doesn't provide it. I also changed a couple bits of code to use asprintf, to make sure we exercise our implementation in testing. (C99 requires vsnprintf and va_copy; vasprintf is a GNU/BSD extension, but an oh so useful one....) * configure.in: Check for va_copy, or if va_list objects can be simply assigned. Define HAS_VA_COPY and CAN_COPY_VA_LIST as appropriate. * include/k5-platform.h: Define a va_copy macro if the compiler doesn't provide it. * include/k5-platform.h: If vsnprintf isn't available from the OS, abort compilation. If vasprintf isn't available from the OS, provide k5_{v,}asprintf based on vsnprintf and define {v,}asprintf macros. * lib/krb5/keytab/t_keytab.c (do_test): Use asprintf. * util/support/errors.c (krb5int_vset_error): Use asprintf unconditionally. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19595 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/keytab/t_keytab.c')
-rw-r--r--src/lib/krb5/keytab/t_keytab.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lib/krb5/keytab/t_keytab.c b/src/lib/krb5/keytab/t_keytab.c
index d16184e25d..08610abac5 100644
--- a/src/lib/krb5/keytab/t_keytab.c
+++ b/src/lib/krb5/keytab/t_keytab.c
@@ -370,10 +370,16 @@ static void kt_test(krb5_context context, const char *name)
static void do_test(krb5_context context, const char *prefix,
krb5_boolean delete)
{
- char name[300], filename[300];
+ char *name, *filename;
- sprintf(filename, "/tmp/kttest.%ld", (long) getpid());
- sprintf(name, "%s%s", prefix, filename);
+ if (asprintf(&filename, "/tmp/kttest.%ld", (long) getpid()) < 0) {
+ perror("asprintf");
+ exit(1);
+ }
+ if (asprintf(&name, "%s%s", prefix, filename) < 0) {
+ perror("asprintf");
+ exit(1);
+ }
printf("Starting test on %s\n", name);
kt_test(context, name);
printf("Test on %s passed\n", name);