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) {
229230static 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
342343static 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
348347static 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
459458static 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-
486479static int
487480get_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