/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2005-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file SysUtils.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @date Tue, 29.05.200517///18// A few system-specific functions19/****************************************************************************/20#include <config.h>2122#include <stdlib.h>23#include <sys/types.h>24#include <sys/stat.h>25#include "StringUtils.h"26#include "SysUtils.h"2728#ifndef WIN3229#include <sys/time.h>30#include <unistd.h>31#else32#define NOMINMAX33#include <windows.h>34#undef NOMINMAX35#define stat _stat36#endif3738// ===========================================================================39// member method definitions40// ===========================================================================4142long43SysUtils::getCurrentMillis() {44#ifndef WIN3245timeval current;46gettimeofday(¤t, 0);47long nanosecs =48(long) current.tv_sec * 1000L + (long) current.tv_usec / 1000L;49return nanosecs;50#else51LARGE_INTEGER val, val2;52BOOL check = QueryPerformanceCounter(&val);53check = QueryPerformanceFrequency(&val2);54return (long)(val.QuadPart * 1000 / val2.QuadPart);55#endif56}575859#ifdef WIN3260long61SysUtils::getWindowsTicks() {62return (long) GetTickCount();63}64#endif656667unsigned long68SysUtils::runHiddenCommand(const std::string& cmd) {69#ifdef WIN3270// code inspired by http://www.codeproject.com/Articles/2537/Running-console-applications-silently71STARTUPINFO StartupInfo;72PROCESS_INFORMATION ProcessInfo;73unsigned long rc;7475memset(&StartupInfo, 0, sizeof(StartupInfo));76StartupInfo.cb = sizeof(STARTUPINFO);77StartupInfo.dwFlags = STARTF_USESHOWWINDOW;78StartupInfo.wShowWindow = SW_HIDE;7980// "/c" option - Do the command then terminate the command window81std::string winCmd = "CMD.exe /c " + StringUtils::transcodeToLocal(cmd);82char* args = new char[winCmd.size() + 1];83args[0] = 0;84strcpy(args, winCmd.c_str());85if (!CreateProcess(nullptr, args, nullptr, nullptr, FALSE,86CREATE_NEW_CONSOLE, nullptr, nullptr, &StartupInfo, &ProcessInfo)) {87delete[] args;88return (unsigned long)GetLastError();89}9091WaitForSingleObject(ProcessInfo.hProcess, INFINITE);92if (!GetExitCodeProcess(ProcessInfo.hProcess, &rc)) {93rc = 0;94}9596CloseHandle(ProcessInfo.hThread);97CloseHandle(ProcessInfo.hProcess);9899delete[] args;100return rc;101#else102return (unsigned long)system(cmd.c_str());103#endif104}105106107long long108SysUtils::getModifiedTime(const std::string& fname) {109struct stat result;110if (stat(fname.c_str(), &result) == 0) {111return result.st_mtime;112}113return -1;114}115116117/****************************************************************************/118119120