Skip to content

Commit

Permalink
printf -> fmt::print in files inc warm_storage/integration/ws_client/…
Browse files Browse the repository at this point in the history
…tests/CppClientTests.cpp

Summary:
One of our [C++ 2024 Modern Code Better Engineering Goals](https://fb.workplace.com/groups/fbcode.fyi/posts/6837863056249437) is to reduce or eliminate the use of printf in our codebase, replacing it with safer and more performant alternatives.

This diff replaces `printf` with its preferred alternative: `fmt::print`.

This diff was auto-generated by fbcode/scripts/rbarnes/printf_upgrader.py, please reach out to r-barnes if you see problems.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

(11 file modified.)

Reviewed By: bcardosolopes

Differential Revision: D51486601

fbshipit-source-id: 5825c141956e17f40183f08f833cdd73352e617e
  • Loading branch information
r-barnes authored and facebook-github-bot committed Nov 30, 2023
1 parent 242d8b4 commit 8dd1898
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion watchman/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "watchman/Options.h"
#include <fmt/core.h>
#include <string.h>
#include "watchman/CommandRegistry.h"
#include "watchman/LogConfig.h"
Expand Down Expand Up @@ -446,7 +447,7 @@ std::vector<std::string> parseOptions(int* argcp, char*** argvp) {
usage(opts, stdout);
}
if (flags.show_version) {
printf("%s\n", PACKAGE_VERSION);
fmt::print("{}\n", PACKAGE_VERSION);
exit(0);
}
return daemon_argv;
Expand Down
2 changes: 1 addition & 1 deletion watchman/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ static bool try_client_mode_command(const Command& command, bool pretty) {
client->responses.front(),
stdout,
pretty ? JSON_INDENT(4) : JSON_COMPACT);
printf("\n");
fmt::print("\n");
}

return res;
Expand Down
13 changes: 7 additions & 6 deletions watchman/test/BserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "watchman/bser.h"
#include <fmt/core.h>
#include <folly/ScopeGuard.h>
#include <folly/logging/xlog.h>
#include <folly/portability/GTest.h>
Expand Down Expand Up @@ -46,19 +47,19 @@ void hexdump(const char* start, const char* end) {
if (limit > maxbytes) {
limit = maxbytes;
}
printf("# ");
fmt::print("# ");
for (i = 0; i < limit; i++) {
printf("%02x", (int)(uint8_t)start[i]);
fmt::print("{:02x}", (int)(uint8_t)start[i]);
}
while (i <= maxbytes) {
printf(" ");
fmt::print(" ");
i++;
}
printf(" ");
fmt::print(" ");
for (i = 0; i < limit; i++) {
printf("%c", isprint((uint8_t)start[i]) ? start[i] : '.');
fmt::print("{}", isprint((uint8_t)start[i]) ? start[i] : '.');
}
printf("\n");
fmt::print("\n");
start += limit;
}
}
Expand Down
14 changes: 8 additions & 6 deletions watchman/winbuild/susres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <errno.h>
#include <fmt/core.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
Expand Down Expand Up @@ -37,24 +38,25 @@ int apply(DWORD pid, BOOL suspend) {
func = (sus_res_func)GetProcAddress(GetModuleHandle("ntdll"), name);

if (!func) {
printf(
"Failed to GetProcAddress(%s): %s\n",
fmt::print(
"Failed to GetProcAddress({}): {}\n",
name,
win32_strerror(GetLastError()));
return 1;
}

proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (proc == INVALID_HANDLE_VALUE) {
printf(
"Failed to OpenProcess(%d): %s\n", pid, win32_strerror(GetLastError()));
fmt::print(
"Failed to OpenProcess({}): {}\n", pid, win32_strerror(GetLastError()));
return 1;
}

res = func(proc);

if (res) {
printf("%s(%d) returns %x: %s\n", name, pid, res, win32_strerror(res));
fmt::print(
"{}({}) returns {:x}: {}\n", name, pid, res, win32_strerror(res));
}

CloseHandle(proc);
Expand All @@ -63,7 +65,7 @@ int apply(DWORD pid, BOOL suspend) {
}

void usage() {
printf(
fmt::print(
"Usage: susres suspend [pid]\n"
" susres resume [pid\n");
exit(1);
Expand Down

0 comments on commit 8dd1898

Please sign in to comment.