From: Davin McCall Date: Thu, 11 Jan 2018 18:09:32 +0000 (+0000) Subject: Move separate_args function from header to source file. X-Git-Tag: v0.08~56 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d3c994e4d2d82d72c6725e3a39b48430fb8f3952;p=oweals%2Fdinit.git Move separate_args function from header to source file. This avoids potential ODR violations. The function isn't worth making inline, it's large enough and not on a critical path so just compile it once. --- diff --git a/src/proc-service.cc b/src/proc-service.cc index 0aeb9e3..c0efb52 100644 --- a/src/proc-service.cc +++ b/src/proc-service.cc @@ -11,6 +11,30 @@ using clock_type = dasynq::clock_type; using rearm = dasynq::rearm; using time_val = dasynq::time_val; +// Given a string and a list of pairs of (start,end) indices for each argument in that string, +// store a null terminator for the argument. Return a `char *` vector containing the beginning +// of each argument and a trailing nullptr. (The returned array is invalidated if the string is later modified). +std::vector separate_args(std::string &s, std::list> &arg_indices) +{ + std::vector r; + r.reserve(arg_indices.size() + 1); + + // First store nul terminator for each part: + for (auto index_pair : arg_indices) { + if (index_pair.second < s.length()) { + s[index_pair.second] = 0; + } + } + + // Now we can get the C string (c_str) and store offsets into it: + const char * cstr = s.c_str(); + for (auto index_pair : arg_indices) { + r.push_back(cstr + index_pair.first); + } + r.push_back(nullptr); + return r; +} + rearm exec_status_pipe_watcher::fd_event(eventloop_t &loop, int fd, int flags) noexcept { base_process_service *sr = service; diff --git a/src/proc-service.h b/src/proc-service.h index edba90e..c23b997 100644 --- a/src/proc-service.h +++ b/src/proc-service.h @@ -3,26 +3,7 @@ // Given a string and a list of pairs of (start,end) indices for each argument in that string, // store a null terminator for the argument. Return a `char *` vector containing the beginning // of each argument and a trailing nullptr. (The returned array is invalidated if the string is later modified). -static std::vector separate_args(std::string &s, std::list> &arg_indices) -{ - std::vector r; - r.reserve(arg_indices.size() + 1); - - // First store nul terminator for each part: - for (auto index_pair : arg_indices) { - if (index_pair.second < s.length()) { - s[index_pair.second] = 0; - } - } - - // Now we can get the C string (c_str) and store offsets into it: - const char * cstr = s.c_str(); - for (auto index_pair : arg_indices) { - r.push_back(cstr + index_pair.first); - } - r.push_back(nullptr); - return r; -} +std::vector separate_args(std::string &s, std::list> &arg_indices); class base_process_service;