From 8c1f7259314b1d81ce7be2fe7abe3f28672b2ce0 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Thu, 24 Mar 2011 15:36:49 +0000 Subject: [PATCH] afs_snprintf is dead, long live rk_snprintf We were shipping our own implementation of snprintf and friends, as afs_snprintf. Now that we're using roken everywhere, we can make use of roken's rk_snprintf, and no longer need to ship our own. As Window's snprintf isn't C99 compliant, roken always uses its own on this platform. The effect of this is that we can no longer use AFS_UINT64_FMT and AFS_INT64_FMT for snprintf calls (and the Log functions that call them). Instead, we need to always use the Unix format specifiers when calling these functions. Make thse changes across the whole tree. Change-Id: I3fffef97566f239ad639f15c4decd136d5bbd765 Reviewed-on: http://gerrit.openafs.org/4316 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/WINNT/afsd/cm_scache.c | 4 +- src/WINNT/afsd/cm_volume.c | 4 +- src/WINNT/afsreg/afssw.c | 3 + src/WINNT/netidmgr_plugin/krb5common.c | 2 + src/aklog/aklog.c | 3 +- src/audit/audit-sysvmq.c | 4 +- src/butc/lwps.c | 9 +- src/libafsauthent/Makefile.in | 4 - src/ptserver/pt_util.c | 2 +- src/shlibafsauthent/Makefile.in | 4 - src/shlibafsauthent/libafsauthent.map | 1 - src/tbudb/Makefile.in | 5 +- src/tptserver/Makefile.in | 5 +- src/tubik/Makefile.in | 6 +- src/tviced/serialize_state.c | 2 +- src/tvlserver/Makefile.in | 7 +- src/ubik/phys.c | 4 +- src/ubik/recovery.c | 20 +- src/ubik/remote.c | 16 +- src/util/Makefile.in | 10 +- src/util/NTMakefile | 2 - src/util/afsutil.h | 29 -- src/util/serverLog.c | 21 +- src/util/snprintf.c | 906 --------------------------------- src/util/test/snprintf_test.c | 407 --------------- src/venus/fstrace.c | 5 +- src/viced/afsfileprocs.c | 5 +- src/viced/host.c | 69 ++- src/vol/namei_ops.c | 54 +- src/vol/partition.c | 16 +- src/vol/salvaged.c | 10 +- src/vol/vol-info.c | 16 +- src/vol/vol-salvage.c | 53 +- src/vol/volume.c | 7 +- src/vol/vutil.c | 22 +- src/volser/restorevol.c | 91 ++-- src/volser/vol-dump.c | 8 +- src/volser/vol_split.c | 29 +- src/volser/volprocs.c | 2 +- 39 files changed, 258 insertions(+), 1609 deletions(-) delete mode 100644 src/util/snprintf.c delete mode 100644 src/util/test/snprintf_test.c diff --git a/src/WINNT/afsd/cm_scache.c b/src/WINNT/afsd/cm_scache.c index 530ad89..3ab5ef8 100644 --- a/src/WINNT/afsd/cm_scache.c +++ b/src/WINNT/afsd/cm_scache.c @@ -9,10 +9,10 @@ #include #include -#include - #include +#include + #include #include #include diff --git a/src/WINNT/afsd/cm_volume.c b/src/WINNT/afsd/cm_volume.c index 3357650..0f2c855 100644 --- a/src/WINNT/afsd/cm_volume.c +++ b/src/WINNT/afsd/cm_volume.c @@ -9,10 +9,10 @@ #include #include -#include - #include +#include + #include #include #include diff --git a/src/WINNT/afsreg/afssw.c b/src/WINNT/afsreg/afssw.c index c00ef96..b433253 100644 --- a/src/WINNT/afsreg/afssw.c +++ b/src/WINNT/afsreg/afssw.c @@ -7,9 +7,12 @@ * directory or online at http://www.openafs.org/dl/license10.html */ +#include #include #include +#include + #include #include #include diff --git a/src/WINNT/netidmgr_plugin/krb5common.c b/src/WINNT/netidmgr_plugin/krb5common.c index 7fbaa9e..ba12a16 100644 --- a/src/WINNT/netidmgr_plugin/krb5common.c +++ b/src/WINNT/netidmgr_plugin/krb5common.c @@ -27,6 +27,8 @@ #include #include +#include + #include #include #include diff --git a/src/aklog/aklog.c b/src/aklog/aklog.c index b724447..10184b6 100644 --- a/src/aklog/aklog.c +++ b/src/aklog/aklog.c @@ -42,7 +42,6 @@ #include -#include #include #include @@ -885,7 +884,7 @@ rxkad_get_token(krb5_context context, struct afsconf_cell *cell, char *realm, } else { len = strlen(username)+strlen(realmUsed)+2; *authuser = malloc(len); - afs_snprintf(*authuser, len, "%s@%s", username, realmUsed); + snprintf(*authuser, len, "%s@%s", username, realmUsed); *foreign = 1; } diff --git a/src/audit/audit-sysvmq.c b/src/audit/audit-sysvmq.c index 327bdda..01e942c 100644 --- a/src/audit/audit-sysvmq.c +++ b/src/audit/audit-sysvmq.c @@ -8,12 +8,14 @@ */ #include +#include + +#include /* only build on platforms that have SysV IPC support; i.e., when we * have sys/ipc.h */ #ifdef HAVE_SYS_IPC_H -#include #include #include diff --git a/src/butc/lwps.c b/src/butc/lwps.c index d05c922..31c8ad0 100644 --- a/src/butc/lwps.c +++ b/src/butc/lwps.c @@ -10,7 +10,6 @@ #include #include - #include #include @@ -239,7 +238,7 @@ TapeLog(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2, va_list ap; va_start(ap, fmt); - afs_vsnprintf(tmp, sizeof(tmp), fmt, ap); + vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); TapeLogStr(debug, task, error1, error2, tmp); @@ -252,7 +251,7 @@ TLog(afs_int32 task, char *fmt, ...) va_list ap; va_start(ap, fmt); - afs_vsnprintf(tmp, sizeof(tmp), fmt, ap); + vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); /* Sends message to TapeLog and stdout */ @@ -287,7 +286,7 @@ ErrorLog(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2, va_list ap; va_start(ap, fmt); - afs_vsnprintf(tmp, sizeof(tmp), fmt, ap); + vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); ErrorLogStr(debug, task, error1, error2, tmp); @@ -301,7 +300,7 @@ ELog(afs_int32 task, char *fmt, ...) va_list ap; va_start(ap, fmt); - afs_vsnprintf(tmp, sizeof(tmp), fmt, ap); + vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); /* Sends message to ErrorLog, TapeLog and stdout */ diff --git a/src/libafsauthent/Makefile.in b/src/libafsauthent/Makefile.in index 82250f2..83d971e 100644 --- a/src/libafsauthent/Makefile.in +++ b/src/libafsauthent/Makefile.in @@ -63,7 +63,6 @@ UTILOBJS = \ get_krbrlm.o \ dirpath.o \ serverLog.o \ - snprintf.o \ fileutil.o RXKADOBJS = \ @@ -204,9 +203,6 @@ dirpath.o: ${UTIL}/dirpath.c serverLog.o: ${UTIL}/serverLog.c ${AFS_CCRULE} ${UTIL}/serverLog.c -snprintf.o: ${UTIL}/snprintf.c - ${AFS_CCRULE} ${UTIL}/snprintf.c - fileutil.o: ${UTIL}/fileutil.c ${AFS_CCRULE} ${UTIL}/fileutil.c diff --git a/src/ptserver/pt_util.c b/src/ptserver/pt_util.c index 9c0e0a4..2c52e42 100644 --- a/src/ptserver/pt_util.c +++ b/src/ptserver/pt_util.c @@ -174,7 +174,7 @@ CommandProc(struct cmd_syndesc *a_as, void *arock) } if (pfile == NULL) { - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB0", pbase); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB0", pbase); pfile = pbuffer; } if ((dbase_fd = open(pfile, (wflag ? O_RDWR : O_RDONLY) | O_CREAT, 0600)) diff --git a/src/shlibafsauthent/Makefile.in b/src/shlibafsauthent/Makefile.in index 521bfa2..480b2d1 100644 --- a/src/shlibafsauthent/Makefile.in +++ b/src/shlibafsauthent/Makefile.in @@ -70,7 +70,6 @@ UTILOBJS = \ get_krbrlm.o \ dirpath.o \ serverLog.o \ - snprintf.o \ fileutil.o RXKADOBJS = \ @@ -239,9 +238,6 @@ dirpath.o: ${UTIL}/dirpath.c serverLog.o: ${UTIL}/serverLog.c ${AFS_CCRULE} ${UTIL}/serverLog.c -snprintf.o: ${UTIL}/snprintf.c - ${AFS_CCRULE} ${UTIL}/snprintf.c - fileutil.o: ${UTIL}/fileutil.c ${AFS_CCRULE} ${UTIL}/fileutil.c diff --git a/src/shlibafsauthent/libafsauthent.map b/src/shlibafsauthent/libafsauthent.map index 76f5dfc..346eac8 100644 --- a/src/shlibafsauthent/libafsauthent.map +++ b/src/shlibafsauthent/libafsauthent.map @@ -83,7 +83,6 @@ pr_SNameToId; afs_get_pag_from_groups; setpag; - afs_snprintf; LogThreadNum; local: diff --git a/src/tbudb/Makefile.in b/src/tbudb/Makefile.in index 191c2b8..0a9d3fc 100644 --- a/src/tbudb/Makefile.in +++ b/src/tbudb/Makefile.in @@ -23,7 +23,7 @@ BUDB=$(srcdir)/../budb RXOBJS= rx_pthread.o rxkad_errs.o UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o \ - volparse.o flipbase64.o softsig.o hostparse.o snprintf.o pthread_glock.o + volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o INCLS=\ @@ -108,9 +108,6 @@ softsig.o: ${UTIL}/softsig.c hostparse.o: ${UTIL}/hostparse.c $(AFS_CCRULE) $(UTIL)/hostparse.c -snprintf.o: ${UTIL}/snprintf.c - $(AFS_CCRULE) $(UTIL)/snprintf.c - pthread_glock.o: ${UTIL}/pthread_glock.c $(AFS_CCRULE) $(UTIL)/pthread_glock.c diff --git a/src/tptserver/Makefile.in b/src/tptserver/Makefile.in index 0871a65..8ea190a 100644 --- a/src/tptserver/Makefile.in +++ b/src/tptserver/Makefile.in @@ -23,7 +23,7 @@ PTSERVER=$(srcdir)/../ptserver RXOBJS= rx_pthread.o rxkad_errs.o UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o \ - volparse.o flipbase64.o softsig.o hostparse.o snprintf.o pthread_glock.o + volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o INCLS=${TOP_INCDIR}/ubik.h \ ${TOP_INCDIR}/lock.h \ @@ -95,9 +95,6 @@ softsig.o: ${UTIL}/softsig.c hostparse.o: ${UTIL}/hostparse.c $(AFS_CCRULE) $(UTIL)/hostparse.c -snprintf.o: ${UTIL}/snprintf.c - $(AFS_CCRULE) $(UTIL)/snprintf.c - pthread_glock.o: ${UTIL}/pthread_glock.c $(AFS_CCRULE) $(UTIL)/pthread_glock.c diff --git a/src/tubik/Makefile.in b/src/tubik/Makefile.in index 7ba412f..462a4e5 100644 --- a/src/tubik/Makefile.in +++ b/src/tubik/Makefile.in @@ -30,8 +30,7 @@ INCLS=${TOP_INCDIR}/lwp.h ${TOP_INCDIR}/lock.h \ RXOBJS = rx_pthread.o UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o \ - volparse.o flipbase64.o softsig.o hostparse.o snprintf.o \ - pthread_glock.o + volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o LIBS=${RXOBJS} ${UTILOBJS} ${TOP_LIBDIR}/libafsauthent.a ${TOP_LIBDIR}/libafsrpc.a \ ${TOP_LIBDIR}/libcom_err.a ${TOP_LIBDIR}/libcmd.a \ @@ -88,9 +87,6 @@ softsig.o: ${UTIL}/softsig.c hostparse.o: ${UTIL}/hostparse.c $(AFS_CCRULE) $(UTIL)/hostparse.c -snprintf.o: ${UTIL}/snprintf.c - $(AFS_CCRULE) $(UTIL)/snprintf.c - pthread_glock.o: ${UTIL}/pthread_glock.c $(AFS_CCRULE) $(UTIL)/pthread_glock.c diff --git a/src/tviced/serialize_state.c b/src/tviced/serialize_state.c index b2b3011..8c104a5 100644 --- a/src/tviced/serialize_state.c +++ b/src/tviced/serialize_state.c @@ -329,7 +329,7 @@ fs_stateCreateDump(struct fs_dump_state * state) char savedump[MAXPATHLEN]; struct afs_stat status; - afs_snprintf(savedump, sizeof(savedump), "%s.old", state->fn); + snprintf(savedump, sizeof(savedump), "%s.old", state->fn); if (afs_stat(state->fn, &status) == 0) { renamefile(state->fn, savedump); diff --git a/src/tvlserver/Makefile.in b/src/tvlserver/Makefile.in index 362cd38..91a95ae 100644 --- a/src/tvlserver/Makefile.in +++ b/src/tvlserver/Makefile.in @@ -23,8 +23,8 @@ VLSERVER=$(srcdir)/../vlserver RXOBJS= rx_pthread.o rxkad_errs.o UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o \ - volparse.o flipbase64.o softsig.o hostparse.o snprintf.o \ - pthread_glock.o get_krbrlm.o + volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o \ + get_krbrlm.o INCLS=${TOP_INCDIR}/ubik.h \ ${TOP_INCDIR}/lwp.h \ @@ -92,9 +92,6 @@ softsig.o: ${UTIL}/softsig.c hostparse.o: ${UTIL}/hostparse.c $(AFS_CCRULE) $(UTIL)/hostparse.c -snprintf.o: ${UTIL}/snprintf.c - $(AFS_CCRULE) $(UTIL)/snprintf.c - pthread_glock.o: ${UTIL}/pthread_glock.c $(AFS_CCRULE) $(UTIL)/pthread_glock.c diff --git a/src/ubik/phys.c b/src/ubik/phys.c index 5ef33be..d763632 100644 --- a/src/ubik/phys.c +++ b/src/ubik/phys.c @@ -89,8 +89,8 @@ uphys_open(struct ubik_dbase *adbase, afs_int32 afid) } /* not found, open it and try to enter in cache */ - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d", adbase->pathName, - (afid<0)?"SYS":"", (afid<0)?-afid:afid); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d", adbase->pathName, + (afid<0)?"SYS":"", (afid<0)?-afid:afid); fd = open(pbuffer, O_CREAT | O_RDWR, 0600); if (fd < 0) { /* try opening read-only */ diff --git a/src/ubik/recovery.c b/src/ubik/recovery.c index 2b3cc76..aa221b0 100644 --- a/src/ubik/recovery.c +++ b/src/ubik/recovery.c @@ -603,7 +603,9 @@ urecovery_Interact(void *dummy) ubik_dprint("setlabel io error=%d\n", code); goto FetchEndCall; } - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", + ubik_dbase->pathName, (file<0)?"SYS":"", + (file<0)?-file:file); fd = open(pbuffer, O_CREAT | O_RDWR | O_TRUNC, 0600); if (fd < 0) { code = errno; @@ -652,13 +654,19 @@ urecovery_Interact(void *dummy) urecovery_state |= UBIK_RECHAVEDB; memcpy(&ubik_dbase->version, &tversion, sizeof(struct ubik_version)); - afs_snprintf(tbuffer, sizeof(tbuffer), "%s.DB%s%d", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(tbuffer, sizeof(tbuffer), "%s.DB%s%d", + ubik_dbase->pathName, (file<0)?"SYS":"", + (file<0)?-file:file); #ifdef AFS_NT40_ENV - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", + ubik_dbase->pathName, (file<0)?"SYS":"", + (file<0)?-file:file); code = unlink(pbuffer); if (!code) code = rename(tbuffer, pbuffer); - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", + ubik_dbase->pathName, (file<0)?"SYS":"", + (file<0)?-file:file); #endif if (!code) code = rename(pbuffer, tbuffer); @@ -670,7 +678,9 @@ urecovery_Interact(void *dummy) &ubik_dbase->version); } #ifdef AFS_NT40_ENV - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", + ubik_dbase->pathName, (file<0)?"SYS":"", + (file<0)?-file:file); unlink(pbuffer); #endif } diff --git a/src/ubik/remote.c b/src/ubik/remote.c index 4a0d706..1bde036 100644 --- a/src/ubik/remote.c +++ b/src/ubik/remote.c @@ -501,7 +501,9 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file, offset = 0; epoch = tversion.epoch = 0; /* start off by labelling in-transit db as invalid */ (*dbase->setlabel) (dbase, file, &tversion); /* setlabel does sync */ - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", + ubik_dbase->pathName, (file<0)?"SYS":"", + (file<0)?-file:file); fd = open(pbuffer, O_CREAT | O_RDWR | O_TRUNC, 0600); if (fd < 0) { code = errno; @@ -544,13 +546,16 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file, /* sync data first, then write label and resync (resync done by setlabel call). * This way, good label is only on good database. */ - afs_snprintf(tbuffer, sizeof(tbuffer), "%s.DB%s%d", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(tbuffer, sizeof(tbuffer), "%s.DB%s%d", + ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); #ifdef AFS_NT40_ENV - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", + ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); code = unlink(pbuffer); if (!code) code = rename(tbuffer, pbuffer); - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", + ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); #endif if (!code) code = rename(pbuffer, tbuffer); @@ -559,7 +564,8 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file, code = (*ubik_dbase->setlabel) (dbase, file, avers); } #ifdef AFS_NT40_ENV - afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); + snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", + ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file); unlink(pbuffer); #endif memcpy(&ubik_dbase->version, avers, sizeof(struct ubik_version)); diff --git a/src/util/Makefile.in b/src/util/Makefile.in index 660f489..82a8d2d 100644 --- a/src/util/Makefile.in +++ b/src/util/Makefile.in @@ -20,8 +20,8 @@ objects = assert.o base64.o casestrcpy.o config_file.o ktime.o volparse.o \ hostparse.o exec.o \ hputil.o kreltime.o get_krbrlm.o uuid.o serverLog.o \ dirpath.o fileutil.o netutils.o flipbase64.o fstab.o \ - afs_atomlist.o afs_lhash.o snprintf.o pthread_glock.o \ - tabular_output.o ${REGEX_OBJ} + afs_atomlist.o afs_lhash.o pthread_glock.o tabular_output.o \ + ${REGEX_OBJ} objects_pic = \ assert_pic.o \ @@ -44,7 +44,6 @@ objects_pic = \ fstab_pic.o \ afs_atomlist_pic.o \ afs_lhash_pic.o \ - snprintf_pic.o \ pthread_glock_pic.o \ tabular_output_pic.o \ ${REGEX_OBJ_PIC} @@ -261,9 +260,6 @@ afs_atomlist_pic.o: ${srcdir}/afs_atomlist.c ${includes} afs_lhash_pic.o: ${srcdir}/afs_lhash.c ${includes} $(SHD_CCRULE) ${srcdir}/afs_lhash.c -snprintf_pic.o: ${srcdir}/snprintf.c ${includes} - $(SHD_CCRULE) ${srcdir}/snprintf.c - pthread_glock_pic.o: ${srcdir}/pthread_glock.c ${includes} $(SHD_CCRULE) ${srcdir}/pthread_glock.c @@ -353,4 +349,4 @@ check-splint: assert.c base64.c casestrcpy.c ktime.c volparse.c hostparse.c \ hputil.c kreltime.c get_krbrlm.c uuid.c serverLog.c \ dirpath.c fileutil.c netutils.c flipbase64.c \ - afs_atomlist.c afs_lhash.c snprintf.c fstab.c + afs_atomlist.c afs_lhash.c fstab.c diff --git a/src/util/NTMakefile b/src/util/NTMakefile index 9901442..514fb22 100644 --- a/src/util/NTMakefile +++ b/src/util/NTMakefile @@ -55,7 +55,6 @@ LIBOBJS = \ $(OUT)\regex.obj \ $(OUT)\readdir_nt.obj \ $(OUT)\serverLog.obj \ - $(OUT)\snprintf.obj \ $(OUT)\uuid.obj \ $(OUT)\volparse.obj \ $(OUT)\winsock_nt.obj \ @@ -77,7 +76,6 @@ MT_LIBOBJS = \ $(OUT)\regex.obj \ $(OUT)\readdir_nt.obj \ $(OUT)\serverLog_mt.obj \ - $(OUT)\snprintf.obj \ $(OUT)\uuid.obj \ $(OUT)\volparse.obj \ $(OUT)\winsock_nt.obj \ diff --git a/src/util/afsutil.h b/src/util/afsutil.h index b56015e..6a06510 100644 --- a/src/util/afsutil.h +++ b/src/util/afsutil.h @@ -55,35 +55,6 @@ extern int OpenLog(const char *filename); extern int ReOpenLog(const char *fileName); extern void SetupLogSignals(void); -extern int -afs_vsnprintf( /*@out@ */ char *p, size_t avail, const char *fmt, - va_list ap) - AFS_ATTRIBUTE_FORMAT(__printf__, 3, 0) - /*@requires maxSet(p) >= (avail-1)@ */ - /*@modifies p@ */ ; - -extern /*@printflike@ */ int -afs_snprintf( /*@out@ */ char *p, size_t avail, const char *fmt, ...) - AFS_ATTRIBUTE_FORMAT(__printf__, 3, 4) - /*@requires maxSet(p) >= (avail-1)@ */ - /*@modifies p@ */ ; - -extern int -afs_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) - AFS_ATTRIBUTE_FORMAT(__printf__, 3, 0); - -extern int -afs_vasprintf (char **ret, const char *format, va_list args) - AFS_ATTRIBUTE_FORMAT(__printf__, 2, 0); - -extern int -afs_asprintf (char **ret, const char *format, ...) - AFS_ATTRIBUTE_FORMAT(__printf__, 2, 3); - -extern int -afs_asnprintf (char **ret, size_t max_sz, const char *format, ...) - AFS_ATTRIBUTE_FORMAT(__printf__, 3, 4); - /* special version of ctime that clobbers a *different static variable, so * that ViceLog can call ctime and not cause buffer confusion. */ diff --git a/src/util/serverLog.c b/src/util/serverLog.c index 65a2456..06c8db2 100644 --- a/src/util/serverLog.c +++ b/src/util/serverLog.c @@ -114,14 +114,13 @@ vFSLog(const char *format, va_list args) if (mrafsStyleLogs || threadIdLogs) { num = (*threadNumProgram) (); if (num > -1) { - (void)afs_snprintf(info, (sizeof tbuffer) - strlen(tbuffer), "[%d] ", - num); - info += strlen(info); - } + snprintf(info, (sizeof tbuffer) - strlen(tbuffer), "[%d] ", + num); + info += strlen(info); + } } - (void)afs_vsnprintf(info, (sizeof tbuffer) - strlen(tbuffer), format, - args); + vsnprintf(info, (sizeof tbuffer) - strlen(tbuffer), format, args); len = strlen(tbuffer); LOCK_SERVERLOG(); @@ -302,11 +301,11 @@ OpenLog(const char *fileName) strcpy((char *)&ourName, (char *)fileName); } makefilename: - afs_snprintf(FileName, MAXPATHLEN, "%s.%d%02d%02d%02d%02d%02d", - ourName, TimeFields->tm_year + 1900, - TimeFields->tm_mon + 1, TimeFields->tm_mday, - TimeFields->tm_hour, TimeFields->tm_min, - TimeFields->tm_sec); + snprintf(FileName, MAXPATHLEN, "%s.%d%02d%02d%02d%02d%02d", + ourName, TimeFields->tm_year + 1900, + TimeFields->tm_mon + 1, TimeFields->tm_mday, + TimeFields->tm_hour, TimeFields->tm_min, + TimeFields->tm_sec); if(lstat(FileName, &buf) == 0) { /* avoid clobbering a log */ TimeFields->tm_sec++; diff --git a/src/util/snprintf.c b/src/util/snprintf.c deleted file mode 100644 index 1f79105..0000000 --- a/src/util/snprintf.c +++ /dev/null @@ -1,906 +0,0 @@ -/* - * Copyright (c) 1997 - 2004 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* snprintf.c - Formatted, length-limited print to a string */ - -#include -#include - -#include -#include - -/* This is an enhanced version of the *printf functionality shipped - * with Heimdal. In addition to the standard Unix formatting types - * this version also supports Microsoft's I32 and I64 type modifiers - * and the OpenAFS I type which is used to generate output from - * network byte order IPv4 addresses (either dotted notation or - * hostname lookups. Implementation details follow: - * - * - Actually obeys the length limit, which (unfortunately) many - * implementations of snprintf do not. - * - * - Supports all the standard format specifiers for integers - * (d, i, o, u, x, X), floating-point values (f, e, E, g, G), - * and strings and characters (c, s, %), plus a few unusual - * but useful ones described below. - * - * - The Microsoft integral size modifiers I32 and I64 are - * supported. I32 is equivalent to 'l'. - * I64 is equivalent to 'll'. - * - * - Supports all the standard flags (-, 0, +, space, #). These - * flags are ignored if used when they are not appropriate. - * - * - Supports the standard size modifiers for short (h), long (h), - * and double (L) arguments. These modifiers are ignored if used - * when they are not appropriate. - * - * - Supports minimum field width and precision, where appropriate, - * including the use of '*' to specify a value given as an argument - * instead of in the format string. There is a maximum precision - * of 100 digits. - * - * - The 'p' specifier for printing pointers is implemented using - * intptr_t (C99-standard). - * - * - Floating-point specifier (%e, %f, %g) are implemented by - * calling the standard sprintf, and thus may be unsafe. - * - * - The '%...$' notation is used primarily when the format string - * is specified by the user, who knows but cannot change the order - * of the arguments. Such usage is inherently dangerous and - * insecure; thus, it is not supported. - * - * - Passing in a format and an NULL buffer is supported. This - * will compute the size of the buffer required by the format - * and the provided input parameters. - * - * The custom format specifier '%I' is supported. This specifier - * takes as its argument an unsigned long integer containing an - * IPv4 address in network byte order. The address is rendered - * either as a hostname or as a dotted quad, as follows: - * - * - If precision is nonzero or unspecified, a hostname lookup - * is attempted; if it is successful, the hostname is printed. - * If the hostname lookup fails, the address is printed in - * dotted-quad notation. - * - * - If precision is explicitly specified as 0, then the hostname - * lookup is skipped, and dotted-quad notation is always used. - * - * - If a hostname is to be printed: - * + The precision controls the maximum number of characters - * printed, as with %s. - * + If the '#' flag is specified, any letters in the hostname - * will be forced to lower case before printing. - * + If the '+' flag is specified, any letters in the hostname - * will be forced to upper case before printing. If both - * '#' and '+' are given, the '+' flag will be ignored. - * + The '0' and ' ' flags have no effect. - * - * - If a dotted quad is to be printed: - * + The precision has no effect; dotted quads are always - * 7 to 12 characters in length, depending on the value - * to be printed and the format flags used. - * + If the '0' flag is given, each field (byte) of the address - * will be padded with '0' on the left to three digits. - * + If the ' ' flag is given, each field (byte) of the address - * will be padded with spaces on the left to three digits. If - * both '0' and ' ' are given, the ' ' flag will be ignored. - * + The '#' and '+' flags have no effect. - * - * A test program exists in src/util/tests/snprintf_tests.c. - */ - -#define MAXPREC 100 - -enum format_flags { - minus_flag = 1, - plus_flag = 2, - space_flag = 4, - alternate_flag = 8, - zero_flag = 16 -}; - -/* - * Common state - */ - -struct snprintf_state { - unsigned char *str; - unsigned char *s; - unsigned char *theend; - size_t sz; - size_t max_sz; - void (*append_char)(struct snprintf_state *, unsigned char); - /* XXX - methods */ -}; - -static int -afs_sn_reserve (struct snprintf_state *state, size_t n) -{ - return state->s + n > state->theend; -} - -static void -afs_sn_append_char (struct snprintf_state *state, unsigned char c) -{ - if (!afs_sn_reserve (state, 1)) - *state->s++ = c; -} - -static int -as_reserve (struct snprintf_state *state, size_t n) -{ - if (state->s + n > state->theend) { - size_t off = state->s - state->str; - unsigned char *tmp; - - if (state->max_sz && state->sz >= state->max_sz) - return 1; - - state->sz = max(state->sz * 2, state->sz + n); - if (state->max_sz) - state->sz = min(state->sz, state->max_sz); - tmp = (unsigned char *)realloc (state->str, state->sz); - if (tmp == NULL) - return 1; - state->str = tmp; - state->s = state->str + off; - state->theend = state->str + state->sz - 1; - } - return 0; -} - -static void -as_append_char (struct snprintf_state *state, unsigned char c) -{ - if(!as_reserve (state, 1)) - *state->s++ = c; -} - -static int -pad(struct snprintf_state *state, int width, char c) -{ - int len = 0; - while(width-- > 0){ - (*state->append_char)(state, c); - ++len; - } - return len; -} - -/* return true if we should use alternatve hex form */ -static int -use_alternative (int flags, afs_uint64 num, unsigned base) -{ - return (flags & alternate_flag) && base == 16 && num != 0; -} - -static int -append_number(struct snprintf_state *state, - afs_uint64 num, unsigned base, const char *rep, - int width, int prec, int flags, int minusp) -{ - int len = 0; - afs_uint64 n = num; - char nstr[MAXPREC]; /* enough for <192 bit octal integers */ - int nstart, nlen; - char signchar; - - /* given precision, ignore zero flag */ - if(prec != -1) - flags &= ~zero_flag; - else - prec = 1; - - /* format number as string */ - nstart = sizeof(nstr); - nlen = 0; - nstr[--nstart] = '\0'; - - do { - nstr[--nstart] = rep[n % base]; - ++nlen; - n /= base; - } while(n); - - /* zero value with zero precision should produce no digits */ - if(prec == 0 && num == 0) { - nlen--; - nstart++; - } - - /* figure out what char to use for sign */ - if(minusp) - signchar = '-'; - else if((flags & plus_flag)) - signchar = '+'; - else if((flags & space_flag)) - signchar = ' '; - else - signchar = '\0'; - - if((flags & alternate_flag) && base == 8) { - /* if necessary, increase the precision to - make first digit a zero */ - - /* XXX C99 claims (regarding # and %o) that "if the value and - precision are both 0, a single 0 is printed", but there is - no such wording for %x. This would mean that %#.o would - output "0", but %#.x "". This does not make sense, and is - also not what other printf implementations are doing. */ - - if(prec <= nlen && nstr[nstart] != '0' && nstr[nstart] != '\0') - prec = nlen + 1; - } - - /* possible formats: - pad | sign | alt | zero | digits - sign | alt | zero | digits | pad minus_flag - sign | alt | zero | digits zero_flag */ - - /* if not right justifying or padding with zeros, we need to - compute the length of the rest of the string, and then pad with - spaces */ - if(!(flags & (minus_flag | zero_flag))) { - if(prec > nlen) - width -= prec; - else - width -= nlen; - - if(use_alternative(flags, num, base)) - width -= 2; - - if(signchar != '\0') - width--; - - /* pad to width */ - len += pad(state, width, ' '); - } - if(signchar != '\0') { - (*state->append_char)(state, signchar); - ++len; - } - if(use_alternative(flags, num, base)) { - (*state->append_char)(state, '0'); - (*state->append_char)(state, rep[10] + 23); /* XXX */ - len += 2; - } - if(flags & zero_flag) { - /* pad to width with zeros */ - if(prec - nlen > width - len - nlen) - len += pad(state, prec - nlen, '0'); - else - len += pad(state, width - len - nlen, '0'); - } else - /* pad to prec with zeros */ - len += pad(state, prec - nlen, '0'); - - while(nstr[nstart] != '\0') { - (*state->append_char)(state, nstr[nstart++]); - ++len; - } - - if(flags & minus_flag) - len += pad(state, width - len, ' '); - - return len; -} - -/* - * return length - */ - -static int -append_string (struct snprintf_state *state, - const unsigned char *arg, - int width, - int prec, - int flags) -{ - int len = 0; - - if(arg == NULL) - arg = (const unsigned char*)"(null)"; - - if(prec != -1) - width -= prec; - else - width -= (int)strlen((const char *)arg); - if(!(flags & minus_flag)) - len += pad(state, width, ' '); - - if (prec != -1) { - while (*arg && prec--) { - (*state->append_char) (state, *arg++); - ++len; - } - } else { - while (*arg) { - (*state->append_char) (state, *arg++); - ++len; - } - } - if(flags & minus_flag) - len += pad(state, width, ' '); - return len; -} - -static int -append_char(struct snprintf_state *state, - unsigned char arg, - int width, - int flags) -{ - int len = 0; - - while(!(flags & minus_flag) && --width > 0) { - (*state->append_char) (state, ' ') ; - ++len; - } - (*state->append_char) (state, arg); - ++len; - while((flags & minus_flag) && --width > 0) { - (*state->append_char) (state, ' '); - ++len; - } - return 0; -} - -#define MAXPREC 100 -static int -append_float(struct snprintf_state *state, - char type, - double arg, - int width, - int prec, - int flags) -{ - int len = 0; - char fbuf[20], xbuf[MAXPREC + 21]; - - sprintf(fbuf, "%%%s%s.*L%c", - (flags & plus_flag) ? "+" : ((flags & space_flag) ? " " : ((flags & minus_flag) ? "-" : "")), - (flags & alternate_flag) ? "#" : "", type); - if (prec == -1) - prec = 6; - if (prec > MAXPREC) - prec = MAXPREC; - sprintf(xbuf, fbuf, prec, arg); - - len = append_string(state, (unsigned char *)xbuf, width, -1, 0); - return len; -} - -static int -append_address(struct snprintf_state *state, - afs_uint32 arg, - int width, - int prec, - int flags) -{ - int len = 0; - struct hostent * he; - struct in_addr ia; - char * x, *y; - - /* IP address: - * value is provided as a network-order unsigned long integer - * precision specifies max hostname length, as for %s - * if precision is explicitly 0, no hostname lookup is done - * if 0fill specified, IPaddr fields are 0-filled to 3 digits - * if spsign specified, IPaddr fields are space-filled to 3 digits - */ - ia.s_addr = arg; - if (prec == 0) - he = 0; - else - he = gethostbyaddr((char *)&ia, 4, AF_INET); - if (he) { - x = he->h_name; - len = (int)strlen(x); - if (prec != -1 && prec < len) - width = prec; - else - width = len; - if (flags & alternate_flag) { - for (y = x; *y; y++) - if (isupper(*y)) - *y = tolower(*y); - } else if (flags & plus_flag) { - for (y = x; *y; y++) - if (islower(*y)) - *y = toupper(*y); - } - len = append_string(state, (unsigned char *)x, width, prec, 0); - } else { - char xbuf[16]; - arg = ntohl(arg); - if (flags & zero_flag) { - x = "%03u.%03u.%03u.%03u"; - } else if (flags & space_flag) { - x = "%3u.%3u.%3u.%3u"; - } else { - x = "%u.%u.%u.%u"; - } - /* typecast to whatever '%u' is! */ - sprintf(xbuf, x, (unsigned int)((arg & 0xff000000) >> 24), - (unsigned int)((arg & 0x00ff0000) >> 16), - (unsigned int)((arg & 0x0000ff00) >> 8), - (unsigned int)(arg & 0x000000ff)); - len = append_string(state, (unsigned char *)xbuf, 0, -1, 0); - } - - return len; -} - -/* - * This can't be made into a function... - */ - -#if defined(AFS_NT40_ENV) - -#define PARSE_INT_FORMAT(res, arg, unsig) \ -if (long_long_flag) \ - res = (unsig __int64)va_arg(arg, unsig __int64); \ -else if (long_flag || addr_flag) \ - res = (unsig long)va_arg(arg, unsig long); \ -else if (size_t_flag) \ - res = (size_t)va_arg(arg, size_t); \ -else if (short_flag) \ - res = (unsig short)va_arg(arg, unsig int); \ -else \ - res = (unsig int)va_arg(arg, unsig int) - -#else /* AFS_NT40_ENV */ - -#define PARSE_INT_FORMAT(res, arg, unsig) \ -if (long_long_flag) \ - res = (unsig long long)va_arg(arg, unsig long long); \ -else if (long_flag || addr_flag) \ - res = (unsig long)va_arg(arg, unsig long); \ -else if (size_t_flag) \ - res = (size_t)va_arg(arg, size_t); \ -else if (short_flag) \ - res = (unsig short)va_arg(arg, unsig int); \ -else \ - res = (unsig int)va_arg(arg, unsig int) -#endif - - -/* - * zyxprintf - return length, as snprintf - */ - -static int -xyzprintf (struct snprintf_state *state, const char *char_format, va_list ap) -{ - const unsigned char *format = (const unsigned char *)char_format; - unsigned char c; - int len = 0; - - while((c = *format++)) { - if (c == '%') { - int flags = 0; - int width = 0; - int prec = -1; - int size_t_flag = 0; - int long_long_flag = 0; - int long_flag = 0; - int short_flag = 0; - int addr_flag = 0; - - /* flags */ - while((c = *format++)){ - if(c == '-') - flags |= minus_flag; - else if(c == '+') - flags |= plus_flag; - else if(c == ' ') - flags |= space_flag; - else if(c == '#') - flags |= alternate_flag; - else if(c == '0') - flags |= zero_flag; - else if(c == '\'') - ; /* just ignore */ - else - break; - } - - if((flags & space_flag) && (flags & plus_flag)) - flags ^= space_flag; - - if((flags & minus_flag) && (flags & zero_flag)) - flags ^= zero_flag; - - /* width */ - if (isdigit(c)) - do { - width = width * 10 + c - '0'; - c = *format++; - } while(isdigit(c)); - else if(c == '*') { - width = va_arg(ap, int); - c = *format++; - } - - /* precision */ - if (c == '.') { - prec = 0; - c = *format++; - if (isdigit(c)) - do { - prec = prec * 10 + c - '0'; - c = *format++; - } while(isdigit(c)); - else if (c == '*') { - prec = va_arg(ap, int); - c = *format++; - } - } - - /* size */ - - if (c == 'h') { - short_flag = 1; - c = *format++; - } else if (c == 'z') { - size_t_flag = 1; - c = *format++; - } else if (c == 'l') { - long_flag = 1; - c = *format++; - if (c == 'l') { - long_long_flag = 1; - c = *format++; - } - } else if (c == 'I') { - /* This could be either Microsoft I{32,64} notation */ - c = *format++; - if (c == '3') { - long_flag = 1; - c = *format++; - if (c == '2') { - c = *format++; - } - } else if (c == '6') { - long_flag = 1; - c = *format++; - if (c == '4') { - long_long_flag = 1; - c = *format++; - } - } else { - /* Or the OpenAFS special %I meaning network address */ - addr_flag = 1; - --format; - c = 'I'; - } - } else if (c == 'p') { - flags |= zero_flag; - if (prec == -1) - prec = 2 * sizeof(void *); - if (sizeof(void *) == sizeof(afs_uint64)) - long_long_flag = 1; - else if (sizeof(void *) == sizeof(afs_uint32)) - long_flag = 1; - else - long_flag = 1; - } - - if(c != 'd' && c != 'i' && c != 'I') - flags &= ~(plus_flag | space_flag); - - switch (c) { - case 'c' : - append_char(state, va_arg(ap, int), width, flags); - ++len; - break; - case 's' : - len += append_string(state, - va_arg(ap, unsigned char*), - width, - prec, - flags); - break; - case 'd' : - case 'i' : { - afs_int64 arg; - afs_uint64 num; - int minusp = 0; - - PARSE_INT_FORMAT(arg, ap, signed); - - if (arg < 0) { - minusp = 1; - num = -arg; - } else - num = arg; - - len += append_number (state, num, 10, "0123456789", - width, prec, flags, minusp); - break; - } - case 'u' : { - afs_uint64 arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - len += append_number (state, arg, 10, "0123456789", - width, prec, flags, 0); - break; - } - case 'o' : { - afs_uint64 arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - len += append_number (state, arg, 010, "01234567", - width, prec, flags, 0); - break; - } - case 'x' : { - afs_uint64 arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - len += append_number (state, arg, 0x10, "0123456789abcdef", - width, prec, flags, 0); - break; - } - case 'X' :{ - afs_uint64 arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - len += append_number (state, arg, 0x10, "0123456789ABCDEF", - width, prec, flags, 0); - break; - } - case 'p' : { - afs_uint64 arg = (intptr_t)va_arg(ap, void*); - len += append_number (state, arg, 0x10, "0123456789ABCDEF", - width, prec, flags, 0); - break; - } - case 'n' : { - int *arg = va_arg(ap, int*); - *arg = (int)(state->s - state->str); - break; - } - case 'I' : { - afs_uint64 arg; - - PARSE_INT_FORMAT(arg, ap, unsigned); - - len += append_address (state, (unsigned long)arg, width, prec, flags); - break; - } - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': { - double arg = (double)va_arg(ap, double); - - len += append_float (state, c, arg, width, prec, flags); - break; - } - case '\0' : - --format; - /* FALLTHROUGH */ - case '%' : - (*state->append_char)(state, c); - ++len; - break; - default : - (*state->append_char)(state, '%'); - (*state->append_char)(state, c); - len += 2; - break; - } - } else { - (*state->append_char) (state, c); - ++len; - } - } - return len; -} - - -int -afs_vsnprintf (char *str, size_t sz, const char *format, va_list args) -{ - struct snprintf_state state; - int ret; - unsigned char *ustr = (unsigned char *)str; - - state.max_sz = 0; - state.sz = sz; - state.str = ustr; - state.s = ustr; - state.theend = ustr + sz - (sz > 0); - state.append_char = afs_sn_append_char; - - ret = xyzprintf (&state, format, args); - if (state.s != NULL && sz != 0) - *state.s = '\0'; - return ret; -} - -int -afs_snprintf (char *str, size_t sz, const char *format, ...) -{ - va_list args; - int ret; - - va_start(args, format); - ret = afs_vsnprintf (str, sz, format, args); - va_end(args); - -#ifdef PARANOIA - { - int ret2; - unsigned char *tmp; - - tmp = (unsigned char *)malloc (sz); - if (tmp == NULL) - abort (); - - va_start(args, format); - ret2 = afs_vsprintf (tmp, format, args); - va_end(args); - if (ret != ret2 || strcmp(str, tmp)) - abort (); - free (tmp); - } -#endif - - return ret; -} - -int -afs_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args) -{ - int st; - struct snprintf_state state; - - state.max_sz = max_sz; - state.sz = 1; - state.str = (unsigned char *)malloc(state.sz); - if (state.str == NULL) { - *ret = NULL; - return -1; - } - state.s = state.str; - state.theend = state.s + state.sz - 1; - state.append_char = as_append_char; - - st = xyzprintf (&state, format, args); - if (st > state.sz) { - free (state.str); - *ret = NULL; - return -1; - } else { - char *tmp; - - *state.s = '\0'; - tmp = (char *)realloc (state.str, st+1); - if (tmp == NULL) { - free (state.str); - *ret = NULL; - return -1; - } - *ret = tmp; - return st; - } -} - -int -afs_vasprintf (char **ret, const char *format, va_list args) -{ - return afs_vasnprintf (ret, 0, format, args); -} - -int -afs_asprintf (char **ret, const char *format, ...) -{ - va_list args; - int val; - - va_start(args, format); - val = afs_vasprintf (ret, format, args); - va_end(args); - -#ifdef PARANOIA - { - int ret2; - unsigned char *tmp; - tmp = (unsigned char *)malloc (val + 1); - if (tmp == NULL) - abort (); - - va_start(args, format); - ret2 = afs_vsprintf (tmp, format, args); - va_end(args); - if (val != ret2 || strcmp(*ret, tmp)) - abort (); - free (tmp); - } -#endif - - return val; -} - -int -afs_asnprintf (char **ret, size_t max_sz, const char *format, ...) -{ - va_list args; - int val; - - va_start(args, format); - val = afs_vasnprintf (ret, max_sz, format, args); - -#ifdef PARANOIA - { - int ret2; - unsigned char *tmp; - tmp = (unsigned char *)malloc (val + 1); - if (tmp == NULL) - abort (); - - ret2 = afs_vsprintf (tmp, format, args); - if (val != ret2 || strcmp(*ret, tmp)) - abort (); - free (tmp); - } -#endif - - va_end(args); - return val; -} - - -#ifndef AFS_NT40_ENV -#ifndef HAVE_VSYSLOG -void -vsyslog(int priority, const char *format, va_list args) -{ - char buf[1024]; - afs_vsnprintf(buf, sizeof(buf), format, args); - syslog(priority, "%s", buf); -} -#endif -#endif diff --git a/src/util/test/snprintf_test.c b/src/util/test/snprintf_test.c deleted file mode 100644 index 753f341..0000000 --- a/src/util/test/snprintf_test.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - * Copyright (c) 2000 - 2001 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of KTH nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#include -#include -#include - -static int -try (const char *format, ...) -{ - int ret; - va_list ap; - char buf1[256], buf2[256]; - - va_start (ap, format); - ret = afs_vsnprintf (buf1, sizeof(buf1), format, ap); - if (ret >= sizeof(buf1)) { - fprintf(stderr, "increase buf and try again\n"); - exit(1); - } - va_end (ap); - va_start (ap, format); - vsprintf (buf2, format, ap); - ret = strcmp (buf1, buf2); - if (ret) - printf ("failed: format = \"%s\", \"%s\" != \"%s\"\n", - format, buf1, buf2); - va_end (ap); - return ret; -} - -static int -cmp_with_sprintf_int (void) -{ - int tot = 0; - int int_values[] = {INT_MIN, -17, -1, 0, 1, 17, 4711, 65535, INT_MAX}; - int i; - - for (i = 0; i < sizeof(int_values) / sizeof(int_values[0]); ++i) { - tot += try ("%d", int_values[i]); - tot += try ("%x", int_values[i]); - tot += try ("%X", int_values[i]); - tot += try ("%o", int_values[i]); - tot += try ("%#x", int_values[i]); - tot += try ("%#X", int_values[i]); - tot += try ("%#o", int_values[i]); - tot += try ("%10d", int_values[i]); - tot += try ("%10x", int_values[i]); - tot += try ("%10X", int_values[i]); - tot += try ("%10o", int_values[i]); - tot += try ("%#10x", int_values[i]); - tot += try ("%#10X", int_values[i]); - tot += try ("%#10o", int_values[i]); - tot += try ("%-10d", int_values[i]); - tot += try ("%-10x", int_values[i]); - tot += try ("%-10X", int_values[i]); - tot += try ("%-10o", int_values[i]); - tot += try ("%-#10x", int_values[i]); - tot += try ("%-#10X", int_values[i]); - tot += try ("%-#10o", int_values[i]); - } - return tot; -} - -static int -cmp_with_sprintf_long (void) -{ - int tot = 0; - long long_values[] = {LONG_MIN, -17, -1, 0, 1, 17, 4711, 65535, LONG_MAX}; - int i; - - for (i = 0; i < sizeof(long_values) / sizeof(long_values[0]); ++i) { - tot += try ("%ld", long_values[i]); - tot += try ("%lx", long_values[i]); - tot += try ("%lX", long_values[i]); - tot += try ("%lo", long_values[i]); - tot += try ("%#lx", long_values[i]); - tot += try ("%#lX", long_values[i]); - tot += try ("%#lo", long_values[i]); - tot += try ("%10ld", long_values[i]); - tot += try ("%10lx", long_values[i]); - tot += try ("%10lX", long_values[i]); - tot += try ("%10lo", long_values[i]); - tot += try ("%#10lx", long_values[i]); - tot += try ("%#10lX", long_values[i]); - tot += try ("%#10lo", long_values[i]); - tot += try ("%-10ld", long_values[i]); - tot += try ("%-10lx", long_values[i]); - tot += try ("%-10lX", long_values[i]); - tot += try ("%-10lo", long_values[i]); - tot += try ("%-#10lx", long_values[i]); - tot += try ("%-#10lX", long_values[i]); - tot += try ("%-#10lo", long_values[i]); - } - return tot; -} - -#ifdef HAVE_LONG_LONG - -/* XXX doesn't work as expected on lp64 platforms with sizeof(long - * long) == sizeof(long) */ - -static int -cmp_with_sprintf_long_long (void) -{ - int tot = 0; - long long long_long_values[] = { - ((long long)LONG_MIN) -1, LONG_MIN, -17, -1, - 0, - 1, 17, 4711, 65535, LONG_MAX, ((long long)LONG_MAX) + 1}; - int i; - - for (i = 0; i < sizeof(long_long_values) / sizeof(long_long_values[0]); ++i) { - tot += try ("%lld", long_long_values[i]); - tot += try ("%llx", long_long_values[i]); - tot += try ("%llX", long_long_values[i]); - tot += try ("%llo", long_long_values[i]); - tot += try ("%#llx", long_long_values[i]); - tot += try ("%#llX", long_long_values[i]); - tot += try ("%#llo", long_long_values[i]); - tot += try ("%10lld", long_long_values[i]); - tot += try ("%10llx", long_long_values[i]); - tot += try ("%10llX", long_long_values[i]); - tot += try ("%10llo", long_long_values[i]); - tot += try ("%#10llx", long_long_values[i]); - tot += try ("%#10llX", long_long_values[i]); - tot += try ("%#10llo", long_long_values[i]); - tot += try ("%-10lld", long_long_values[i]); - tot += try ("%-10llx", long_long_values[i]); - tot += try ("%-10llX", long_long_values[i]); - tot += try ("%-10llo", long_long_values[i]); - tot += try ("%-#10llx", long_long_values[i]); - tot += try ("%-#10llX", long_long_values[i]); - tot += try ("%-#10llo", long_long_values[i]); - } - return tot; -} - -#endif - -#if defined(AFS_NT40_ENV) - -static int -cmp_with_sprintf_I64 (void) -{ - int tot = 0; - __int64 int64_values[] = { - ((__int64)LONG_MIN) -1, LONG_MIN, -17, -1, - 0, - 1, 17, 4711, 65535, LONG_MAX, ((__int64)LONG_MAX) + 1}; - int i; - - for (i = 0; i < sizeof(int64_values) / sizeof(int64_values[0]); ++i) { - tot += try ("%I64d", int64_values[i]); - tot += try ("%I64x", int64_values[i]); - tot += try ("%I64X", int64_values[i]); - tot += try ("%I64o", int64_values[i]); - tot += try ("%#I64x", int64_values[i]); - tot += try ("%#I64X", int64_values[i]); - tot += try ("%#I64o", int64_values[i]); - tot += try ("%10I64d", int64_values[i]); - tot += try ("%10I64x", int64_values[i]); - tot += try ("%10I64X", int64_values[i]); - tot += try ("%10I64o", int64_values[i]); - tot += try ("%#10I64x", int64_values[i]); - tot += try ("%#10I64X", int64_values[i]); - tot += try ("%#10I64o", int64_values[i]); - tot += try ("%-10I64d", int64_values[i]); - tot += try ("%-10I64x", int64_values[i]); - tot += try ("%-10I64X", int64_values[i]); - tot += try ("%-10I64o", int64_values[i]); - tot += try ("%-#10I64x", int64_values[i]); - tot += try ("%-#10I64X", int64_values[i]); - tot += try ("%-#10I64o", int64_values[i]); - } - return tot; -} - -#endif - -static int -cmp_with_sprintf_float (void) -{ - int tot = 0; - double double_values[] = {-99999, -999, -17.4, -4.3, -3.0, -1.5, -1, - 0, 0.1, 0.2342374852, 0.2340007, - 3.1415926, 14.7845, 34.24758, 9999, 9999999}; - int i; - - for (i = 0; i < sizeof(double_values) / sizeof(double_values[0]); ++i) { - tot += try ("%f", double_values[i]); - tot += try ("%10f", double_values[i]); - tot += try ("%.2f", double_values[i]); - tot += try ("%7.0f", double_values[i]); - tot += try ("%5.2f", double_values[i]); - tot += try ("%0f", double_values[i]); - tot += try ("%#f", double_values[i]); - tot += try ("%e", double_values[i]); - tot += try ("%10e", double_values[i]); - tot += try ("%.2e", double_values[i]); - tot += try ("%7.0e", double_values[i]); - tot += try ("%5.2e", double_values[i]); - tot += try ("%0e", double_values[i]); - tot += try ("%#e", double_values[i]); - tot += try ("%E", double_values[i]); - tot += try ("%10E", double_values[i]); - tot += try ("%.2E", double_values[i]); - tot += try ("%7.0E", double_values[i]); - tot += try ("%5.2E", double_values[i]); - tot += try ("%0E", double_values[i]); - tot += try ("%#E", double_values[i]); - tot += try ("%g", double_values[i]); - tot += try ("%10g", double_values[i]); - tot += try ("%.2g", double_values[i]); - tot += try ("%7.0g", double_values[i]); - tot += try ("%5.2g", double_values[i]); - tot += try ("%0g", double_values[i]); - tot += try ("%#g", double_values[i]); - tot += try ("%G", double_values[i]); - tot += try ("%10G", double_values[i]); - tot += try ("%.2G", double_values[i]); - tot += try ("%7.0G", double_values[i]); - tot += try ("%5.2G", double_values[i]); - tot += try ("%0G", double_values[i]); - tot += try ("%#G", double_values[i]); - } - return tot; -} - -static int -test_null (void) -{ - return afs_snprintf (NULL, 0, "foo") != 3; -} - -static int -test_sizet (void) -{ - int tot = 0; - size_t sizet_values[] = { 0, 1, 2, 200, 4294967295u -#ifdef _WIN64 - ,0xffffffffffffffffui64 -#endif - }; /* SIZE_MAX */ - char *result[] = { "0", "1", "2", "200", "4294967295" -#ifdef _WIN64 - ,"18446744073709551615" -#endif - }; - int i; - - for (i = 0; i < sizeof(sizet_values) / sizeof(sizet_values[0]); ++i) { -#if 0 - tot += try("%zu", sizet_values[i]); - tot += try("%zx", sizet_values[i]); - tot += try("%zX", sizet_values[i]); -#else - char buf[256]; - afs_snprintf(buf, sizeof(buf), "%zu", sizet_values[i]); - if (strcmp(buf, result[i]) != 0) { - printf("%s != %s", buf, result[i]); - tot++; - } -#endif - } - return tot; -} - -static int -test_ptr (void) -{ - int tot = 0; - void * ptr; - - if (sizeof(ptr) == 4) { - ptr = (void *)0x12345678; - tot += try ("%p", ptr); - tot += try ("%#p", ptr); - tot += try ("%4p", ptr); - tot += try ("%#4p", ptr); - tot += try ("%-4p", ptr); - tot += try ("%-#4p", ptr); - } else if (sizeof(ptr) == 8) { - ptr = (void *)0x0102030405060708; - tot += try ("%p", ptr); - tot += try ("%#p", ptr); - tot += try ("%8p", ptr); - tot += try ("%#8p", ptr); - tot += try ("%-8p", ptr); - tot += try ("%-#8p", ptr); - } - - - return tot; -} - -static int -test_ipaddr (void) -{ - int tot = 0; - struct hostent * he = gethostbyname("www.openafs.org"); - char buf[256]; - unsigned long addr; - - if (!he) { - fprintf(stderr, "gethostbyname failure\n"); - tot = 1; - } - addr = *((unsigned long *)he->h_addr); - afs_snprintf(buf, sizeof(buf), "%I", addr); - if (strcmp(buf, "OPENAFS.ORG")) { - fprintf(stderr, "%s != %s\n", buf, "OPENAFS.ORG"); - tot++; - } - afs_snprintf(buf, sizeof(buf), "%+I", addr); - if (strcmp(buf, "OPENAFS.ORG")) { - fprintf(stderr, "%s != %s\n", buf, "OPENAFS.ORG"); - tot++; - } - afs_snprintf(buf, sizeof(buf), "%#I", addr); - if (strcmp(buf, "openafs.org")) { - fprintf(stderr, "%s != %s\n", buf, "openafs.org"); - tot++; - } - afs_snprintf(buf, sizeof(buf), "%.7I", addr); - if (strcmp(buf, "OPENAFS")) { - fprintf(stderr, "%s != %s\n", buf, "OPENAFS"); - tot++; - } - afs_snprintf(buf, sizeof(buf), "%.0I", addr); - if (strcmp(buf, "128.2.200.90")) { - fprintf(stderr, "%s != %s\n", buf, "128.2.200.90"); - tot++; - } - afs_snprintf(buf, sizeof(buf), "%0.0I", addr); - if (strcmp(buf, "128.002.200.090")) { - fprintf(stderr, "%s != %s\n", buf, "128.002.200.090"); - tot++; - } - afs_snprintf(buf, sizeof(buf), "% .0I", addr); - if (strcmp(buf, "128. 2.200. 90")) { - fprintf(stderr, "%s != %s\n", buf, "128. 2.200. 90"); - tot++; - } - - return tot; -} - - -int -main (int argc, char **argv) -{ - int ret = 0; - -#ifdef AFS_NT40_ENV - afs_winsockInit(); -#endif - - ret += cmp_with_sprintf_int (); - ret += cmp_with_sprintf_long (); -#ifdef HAVE_LONG_LONG - ret += cmp_with_sprintf_long_long (); -#endif -#if defined(AFS_NT40_ENV) - ret += cmp_with_sprintf_I64 (); -#endif - ret += cmp_with_sprintf_float (); - ret += test_null (); - ret += test_sizet (); - ret += test_ptr (); - ret += test_ipaddr (); - -#ifdef AFS_NT40_ENV - afs_winsockCleanup(); -#endif - - return ret; -} diff --git a/src/venus/fstrace.c b/src/venus/fstrace.c index b677431..3cb5bfa 100644 --- a/src/venus/fstrace.c +++ b/src/venus/fstrace.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -622,8 +623,8 @@ dce1_error_inq_text(afs_uint32 status_to_convert, * install this special message catalog in with internationalization * catalogs. */ - afs_snprintf(nls_filename, sizeof(nls_filename), "%s/C/%s.cat", - AFSDIR_CLIENT_DATA_DIRPATH, filename_prefix); + snprintf(nls_filename, sizeof(nls_filename), "%s/C/%s.cat", + AFSDIR_CLIENT_DATA_DIRPATH, filename_prefix); catd = catopen(nls_filename, 0); if (catd == (nl_catd) -1) { diff --git a/src/viced/afsfileprocs.c b/src/viced/afsfileprocs.c index a8f9975..2349c04 100644 --- a/src/viced/afsfileprocs.c +++ b/src/viced/afsfileprocs.c @@ -326,8 +326,7 @@ CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen) if (alen != vlen) { afs_int64 alen64 = alen, vlen64 = vlen; ViceLog(0, ("Fid %lu.%lu.%lu has inconsistent length (index " - "%" AFS_INT64_FMT ", inode %" AFS_INT64_FMT "); volume " - "must be salvaged\n", + "%lld inode %lld ); volume must be salvaged\n", afs_printable_uint32_lu(vp->hashid), afs_printable_uint32_lu(Vn_id(vnp)), afs_printable_uint32_lu(vnp->disk.uniquifier), @@ -1821,7 +1820,7 @@ Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr, AdjustDiskUsage(volptr, BlocksPreallocatedForVnode, BlocksPreallocatedForVnode))) { ViceLog(25, - ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n", + ("Insufficient space to allocate %lld blocks\n", (afs_intmax_t) BlocksPreallocatedForVnode)); return (errorCode); } diff --git a/src/viced/host.c b/src/viced/host.c index 211383a..ae5b008 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -2749,34 +2749,30 @@ h_PrintClient(struct host *host, int flags, void *rock) H_UNLOCK; return flags; } - (void)afs_snprintf(tmpStr, sizeof tmpStr, - "Host %s:%d down = %d, LastCall %s", - afs_inet_ntoa_r(host->host, hoststr), - ntohs(host->port), (host->hostFlags & VENUSDOWN), - afs_ctime(&LastCall, tbuffer, - sizeof(tbuffer))); + snprintf(tmpStr, sizeof tmpStr, "Host %s:%d down = %d, LastCall %s", + afs_inet_ntoa_r(host->host, hoststr), + ntohs(host->port), (host->hostFlags & VENUSDOWN), + afs_ctime(&LastCall, tbuffer, sizeof(tbuffer))); (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); for (client = host->FirstClient; client; client = client->next) { if (!client->deleted) { - expTime = client->expTime; - (void)afs_snprintf(tmpStr, sizeof tmpStr, - " user id=%d, name=%s, sl=%s till %s", - client->ViceId, h_UserName(client), - client-> - authClass ? "Authenticated" : - "Not authenticated", - client-> - authClass ? afs_ctime(&expTime, tbuffer, - sizeof(tbuffer)) - : "No Limit\n"); - (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); - (void)afs_snprintf(tmpStr, sizeof tmpStr, " CPS-%d is [", - client->CPS.prlist_len); + expTime = client->expTime; + snprintf(tmpStr, sizeof tmpStr, + " user id=%d, name=%s, sl=%s till %s", + client->ViceId, h_UserName(client), + client->authClass ? "Authenticated" + : "Not authenticated", + client->authClass ? afs_ctime(&expTime, tbuffer, + sizeof(tbuffer)) + : "No Limit\n"); + (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); + snprintf(tmpStr, sizeof tmpStr, " CPS-%d is [", + client->CPS.prlist_len); (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); if (client->CPS.prlist_val) { for (i = 0; i < client->CPS.prlist_len; i++) { - (void)afs_snprintf(tmpStr, sizeof tmpStr, " %d", - client->CPS.prlist_val[i]); + snprintf(tmpStr, sizeof tmpStr, " %d", + client->CPS.prlist_val[i]); (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); } } @@ -2811,8 +2807,8 @@ h_PrintClients(void) return; } now = FT_ApproxTime(); - (void)afs_snprintf(tmpStr, sizeof tmpStr, "List of active users at %s\n", - afs_ctime(&now, tbuffer, sizeof(tbuffer))); + snprintf(tmpStr, sizeof tmpStr, "List of active users at %s\n", + afs_ctime(&now, tbuffer, sizeof(tbuffer))); (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); h_Enumerate(h_PrintClient, (char *)file); STREAM_REALLYCLOSE(file); @@ -2832,19 +2828,20 @@ h_DumpHost(struct host *host, int flags, void *rock) char hoststr[16]; H_LOCK; - (void)afs_snprintf(tmpStr, sizeof tmpStr, - "ip:%s port:%d hidx:%d cbid:%d lock:%x last:%u active:%u down:%d del:%d cons:%d cldel:%d\n\t hpfailed:%d hcpsCall:%u hcps [", - afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), host->index, - host->cblist, CheckLock(&host->lock), host->LastCall, - host->ActiveCall, (host->hostFlags & VENUSDOWN), - host->hostFlags & HOSTDELETED, host->Console, - host->hostFlags & CLIENTDELETED, host->hcpsfailed, - host->cpsCall); + snprintf(tmpStr, sizeof tmpStr, + "ip:%s port:%d hidx:%d cbid:%d lock:%x last:%u active:%u " + "down:%d del:%d cons:%d cldel:%d\n\t hpfailed:%d hcpsCall:%u " + "hcps [", + afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), + host->index, host->cblist, CheckLock(&host->lock), + host->LastCall, host->ActiveCall, (host->hostFlags & VENUSDOWN), + host->hostFlags & HOSTDELETED, host->Console, + host->hostFlags & CLIENTDELETED, host->hcpsfailed, + host->cpsCall); (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); if (host->hcps.prlist_val) for (i = 0; i < host->hcps.prlist_len; i++) { - (void)afs_snprintf(tmpStr, sizeof tmpStr, " %d", - host->hcps.prlist_val[i]); + snprintf(tmpStr, sizeof tmpStr, " %d", host->hcps.prlist_val[i]); (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); } sprintf(tmpStr, "] ["); @@ -2881,8 +2878,8 @@ h_DumpHosts(void) return; } now = FT_ApproxTime(); - (void)afs_snprintf(tmpStr, sizeof tmpStr, "List of active hosts at %s\n", - afs_ctime(&now, tbuffer, sizeof(tbuffer))); + snprintf(tmpStr, sizeof tmpStr, "List of active hosts at %s\n", + afs_ctime(&now, tbuffer, sizeof(tbuffer))); (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file); h_Enumerate(h_DumpHost, (char *)file); STREAM_REALLYCLOSE(file); diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index 82c4aad..7cf3042 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -353,12 +353,13 @@ namei_ViceREADME(char *partition) int fd; /* Create the inode directory if we're starting for the first time */ - (void)afs_snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s", partition, - INODEDIR); + snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s", partition, + INODEDIR); mkdir(filename, 0700); - (void)afs_snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s" OS_DIRSEP "README", - partition, INODEDIR); + snprintf(filename, sizeof filename, + "%s" OS_DIRSEP "%s" OS_DIRSEP "README", + partition, INODEDIR); fd = OS_OPEN(filename, O_WRONLY | O_CREAT | O_TRUNC, 0444); if (fd != INVALID_FD) { (void)OS_WRITE(fd, VICE_README, strlen(VICE_README)); @@ -382,7 +383,7 @@ namei_CreateDataDirectories(namei_t * name, int *created) int i; *created = 0; - afs_snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir); + snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir); if (mkdir(tmp) < 0) { if (errno != EEXIST) @@ -540,7 +541,7 @@ namei_RemoveDataDirectories(namei_t * name) char tmp[256]; int i; - afs_snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir); + snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir); path = tmp; path += strlen(path); @@ -1067,7 +1068,7 @@ namei_dec(IHandle_t * ih, Inode ino, int p1) } else { IHandle_t *th; IH_INIT(th, ih->ih_dev, ih->ih_vid, ino); - Log("Warning: Lost ref on ihandle dev %d vid %d ino %" AFS_INT64_FMT "\n", + Log("Warning: Lost ref on ihandle dev %d vid %d ino %lld\n", th->ih_dev, th->ih_vid, (afs_int64)th->ih_ino); IH_RELEASE(th); @@ -1171,7 +1172,7 @@ namei_copy_on_write(IHandle_t *h) fdP = IH_OPEN(h); if (!fdP) return EIO; - afs_snprintf(path, sizeof(path), "%s-tmp", name.n_path); + snprintf(path, sizeof(path), "%s-tmp", name.n_path); fd = OS_OPEN(path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0); if (fd == INVALID_FD) { FDH_CLOSE(fdP); @@ -1760,8 +1761,8 @@ namei_ListAFSFiles(char *dev, #else if (*dp1->d_name == '.') continue; - afs_snprintf(path2, sizeof(path2), "%s" OS_DIRSEP "%s", name.n_path, - dp1->d_name); + snprintf(path2, sizeof(path2), "%s" OS_DIRSEP "%s", name.n_path, + dp1->d_name); dirp2 = opendir(path2); if (dirp2) { while ((dp2 = readdir(dirp2))) { @@ -1861,8 +1862,8 @@ _namei_examine_special(char * path1, } else { char path2[512]; /* Open this handle */ - (void)afs_snprintf(path2, sizeof(path2), - "%s" OS_DIRSEP "%s", path1, dname); + snprintf(path2, sizeof(path2), + "%s" OS_DIRSEP "%s", path1, dname); linkHandle->fd_fd = OS_OPEN(path2, Testing ? O_RDONLY : O_RDWR, 0666); info.linkCount = namei_GetLinkCount(linkHandle, (Inode) 0, 1, 1, Testing); @@ -2444,7 +2445,8 @@ namei_ListAFSSubDirs(IHandle_t * dirIH, #ifndef AFS_NT40_ENV /* This level missing on Windows */ /* Now we've got a next level subdir. */ - afs_snprintf(path2, sizeof(path2), "%s" OS_DIRSEP "%s", path1, dp1->d_name); + snprintf(path2, sizeof(path2), "%s" OS_DIRSEP "%s", + path1, dp1->d_name); dirp2 = opendir(path2); if (dirp2) { while ((dp2 = readdir(dirp2))) { @@ -2452,12 +2454,12 @@ namei_ListAFSSubDirs(IHandle_t * dirIH, continue; /* Now we've got to the actual data */ - afs_snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s", path2, - dp2->d_name); + snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s", + path2, dp2->d_name); #else /* Now we've got to the actual data */ - afs_snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s", path1, - dp1->d_name); + snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s", + path1, dp1->d_name); #endif dirp3 = opendir(path3); if (dirp3) { @@ -2598,7 +2600,7 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, FdHandle_t linkHandle; char dirl; - afs_snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name); + snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name); dirH = FindFirstFileEx(fpath, FindExInfoStandard, &data, FindExSearchNameMatch, NULL, @@ -2670,7 +2672,7 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, int parm, tag; lb64_string_t check; - afs_snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name); + snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name); if (afs_stat(fpath, &status) < 0) { return -1; @@ -2913,8 +2915,8 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId) t_ih.ih_dev = ih->ih_dev; t_ih.ih_vid = ih->ih_vid; - (void)afs_snprintf(oldpath, sizeof oldpath, "%s" OS_DIRSEP "%s", dir_name, - infoName); + snprintf(oldpath, sizeof oldpath, "%s" OS_DIRSEP "%s", dir_name, + infoName); fd = OS_OPEN(oldpath, O_RDWR, 0); if (fd == INVALID_FD) { Log("1 namei_ConvertROtoRWvolume: could not open RO info file: %s\n", @@ -2944,8 +2946,8 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId) t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_SMALLINDEX); namei_HandleToName(&n, &t_ih); - (void)afs_snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name, - smallName); + snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name, + smallName); fd = OS_OPEN(newpath, O_RDWR, 0); if (fd == INVALID_FD) { Log("1 namei_ConvertROtoRWvolume: could not open SmallIndex file: %s\n", newpath); @@ -2963,8 +2965,8 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId) t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_LARGEINDEX); namei_HandleToName(&n, &t_ih); - (void)afs_snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name, - largeName); + snprintf(newpath, sizeof newpath, "%s" OS_DIRSEP "%s", dir_name, + largeName); fd = OS_OPEN(newpath, O_RDWR, 0); if (fd == INVALID_FD) { Log("1 namei_ConvertROtoRWvolume: could not open LargeIndex file: %s\n", newpath); @@ -3025,7 +3027,7 @@ PrintInode(char *s, Inode ino) if (!s) s = result; - (void)afs_snprintf(s, sizeof(afs_ino_str_t), "%" AFS_UINT64_FMT, (afs_uintmax_t) ino); + snprintf(s, sizeof(afs_ino_str_t), "%llu", (afs_uintmax_t) ino); return s; } diff --git a/src/vol/partition.c b/src/vol/partition.c index 48e18c2..2fec1bb 100644 --- a/src/vol/partition.c +++ b/src/vol/partition.c @@ -250,11 +250,11 @@ VInitPartition_r(char *path, char *devname, Device dev) dp->vol_list.busy = 0; { char lockpath[MAXPATHLEN+1]; - afs_snprintf(lockpath, MAXPATHLEN, "%s/" AFS_PARTLOCK_FILE, dp->name); + snprintf(lockpath, MAXPATHLEN, "%s/" AFS_PARTLOCK_FILE, dp->name); lockpath[MAXPATHLEN] = '\0'; VLockFileInit(&dp->headerLockFile, lockpath); - afs_snprintf(lockpath, MAXPATHLEN, "%s/" AFS_VOLUMELOCK_FILE, dp->name); + snprintf(lockpath, MAXPATHLEN, "%s/" AFS_VOLUMELOCK_FILE, dp->name); lockpath[MAXPATHLEN] = '\0'; VLockFileInit(&dp->volLockFile, lockpath); } @@ -1093,14 +1093,14 @@ VPrintDiskStats_r(void) struct DiskPartition64 *dp; for (dp = DiskPartitionList; dp; dp = dp->next) { if (dp->free < 0) { - Log("Partition %s: %"AFS_INT64_FMT - " available 1K blocks (minfree=%"AFS_INT64_FMT"), " - "overallocated by %"AFS_INT64_FMT" blocks\n", dp->name, + Log("Partition %s: %lld " + " available 1K blocks (minfree=%lld), " + "overallocated by %lld blocks\n", dp->name, dp->totalUsable, dp->minFree, -dp->free); } else { - Log("Partition %s: %"AFS_INT64_FMT - " available 1K blocks (minfree=%"AFS_INT64_FMT"), " - "%"AFS_INT64_FMT" free blocks\n", dp->name, + Log("Partition %s: %lld" + " available 1K blocks (minfree=%lld), " + "%lld free blocks\n", dp->name, dp->totalUsable, dp->minFree, dp->free); } } diff --git a/src/vol/salvaged.c b/src/vol/salvaged.c index 6883849..d977df9 100644 --- a/src/vol/salvaged.c +++ b/src/vol/salvaged.c @@ -611,8 +611,8 @@ DoSalvageVolume(struct SalvageQueueNode * node, int slot) * another thread may have held the lock on the FILE * structure when fork was called! */ - afs_snprintf(childLog, sizeof(childLog), "%s.%d", - AFSDIR_SERVER_SLVGLOG_FILEPATH, getpid()); + snprintf(childLog, sizeof(childLog), "%s.%d", + AFSDIR_SERVER_SLVGLOG_FILEPATH, getpid()); logFile = afs_fopen(childLog, "a"); if (!logFile) { /* still nothing, use stdout */ @@ -755,8 +755,8 @@ SalvageLogCleanup(int pid) char fn[AFSDIR_PATH_MAX]; static char buf[LOG_XFER_BUF_SIZE]; - afs_snprintf(fn, sizeof(fn), "%s.%d", - AFSDIR_SERVER_SLVGLOG_FILEPATH, pid); + snprintf(fn, sizeof(fn), "%s.%d", + AFSDIR_SERVER_SLVGLOG_FILEPATH, pid); pidlog = open(fn, O_RDONLY); @@ -801,7 +801,7 @@ SalvageLogScanningThread(void * arg) char prefix[AFSDIR_PATH_MAX]; size_t prefix_len; - afs_snprintf(prefix, sizeof(prefix), "%s.", AFSDIR_SLVGLOG_FILE); + snprintf(prefix, sizeof(prefix), "%s.", AFSDIR_SLVGLOG_FILE); prefix_len = strlen(prefix); dp = opendir(AFSDIR_LOGS_DIR); diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index 7e4b3ba..6a95cbd 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -101,8 +101,8 @@ date(time_t date) char buf[32]; (void)strftime(buf, 32, "%Y/%m/%d.%H:%M:%S", tm); /* NT does not have %T */ - (void)afs_snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT, - "%lu (%s)", (unsigned long)date, buf); + snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT, + "%lu (%s)", (unsigned long)date, buf); return results[next]; } @@ -311,8 +311,8 @@ handleit(struct cmd_syndesc *as, void *arock) exit(1); } } - (void)afs_snprintf(name1, sizeof name1, VFORMAT, - afs_printable_uint32_lu(volumeId)); + snprintf(name1, sizeof name1, VFORMAT, + afs_printable_uint32_lu(volumeId)); if (dsizeOnly && !saveinodes) printf ("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n"); @@ -446,8 +446,8 @@ HandleVolume(struct DiskPartition64 *dp, char *name) } else { afs_sfsize_t n; - (void)afs_snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s", - VPartitionPath(dp), name); + snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s", + VPartitionPath(dp), name); if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD || OS_SIZE(fd) < 0) { printf("Volinfo: Cannot read volume header %s\n", name); @@ -786,8 +786,8 @@ PrintVnodes(Volume * vp, VnodeClass class) PrintInode(NULL, ino), errno); continue; } - (void)afs_snprintf(nfile, sizeof nfile, "TmpInode.%s", - PrintInode(NULL, ino)); + snprintf(nfile, sizeof nfile, "TmpInode.%s", + PrintInode(NULL, ino)); ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600); if (ofd < 0) { printf("Can't create file %s; error %d (ignored)\n", diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 5e43d2b..b212265 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -634,10 +634,9 @@ SalvageFileSysParallel(struct DiskPartition64 *partP) } else #endif { - (void)afs_snprintf(logFileName, sizeof logFileName, - "%s.%d", - AFSDIR_SERVER_SLVGLOG_FILEPATH, - jobs[startjob]->jobnumb); + snprintf(logFileName, sizeof logFileName, "%s.%d", + AFSDIR_SERVER_SLVGLOG_FILEPATH, + jobs[startjob]->jobnumb); logFile = afs_fopen(logFileName, "w"); } if (!logFile) @@ -656,8 +655,8 @@ SalvageFileSysParallel(struct DiskPartition64 *partP) #endif if (!partP) { for (i = 0; i < jobcount; i++) { - (void)afs_snprintf(logFileName, sizeof logFileName, "%s.%d", - AFSDIR_SERVER_SLVGLOG_FILEPATH, i); + snprintf(logFileName, sizeof logFileName, "%s.%d", + AFSDIR_SERVER_SLVGLOG_FILEPATH, i); if ((passLog = afs_fopen(logFileName, "r"))) { while (fgets(buf, sizeof(buf), passLog)) { fputs(buf, logFile); @@ -1192,8 +1191,8 @@ GetInodeSummary(struct SalvInfo *salvinfo, FD_t inodeFile, VolumeId singleVolume (void)_putenv("TMP="); /* If "TMP" is set, then that overrides tdir. */ (void)strcpy(summaryFileName, _tempnam(tdir, "salvage.temp.")); #else - (void)afs_snprintf(summaryFileName, sizeof summaryFileName, - "%s" OS_DIRSEP "salvage.temp.%d", tdir, getpid()); + snprintf(summaryFileName, sizeof summaryFileName, + "%s" OS_DIRSEP "salvage.temp.%d", tdir, getpid()); #endif summaryFile = OS_OPEN(summaryFileName, O_RDWR|O_APPEND|O_CREAT, 0666); if (summaryFile == INVALID_FD) { @@ -1578,8 +1577,8 @@ RecordHeader(struct DiskPartition64 *dp, const char *name, base = name; } - (void)afs_snprintf(nameShouldBe, sizeof nameShouldBe, - VFORMAT, afs_printable_uint32_lu(summary.header.id)); + snprintf(nameShouldBe, sizeof nameShouldBe, + VFORMAT, afs_printable_uint32_lu(summary.header.id)); if (strcmp(nameShouldBe, base)) { @@ -2300,8 +2299,10 @@ SalvageVolumeHeaderFile(struct SalvInfo *salvinfo, struct InodeSummary *isp, if (isp->volSummary == NULL) { char path[64]; char headerName[64]; - (void)afs_snprintf(headerName, sizeof headerName, VFORMAT, afs_printable_uint32_lu(isp->volumeId)); - (void)afs_snprintf(path, sizeof path, "%s" OS_DIRSEP "%s", salvinfo->fileSysPath, headerName); + snprintf(headerName, sizeof headerName, VFORMAT, + afs_printable_uint32_lu(isp->volumeId)); + snprintf(path, sizeof path, "%s" OS_DIRSEP "%s", + salvinfo->fileSysPath, headerName); if (check) { Log("No header file for volume %u\n", isp->volumeId); return -1; @@ -2328,10 +2329,12 @@ SalvageVolumeHeaderFile(struct SalvInfo *salvinfo, struct InodeSummary *isp, if (isp->volSummary->fileName) { strcpy(headerName, isp->volSummary->fileName); } else { - (void)afs_snprintf(headerName, sizeof headerName, VFORMAT, afs_printable_uint32_lu(isp->volumeId)); + snprintf(headerName, sizeof headerName, VFORMAT, + afs_printable_uint32_lu(isp->volumeId)); isp->volSummary->fileName = ToString(headerName); } - (void)afs_snprintf(path, sizeof path, "%s" OS_DIRSEP "%s", salvinfo->fileSysPath, headerName); + snprintf(path, sizeof path, "%s" OS_DIRSEP "%s", + salvinfo->fileSysPath, headerName); Log("Header file %s is damaged or no longer valid%s\n", path, (check ? "" : "; repairing")); @@ -3973,11 +3976,10 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * pa.Vnode = ThisVnode; pa.Unique = ThisUnique; - (void)afs_snprintf(npath, sizeof npath, "%s.%u.%u", - ((class == - vLarge) ? "__ORPHANDIR__" : - "__ORPHANFILE__"), ThisVnode, - ThisUnique); + snprintf(npath, sizeof npath, "%s.%u.%u", + ((class == vLarge) ? "__ORPHANDIR__" + : "__ORPHANFILE__"), + ThisVnode, ThisUnique); CopyOnWrite(salvinfo, &rootdir); code = Create(&rootdir.dirHandle, npath, &pa); @@ -4697,11 +4699,10 @@ TimeStampLogFile(char * log_path) now = time(0); lt = localtime(&now); - (void)afs_snprintf(stampSlvgLog, sizeof stampSlvgLog, - "%s.%04d-%02d-%02d.%02d:%02d:%02d", - log_path, lt->tm_year + 1900, - lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, - lt->tm_sec); + snprintf(stampSlvgLog, sizeof stampSlvgLog, + "%s.%04d-%02d-%02d.%02d:%02d:%02d", log_path, + lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, + lt->tm_min, lt->tm_sec); /* try to link the logfile to a timestamped filename */ /* if it fails, oh well, nothing we can do */ @@ -4747,7 +4748,7 @@ Log(const char *format, ...) va_list args; va_start(args, format); - (void)afs_vsnprintf(tmp, sizeof tmp, format, args); + vsnprintf(tmp, sizeof tmp, format, args); va_end(args); #ifndef AFS_NT40_ENV if (useSyslog) { @@ -4768,7 +4769,7 @@ Abort(const char *format, ...) char tmp[1024]; va_start(args, format); - (void)afs_vsnprintf(tmp, sizeof tmp, format, args); + vsnprintf(tmp, sizeof tmp, format, args); va_end(args); #ifndef AFS_NT40_ENV if (useSyslog) { diff --git a/src/vol/volume.c b/src/vol/volume.c index d884a40..bf8c02b 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -6495,7 +6495,8 @@ VGetVolumePath(Error * ec, VolId volumeId, char **partitionp, char **namep) *ec = 0; name[0] = OS_DIRSEPC; - (void)afs_snprintf(&name[1], (sizeof name) - 1, VFORMAT, afs_printable_uint32_lu(volumeId)); + snprintf(&name[1], (sizeof name) - 1, VFORMAT, + afs_printable_uint32_lu(volumeId)); for (dp = DiskPartitionList; dp; dp = dp->next) { struct afs_stat_st status; strcpy(path, VPartitionPath(dp)); @@ -6558,7 +6559,7 @@ char * VolumeExternalName(VolumeId volumeId) { static char name[VMAXPATHLEN]; - (void)afs_snprintf(name, sizeof name, VFORMAT, afs_printable_uint32_lu(volumeId)); + snprintf(name, sizeof name, VFORMAT, afs_printable_uint32_lu(volumeId)); return name; } @@ -6579,7 +6580,7 @@ VolumeExternalName(VolumeId volumeId) int VolumeExternalName_r(VolumeId volumeId, char * name, size_t len) { - return afs_snprintf(name, len, VFORMAT, afs_printable_uint32_lu(volumeId)); + return snprintf(name, len, VFORMAT, afs_printable_uint32_lu(volumeId)); } diff --git a/src/vol/vutil.c b/src/vol/vutil.c index 55e60a6..b918389 100644 --- a/src/vol/vutil.c +++ b/src/vol/vutil.c @@ -194,9 +194,10 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId) vol.stamp.magic = VOLUMEINFOMAGIC; vol.stamp.version = VOLUMEINFOVERSION; vol.destroyMe = DESTROY_ME; - (void)afs_snprintf(headerName, sizeof headerName, VFORMAT, afs_printable_uint32_lu(vol.id)); - (void)afs_snprintf(volumePath, sizeof volumePath, "%s" OS_DIRSEP "%s", - VPartitionPath(partition), headerName); + snprintf(headerName, sizeof headerName, VFORMAT, + afs_printable_uint32_lu(vol.id)); + snprintf(volumePath, sizeof volumePath, "%s" OS_DIRSEP "%s", + VPartitionPath(partition), headerName); rc = stat(volumePath, &st); if (rc == 0 || errno != ENOENT) { if (rc == 0) { @@ -422,9 +423,8 @@ VReadVolumeDiskHeader(VolumeId volid, int fd; char path[MAXPATHLEN]; - (void)afs_snprintf(path, sizeof(path), - "%s" OS_DIRSEP VFORMAT, - VPartitionPath(dp), afs_printable_uint32_lu(volid)); + snprintf(path, sizeof(path), "%s" OS_DIRSEP VFORMAT, + VPartitionPath(dp), afs_printable_uint32_lu(volid)); fd = open(path, O_RDONLY); if (fd < 0) { Log("VReadVolumeDiskHeader: Couldn't open header for volume %lu (errno %d).\n", @@ -478,9 +478,8 @@ _VWriteVolumeDiskHeader(VolumeDiskHeader_t * hdr, flags |= O_RDWR; - (void)afs_snprintf(path, sizeof(path), - "%s" OS_DIRSEP VFORMAT, - VPartitionPath(dp), afs_printable_uint32_lu(hdr->id)); + snprintf(path, sizeof(path), "%s" OS_DIRSEP VFORMAT, + VPartitionPath(dp), afs_printable_uint32_lu(hdr->id)); fd = open(path, flags, 0644); if (fd < 0) { code = errno; @@ -658,9 +657,8 @@ VDestroyVolumeDiskHeader(struct DiskPartition64 * dp, SYNC_response res; #endif /* AFS_DEMAND_ATTACH_FS */ - (void)afs_snprintf(path, sizeof(path), - "%s" OS_DIRSEP VFORMAT, - VPartitionPath(dp), afs_printable_uint32_lu(volid)); + snprintf(path, sizeof(path), "%s" OS_DIRSEP VFORMAT, + VPartitionPath(dp), afs_printable_uint32_lu(volid)); code = unlink(path); if (code) { Log("VDestroyVolumeDiskHeader: Couldn't unlink disk header, error = %d\n", errno); diff --git a/src/volser/restorevol.c b/src/volser/restorevol.c index f8f198e..7001737 100644 --- a/src/volser/restorevol.c +++ b/src/volser/restorevol.c @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -474,16 +475,16 @@ ReadVNode(afs_int32 count) if (vnode == 1) strncpy(parentdir, rootdir, sizeof parentdir); else { - afs_snprintf(parentdir, sizeof parentdir, "%s" OS_DIRSEP "%s%d", rootdir, - ADIR, vnode); + snprintf(parentdir, sizeof parentdir, + "%s" OS_DIRSEP "%s%d", rootdir, ADIR, vnode); len = readlink(parentdir, linkname, MAXNAMELEN); if (len < 0) { /* parentdir does not exist. So create an orphan dir. * and then link the parentdir to the orphaned dir. */ - afs_snprintf(linkname, sizeof linkname, "%s" OS_DIRSEP "%s%d", - rootdir, ODIR, vnode); + snprintf(linkname, sizeof linkname, "%s" OS_DIRSEP "%s%d", + rootdir, ODIR, vnode); code = mkdir(linkname, 0777); if ((code < 0) && (errno != EEXIST)) { fprintf(stderr, @@ -492,8 +493,8 @@ ReadVNode(afs_int32 count) } /* Link the parentdir to it - now parentdir exists */ - afs_snprintf(linkname, sizeof linkname, "%s%d/", ODIR, - vnode); + snprintf(linkname, sizeof linkname, "%s%d/", ODIR, + vnode); code = symlink(linkname, parentdir); if (code) { fprintf(stderr, @@ -575,10 +576,12 @@ ReadVNode(afs_int32 count) /* dirname is the directory to create. * vflink is what will link to it. */ - afs_snprintf(dirname, sizeof dirname, "%s" OS_DIRSEP "%s", - parentdir, this_name); - afs_snprintf(vflink, sizeof vflink, "%s" OS_DIRSEP "%s%d", - rootdir, ADIR, this_vn); + snprintf(dirname, sizeof dirname, + "%s" OS_DIRSEP "%s", + parentdir, this_name); + snprintf(vflink, sizeof vflink, + "%s" OS_DIRSEP "%s%d", + rootdir, ADIR, this_vn); /* The link and directory may already exist */ len = readlink(vflink, linkname, MAXNAMELEN); @@ -597,8 +600,9 @@ ReadVNode(afs_int32 count) * It was created originally as orphaned. */ linkname[len - 1] = '\0'; /* remove '/' at end */ - afs_snprintf(lname, sizeof lname, "%s" OS_DIRSEP "%s", - rootdir, linkname); + snprintf(lname, sizeof lname, + "%s" OS_DIRSEP "%s", + rootdir, linkname); code = rename(lname, dirname); if (code) { fprintf(stderr, @@ -609,12 +613,11 @@ ReadVNode(afs_int32 count) /* Now create/update the link to the new/moved directory */ if (vn.vnode == 1) - afs_snprintf(dirname, sizeof dirname, "%s/", - this_name); + snprintf(dirname, sizeof dirname, "%s/", + this_name); else - afs_snprintf(dirname, sizeof dirname, - "%s%d/%s/", ADIR, vn.vnode, - this_name); + snprintf(dirname, sizeof dirname, "%s%d/%s/", + ADIR, vn.vnode, this_name); unlink(vflink); code = symlink(dirname, vflink); if (code) { @@ -628,11 +631,11 @@ ReadVNode(afs_int32 count) * by creating a link within the directory. Restoring * the file will later remove the link. */ - else { - /*AFILEENTRY*/ afs_snprintf(vflink, - sizeof vflink, - "%s" OS_DIRSEP "%s%d", parentdir, - AFILE, this_vn); + else { + /*AFILEENTRY*/ + snprintf(vflink, sizeof vflink, + "%s" OS_DIRSEP "%s%d", parentdir, + AFILE, this_vn); code = symlink(this_name, vflink); if ((code < 0) && (errno != EEXIST)) { @@ -660,12 +663,12 @@ ReadVNode(afs_int32 count) * then the file will be an orphaned file. */ lfile = 1; - afs_snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d", parentdir, - AFILE, vn.vnode); + snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d", + parentdir, AFILE, vn.vnode); len = readlink(filename, fname, MAXNAMELEN); if (len < 0) { - afs_snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d", - rootdir, OFILE, vn.vnode); + snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d", + rootdir, OFILE, vn.vnode); lfile = 0; /* no longer a linked file; a direct path */ } @@ -692,11 +695,10 @@ ReadVNode(afs_int32 count) errno); else { char tmp[100]; - (void)afs_snprintf(tmp, sizeof tmp, - "Read %llu bytes out of %llu", - (afs_uintmax_t) (vn.dataSize - - size), - (afs_uintmax_t) vn.dataSize); + snprintf(tmp, sizeof tmp, + "Read %llu bytes out of %llu", + (afs_uintmax_t) (vn.dataSize - size), + (afs_uintmax_t) vn.dataSize); fprintf(stderr, "%s\n", tmp); } break; @@ -726,16 +728,16 @@ ReadVNode(afs_int32 count) * of the symbolic link. If it doesn't exist, * then the link will be an orphaned link. */ - afs_snprintf(linkname, sizeof linkname, "%s" OS_DIRSEP "%s%d", parentdir, - AFILE, vn.vnode); + snprintf(linkname, sizeof linkname, "%s" OS_DIRSEP "%s%d", + parentdir, AFILE, vn.vnode); len = readlink(linkname, fname, MAXNAMELEN); if (len < 0) { - afs_snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d", - rootdir, OFILE, vn.vnode); + snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s%d", + rootdir, OFILE, vn.vnode); } else { fname[len] = '\0'; - afs_snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s", - parentdir, fname); + snprintf(filename, sizeof filename, "%s" OS_DIRSEP "%s", + parentdir, fname); } /* Read the link in, delete it, and then create it */ @@ -922,20 +924,20 @@ WorkerBee(struct cmd_syndesc *as, void *arock) dirP = opendir(rootdir); while (dirP && (dirE = readdir(dirP))) { if (strncmp(dirE->d_name, ADIR, strlen(ADIR)) == 0) { - afs_snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir, - dirE->d_name); + snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir, + dirE->d_name); dirQ = opendir(name); while (dirQ && (dirF = readdir(dirQ))) { if (strncmp(dirF->d_name, AFILE, strlen(AFILE)) == 0) { - afs_snprintf(name, sizeof name, "%s" OS_DIRSEP "%s/%s", rootdir, - dirE->d_name, dirF->d_name); + snprintf(name, sizeof name, "%s" OS_DIRSEP "%s/%s", + rootdir, dirE->d_name, dirF->d_name); unlink(name); } } closedir(dirQ); } else if (strncmp(dirE->d_name, AFILE, strlen(AFILE)) == 0) { - afs_snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir, - dirE->d_name); + snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir, + dirE->d_name); unlink(name); } } @@ -946,7 +948,8 @@ WorkerBee(struct cmd_syndesc *as, void *arock) dirP = opendir(rootdir); while (dirP && (dirE = readdir(dirP))) { if (strncmp(dirE->d_name, ADIR, strlen(ADIR)) == 0) { - afs_snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir, dirE->d_name); + snprintf(name, sizeof name, "%s" OS_DIRSEP "%s", rootdir, + dirE->d_name); unlink(name); } } diff --git a/src/volser/vol-dump.c b/src/volser/vol-dump.c index adcdc3e..680e828 100644 --- a/src/volser/vol-dump.c +++ b/src/volser/vol-dump.c @@ -21,6 +21,8 @@ # pragma GCC diagnostic warning "-Wformat" #endif +#include + #include #include #include @@ -233,7 +235,7 @@ handleit(struct cmd_syndesc *as, void *arock) exit(1); } - (void)afs_snprintf(name1, sizeof name1, VFORMAT, (unsigned long)volumeId); + snprintf(name1, sizeof name1, VFORMAT, (unsigned long)volumeId); HandleVolume(partP, name1, fileName, fromtime); return 0; } @@ -250,8 +252,8 @@ HandleVolume(struct DiskPartition64 *dp, char *name, char *filename, int fromtim afs_int32 n; - (void)afs_snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s", - VPartitionPath(dp), name); + snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s", + VPartitionPath(dp), name); if ((fd = afs_open(headerName, O_RDONLY)) == -1 || afs_fstat(fd, &status) == -1) { fprintf(stderr, "Cannot read volume header %s\n", name); diff --git a/src/volser/vol_split.c b/src/volser/vol_split.c index c34cbbe..cb3196d 100644 --- a/src/volser/vol_split.c +++ b/src/volser/vol_split.c @@ -349,9 +349,8 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, afs_uint64 size; offset = (e->vN + 1 - class) << (vcp->logSize -1); if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { - Log("Couldn't read in %s Index of volume %u at offset %" - AFS_UINT64_FMT "\n", class ? "small":"large", - V_id(vol), offset); + Log("Couldn't read in %s Index of volume %u at offset %llu\n", + class ? "small":"large", V_id(vol), offset); code = EIO; goto Bad_Copy; } @@ -381,9 +380,8 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, VNDISK_SET_INO(vnode, newino); vnode->cloned = 0; if (FDH_PWRITE(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { - Log("Couldn't write in %s Index of volume %u at offset %" - AFS_UINT64_FMT "\n", class ? "small":"large", - V_id(vol), offset); + Log("Couldn't write in %s Index of volume %u at offset %llu\n", + class ? "small":"large", V_id(vol), offset); code = EIO; goto Bad_Copy; } @@ -428,9 +426,8 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, vnode->parent = 1; /* in new root-directory */ vnode->cloned = 0; if (FDH_PWRITE(newfdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { - Log("Couldn't write in %s Index of volume %u to offset %" - AFS_UINT64_FMT "\n", class ? "small":"large", - V_id(newvol), offset); + Log("Couldn't write in %s Index of volume %u to offset %llu\n", + class ? "small":"large", V_id(newvol), offset); code = EIO; goto Bad_Copy; } @@ -455,8 +452,8 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, } offset = (where + 1 - class) << (vcp->logSize -1); if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { - Log("Couldn't read in large Index of old volume %u at offset %" - AFS_UINT64_FMT "\n", V_id(vol), offset); + Log("Couldn't read in large Index of old volume %u at offset %llu\n", + V_id(vol), offset); code = EIO; goto Bad_Copy; } @@ -667,9 +664,8 @@ deleteVnodes(Volume *vol, afs_int32 class, if (e->flag & NEEDED) { offset = (e->vN + 1 - class) << (vcp->logSize -1); if (FDH_PREAD(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { - Log("Couldn't read in %s Index of volume %u at offset %" - AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol), - offset); + Log("Couldn't read in %s Index of volume %u at offset %llu\n", + class ? "small":"large", V_id(vol), offset); code = EIO; goto Bad_Delete; } @@ -688,9 +684,8 @@ deleteVnodes(Volume *vol, afs_int32 class, memset(vnode, 0, vcp->diskSize); vnode->type = vNull; if (FDH_PWRITE(fdP, vnode, vcp->diskSize, offset) != vcp->diskSize) { - Log("Couldn't write in %s Index of volume %u to offset %" - AFS_UINT64_FMT "\n", class ? "small":"large", - V_id(vol), offset); + Log("Couldn't write in %s Index of volume %u to offset %llu\n", + class ? "small":"large", V_id(vol), offset); } } } diff --git a/src/volser/volprocs.c b/src/volser/volprocs.c index 7b9891e..012a8c3 100644 --- a/src/volser/volprocs.c +++ b/src/volser/volprocs.c @@ -197,7 +197,7 @@ ConvertVolume(afs_uint32 avol, char *aname, afs_int32 asize) if (asize < 18) return -1; /* It's better using the Generic VFORMAT since otherwise we have to make changes to too many places... The 14 char limitation in names hits us again in AIX; print in field of 9 digits (still 10 for the rest), right justified with 0 padding */ - (void)afs_snprintf(aname, asize, VFORMAT, (unsigned long)avol); + snprintf(aname, asize, VFORMAT, (unsigned long)avol); return 0; } -- 1.9.4