Skip to content

Commit 292d8dc

Browse files
committed
Cleanup: use fmt::format where possible
1 parent b78e5c9 commit 292d8dc

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

src/rtapi/Submakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $(call TOOBJSDEPS, $(RTAPI_APP_SRCS)): EXTRAFLAGS += -DSIM \
4444
-UULAPI -DRTAPI -pthread
4545
../bin/rtapi_app: $(call TOOBJS, $(RTAPI_APP_SRCS))
4646
$(ECHO) Linking $(notdir $@)
47-
$(Q)$(CXX) -rdynamic -o $@ $^ $(LIBDL) -pthread -lrt $(LIBUDEV_LIBS) -ldl $(LDFLAGS)
47+
$(Q)$(CXX) -rdynamic -o $@ $^ $(LIBDL) -pthread -lrt -lfmt $(LIBUDEV_LIBS) -ldl $(LDFLAGS)
4848
TARGETS += ../bin/rtapi_app
4949
endif
5050

src/rtapi/uspace_rtapi_main.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <pthread_np.h>
5252
#endif
5353

54+
#include <fmt/format.h>
5455
#include <boost/lockfree/queue.hpp>
5556

5657
#include "rtapi.h"
@@ -229,9 +230,9 @@ static int do_comp_args(void *module, std::vector<std::string> args) {
229230
static int do_load_cmd(const std::string& name, const std::vector<std::string>& args) {
230231
void *w = modules[name];
231232
if(w == NULL) {
232-
char what[LINELEN+1];
233-
snprintf(what, LINELEN, "%s/%s.so", EMC2_RTLIB_DIR, name.c_str());
234-
void *module = modules[name] = dlopen(what, RTLD_GLOBAL | RTLD_NOW);
233+
std::string what;
234+
what=fmt::format("{}/{}.so", EMC2_RTLIB_DIR, name);
235+
void *module = modules[name] = dlopen(what.c_str(), RTLD_GLOBAL | RTLD_NOW);
235236
if(!module) {
236237
rtapi_print_msg(RTAPI_MSG_ERR, "%s: dlopen: %s\n", name.c_str(), dlerror());
237238
modules.erase(name);
@@ -340,9 +341,7 @@ static std::vector<std::string> read_strings(int fd) {
340341
}
341342

342343
static void write_number(std::string &buf, int num) {
343-
char numbuf[10];
344-
snprintf(numbuf, sizeof(numbuf), "%d ", num);
345-
buf = buf + numbuf;
344+
buf = buf + fmt::format("{} ", num);
346345
}
347346

348347
static void write_string(std::string &buf, const std::string& s) {
@@ -457,7 +456,7 @@ static int master(int fd, const std::vector<std::string>& args) {
457456
}
458457

459458
static std::string
460-
_get_fifo_path() {
459+
get_fifo_path() {
461460
std::string s;
462461
if(getenv("RTAPI_FIFO_PATH"))
463462
s = getenv("RTAPI_FIFO_PATH");
@@ -466,29 +465,23 @@ _get_fifo_path() {
466465
else {
467466
rtapi_print_msg(RTAPI_MSG_ERR,
468467
"rtapi_app: RTAPI_FIFO_PATH and HOME are unset. rtapi fifo creation is unsafe.");
469-
return NULL;
468+
return std::string();
470469
}
471470
if(s.size() + 1 > sizeof(sockaddr_un::sun_path)) {
472471
rtapi_print_msg(RTAPI_MSG_ERR,
473472
"rtapi_app: rtapi fifo path is too long (arch limit %zd): %s",
474473
sizeof(sockaddr_un::sun_path), s.c_str());
475-
return NULL;
474+
return std::string();
476475
}
477476
return s;
478477
}
479478

480-
static const char *
481-
get_fifo_path() {
482-
static std::string path = _get_fifo_path();
483-
return path.c_str();
484-
}
485-
486479
static int
487480
get_fifo_path(char *buf, size_t bufsize) {
488481
int len;
489-
const char *s = get_fifo_path();
490-
if(!s) return -1;
491-
len=snprintf(buf+1, bufsize-1, "%s", s);
482+
const std::string s = get_fifo_path();
483+
if(s.empty()) return -1;
484+
len=snprintf(buf+1, bufsize-1, "%s", s.c_str());
492485
return len;
493486
}
494487

0 commit comments

Comments
 (0)