diff options
author | Shauren <shauren.trinity@gmail.com> | 2016-03-21 17:25:34 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2016-03-21 17:26:48 +0100 |
commit | 9295d9fa09b82b67af558aa838ef78561dbc0e79 (patch) | |
tree | 006617b5cd3f00761a36686daf79035e5509e8dc | |
parent | b327dc3d4ab8f5d4732946eaecad9f8560d61bff (diff) |
Core/Util: Extracted GetPID to separate function
(cherry picked from commit e3af42e05cdf9e4c959d4e038349008da4faca27)
-rw-r--r-- | src/common/Utilities/Util.cpp | 19 | ||||
-rw-r--r-- | src/common/Utilities/Util.h | 3 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index ddc07505942..6572280d00b 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -218,22 +218,29 @@ bool IsIPAddress(char const* ipaddress) } /// create PID file -uint32 CreatePIDFile(const std::string& filename) +uint32 CreatePIDFile(std::string const& filename) { - FILE* pid_file = fopen (filename.c_str(), "w" ); + FILE* pid_file = fopen(filename.c_str(), "w"); if (pid_file == NULL) return 0; + uint32 pid = GetPID(); + + fprintf(pid_file, "%u", pid); + fclose(pid_file); + + return pid; +} + +uint32 GetPID() +{ #ifdef _WIN32 DWORD pid = GetCurrentProcessId(); #else pid_t pid = getpid(); #endif - fprintf(pid_file, "%u", pid ); - fclose(pid_file); - - return (uint32)pid; + return uint32(pid); } size_t utf8length(std::string& utf8str) diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index a3e3f21466e..25fce88954d 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -314,7 +314,8 @@ bool Utf8ToUpperOnlyLatin(std::string& utf8String); bool IsIPAddress(char const* ipaddress); -uint32 CreatePIDFile(const std::string& filename); +uint32 CreatePIDFile(std::string const& filename); +uint32 GetPID(); std::string ByteArrayToHexStr(uint8 const* bytes, uint32 length, bool reverse = false); |