Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace use of dprintf() with fprintf() or write() #1912

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@

static void msg(const char *message)
{
dprintf(STDERR_FILENO, "%s\n", message);
fprintf(stderr, "%s\n", message);
}

#ifdef KEY_RESIZE
Expand Down Expand Up @@ -2843,7 +2843,8 @@
: cfgpath, O_CREAT | O_WRONLY | O_TRUNC, S_IWUSR | S_IRUSR);

if (fd != -1 && shell_escape(g_buf, sizeof(g_buf), curpath)) {
dprintf(fd, "cd %s", g_buf);
write(fd, "cd ", 3);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the return value of write. CI fails with the following:

########## gcc-9 ##########
gcc-9  -Werror -std=c11 -Wall -Wextra -Wshadow -O3 -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600  -o nnn  src/nnn.c -lreadline -lncursesw -ltinfo -lpthread
src/nnn.c: In function 'write_lastdir':
src/nnn.c:2846:3: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result]
 2846 |   write(fd, "cd ", 3);
      |   ^~~~~~~~~~~~~~~~~~~
src/nnn.c:2847:3: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result]
 2847 |   write(fd, g_buf, strlen(g_buf));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:224: nnn] Error 1

Exited with code exit status 2

write(fd, g_buf, strlen(g_buf));
jarun marked this conversation as resolved.
Show resolved Hide resolved
close(fd);
}
}
Expand Down Expand Up @@ -8357,15 +8358,15 @@
key = bindings[i].sym;

if (bitmap[key])
dprintf(STDERR_FILENO, "key collision! [%s]\n", keyname(key));
fprintf(stderr, "key collision! [%s]\n", keyname(key));
else
bitmap[key] = TRUE;
}
}

static void usage(void)
{
dprintf(STDOUT_FILENO,
printf(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use fprintf().

"%s: nnn [OPTIONS] [PATH]\n\n"
"The unorthodox terminal file manager.\n\n"
"positional args:\n"
Expand Down Expand Up @@ -8716,7 +8717,7 @@
g_state.uidgid = 1;
break;
case 'V':
dprintf(STDOUT_FILENO, "%s\n", VERSION);
printf("%s\n", VERSION);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use fprintf().

return EXIT_SUCCESS;
case 'x':
cfg.x11 = 1;
Expand Down
Loading