[netperf-dev] netperf4 commit notice r66 - trunk/src
raj at netperf.org
raj at netperf.org
Mon Feb 27 13:11:22 PST 2006
Author: raj
Date: 2006-02-27 13:11:21 -0800 (Mon, 27 Feb 2006)
New Revision: 66
Modified:
trunk/src/netlib.c
Log:
Provide a netperf_complete_filename routine in netlib for suites to use
to find things like their fill files. If the base name does not stat
we try prepending NETPERFDIR to it.
Modified: trunk/src/netlib.c
===================================================================
--- trunk/src/netlib.c 2006-02-24 15:56:53 UTC (rev 65)
+++ trunk/src/netlib.c 2006-02-27 21:11:21 UTC (rev 66)
@@ -40,6 +40,10 @@
#include <sys/types.h>
#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
@@ -120,6 +124,42 @@
#include "nettest_bsd.h"
+/* given a filename, return the first path to the file that stats
+ successfully - which is either the name already given, or that name
+ with NETPERFDIR prepended. */
+
+int
+netperf_complete_filename(char *name, char *full, int fulllen) {
+ char path[PATH_MAX+1];
+ int ret;
+
+ struct stat buf;
+
+ if (0 == stat(name,&buf)) {
+ /* the name resolved where we are - either there is a match in
+ CWD, or they specified a full path name, I wonder if we need to
+ worry about explicit null termination of full? raj 2006-02-27 */
+ strncpy(full,name,fulllen);
+ ret = 0;
+ }
+ else {
+ /* very simple, even simplistic - since the stat above didn't
+ work, we presume that the name given wasn't a full one, so we
+ just slap the NETPERFDIR and path separator in front of the
+ name and try again. */
+ snprintf(path,PATH_MAX,"%s%s%s",NETPERFDIR,NETPERF_PATH_SEP,name);
+ path[PATH_MAX] = '\0';
+ if (0 == stat(path,&buf)) {
+ strncpy(full,path,fulllen);
+ ret = 0;
+ }
+ else {
+ ret = -1;
+ }
+ }
+ return ret;
+}
+
#ifdef HAVE_GETHRTIME
void
More information about the netperf-dev
mailing list