diff mbox

opensm - address windows env issues

Message ID 4A4BD5F425D5495387BA92964E2873C8@amr.corp.intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Smith, Stan May 25, 2010, 4:03 p.m. UTC
None
diff mbox

Patch

--- a/opensm/osm_log.c	2010-05-22 05:49:24.000000000 -0700
+++ b/opensm/osm_log.c	2010-05-24 11:40:07.823895800 -0700
@@ -96,8 +96,14 @@ 
 
 static void truncate_log_file(osm_log_t * p_log)
 {
-	fprintf(stderr,
-		"truncate_log_file: cannot truncate on windows system (yet)\n");
+	int fd = _fileno(p_log->out_port);
+	HANDLE hFile = (HANDLE) _get_osfhandle(fd);
+
+	if (_lseek(fd, 0, SEEK_SET) < 0)
+		fprintf(stderr, "truncate_log_file: cannot rewind: %s\n",
+			strerror(errno));
+	SetEndOfFile(hFile);
+	p_log->count = 0;
 }
 #endif				/* ndef __WIN__ */
 
@@ -123,12 +129,21 @@ 
 		return;
 
 	va_start(args, p_str);
+#ifndef __WIN__
 	if (p_log->log_prefix == NULL)
 		vsprintf(buffer, p_str, args);
 	else {
 		int n = snprintf(buffer, sizeof(buffer), "%s: ", p_log->log_prefix);
 		vsprintf(buffer + n, p_str, args);
 	}
+#else
+	if (p_log->log_prefix == NULL)
+		_vsnprintf(buffer, 1024, (LPSTR)p_str, args);
+	else {
+		int n = snprintf(buffer, sizeof(buffer), "%s: ", p_log->log_prefix);
+		_vsnprintf(buffer + n, (1024 - n), (LPSTR)p_str, args);
+	}
+#endif
 	va_end(args);
 
 	/* this is a call to the syslog */