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

Conversation

sjmulder
Copy link
Collaborator

This improves compatibility with legacy platforms that don't provide the function, in particular, Illumos.

(Alternative to #1911)

This improves compatibility with legacy platforms that don't provide the
function, in particular, Illumos.
src/nnn.c Show resolved Hide resolved
src/nnn.c Show resolved Hide resolved
@@ -2843,7 +2843,8 @@ static void write_lastdir(const char *curpath, const char *outfile)
: 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

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().

@@ -8716,7 +8717,7 @@ int main(int argc, char *argv[])
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().

@jarun
Copy link
Owner

jarun commented Aug 11, 2024

Any update here?

@jarun
Copy link
Owner

jarun commented Aug 11, 2024

Merging. I'll take care of the rest.

@jarun jarun merged commit 7fcb3bf into jarun:master Aug 11, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants