From patchwork Tue May 25 16:03:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Smith, Stan" X-Patchwork-Id: 102243 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4PGxZW0009172 for ; Tue, 25 May 2010 16:59:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932619Ab0EYQ7d (ORCPT ); Tue, 25 May 2010 12:59:33 -0400 Received: from mga01.intel.com ([192.55.52.88]:41826 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932294Ab0EYQ7c (ORCPT ); Tue, 25 May 2010 12:59:32 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 25 May 2010 08:59:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.53,299,1272870000"; d="scan'208";a="570380290" Received: from unknown (HELO scsmithMOBL1) ([10.254.76.100]) by fmsmga002.fm.intel.com with ESMTP; 25 May 2010 09:02:16 -0700 From: "Stan C. Smith" To: "'Sasha Khapyorsky'" Cc: Subject: [PATCH] opensm - address windows env issues Date: Tue, 25 May 2010 09:03:16 -0700 Message-ID: <4A4BD5F425D5495387BA92964E2873C8@amr.corp.intel.com> MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 11 Thread-Index: Acr8I8li5cU62EHWRgSLcbffEZVS6A== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 25 May 2010 16:59:35 +0000 (UTC) --- 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 */