Prefer fputs over fprintf where possible

fprintf does extra work and meant for formatting strings.
This commit is contained in:
Rose
2023-07-18 12:10:06 -04:00
committed by Todd C. Miller
parent a4cbd7fe7b
commit e095069d2a
12 changed files with 27 additions and 29 deletions

View File

@@ -109,7 +109,7 @@ main(int argc, char *argv[])
}
while (len <= maxlen) {
if (len == 0)
printf("# word wrap disabled\n");
puts("# word wrap disabled");
else
printf("# word wrap at %zu characters\n", len);
eventlog_writeln(stdout, lines[0], strlen(lines[0]), len);

View File

@@ -940,14 +940,14 @@ qprintf(const char *str, Char *s)
(void)printf("%s:\n", str);
for (p = s; *p; p++)
(void)printf("%c", CHAR(*p));
(void)printf("\n");
(void)fputc(CHAR(*p), stdout);
(void)fputc('\n', stdout);
for (p = s; *p; p++)
(void)printf("%c", *p & M_PROTECT ? '"' : ' ');
(void)printf("\n");
(void)fputc(*p & M_PROTECT ? '"' : ' ', stdout);
(void)fputc('\n', stdout);
for (p = s; *p; p++)
(void)printf("%c", ismeta(*p) ? '_' : ' ');
(void)printf("\n");
(void)fputc(ismeta(*p) ? '_' : ' ', stdout);
(void)fputc('\n', stdout);
}
#endif /* DEBUG */
#endif /* HAVE_GLOB */

View File

@@ -38,7 +38,7 @@ main(int argc, char *argv[])
#include "mksiglist.h"
printf("const char *const sudo_sys_siglist[] = {\n");
puts("const char *const sudo_sys_siglist[] = {");
for (i = 0; i < nitems(sudo_sys_siglist); i++) {
if (sudo_sys_siglist[i] != NULL) {
printf(" \"%s\",\n", sudo_sys_siglist[i]);
@@ -46,7 +46,7 @@ main(int argc, char *argv[])
printf(" \"Signal %zu\",\n", i);
}
}
printf("};\n");
puts("};");
return EXIT_SUCCESS;
}

View File

@@ -38,7 +38,7 @@ main(int argc, char *argv[])
#include "mksigname.h"
printf("const char *const sudo_sys_signame[] = {\n");
puts("const char *const sudo_sys_signame[] = {");
for (i = 0; i < nitems(sudo_sys_signame); i++) {
if (sudo_sys_signame[i] != NULL) {
printf(" \"%s\",\n", sudo_sys_signame[i]);
@@ -46,7 +46,7 @@ main(int argc, char *argv[])
printf(" \"Signal %zu\",\n", i);
}
}
printf("};\n");
puts("};");
return EXIT_SUCCESS;
}

View File

@@ -80,8 +80,7 @@ main(int argc, char **argv)
len = strlen(buf);
if (len > 0) {
if (buf[len - 1] != '\n') {
fprintf(stderr,
"globtest: missing newline at EOF\n");
fputs("globtest: missing newline at EOF\n", stderr);
return EXIT_FAILURE;
}
buf[--len] = '\0';

View File

@@ -1861,7 +1861,7 @@ main(int argc, char *argv[])
}
if (testrun)
printf("sending logs...\n");
puts("sending logs...");
struct timespec t_start, t_end, t_result;
sudo_gettime_real(&t_start);

View File

@@ -109,7 +109,7 @@ group_plugin_load(char *plugin_info)
if (SUDO_API_VERSION_GET_MAJOR(group_plugin->version) != GROUP_API_VERSION_MAJOR) {
fprintf(stderr,
"%s: incompatible group plugin major version %u, expected %d\n",
"%s: incompatible group plugin major version %u, expected %u\n",
path, SUDO_API_VERSION_GET_MAJOR(group_plugin->version),
GROUP_API_VERSION_MAJOR);
return -1;
@@ -171,15 +171,16 @@ group_plugin_query(const char *user, const char *group,
static void
usage(void)
{
fprintf(stderr,
"usage: plugin_test [-p \"plugin.so plugin_args ...\"] user:group ...\n");
fputs("usage: plugin_test [-p \"plugin.so plugin_args ...\"] user:group ...\n",
stderr);
exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
int ch, i, found;
int ch, found;
size_t i;
char *plugin = "group_file.so";
char *user, *group;
struct passwd *pwd;

View File

@@ -474,7 +474,7 @@ create_debug_config(const char *debug_spec)
if (asprintf(&content, "Debug %s %s/debug.log %s\n",
"python_plugin.so", data.tmp_dir, debug_spec) < 0)
{
printf("Failed to allocate string\n");
puts("Failed to allocate string");
goto cleanup;
}

View File

@@ -2440,15 +2440,14 @@ main(int argc, char *argv[])
char buff[128];
time_t d;
(void)printf("Enter date, or blank line to exit.\n\t> ");
(void)fputs("Enter date, or blank line to exit.\n\t> ", stdout);
(void)fflush(stdout);
while (fgets(buff, sizeof(buff), stdin) && buff[0]) {
d = get_date(buff);
if (d == -1)
(void)printf("Bad format - couldn't convert.\n");
(void)fputs("Bad format - couldn't convert.\n\t> ", stdout);
else
(void)printf("%s", ctime(&d));
(void)printf("\t> ");
(void)printf("%s\t> ", ctime(&d));
(void)fflush(stdout);
}
return 0;

View File

@@ -906,15 +906,14 @@ main(int argc, char *argv[])
char buff[128];
time_t d;
(void)printf("Enter date, or blank line to exit.\n\t> ");
(void)fputs("Enter date, or blank line to exit.\n\t> ", stdout);
(void)fflush(stdout);
while (fgets(buff, sizeof(buff), stdin) && buff[0]) {
d = get_date(buff);
if (d == -1)
(void)printf("Bad format - couldn't convert.\n");
(void)fputs("Bad format - couldn't convert.\n\t> ", stdout);
else
(void)printf("%s", ctime(&d));
(void)printf("\t> ");
(void)printf("%s\t> ", ctime(&d));
(void)fflush(stdout);
}
return 0;

View File

@@ -682,7 +682,7 @@ setup_terminal(struct eventlog *evlog, bool interactive, bool resize)
}
if (evlog->lines > terminal_lines || evlog->columns > terminal_cols) {
fputs(_("Warning: your terminal is too small to properly replay the log.\n"), stdout);
puts(_("Warning: your terminal is too small to properly replay the log."));
printf(_("Log geometry is %d x %d, your terminal's geometry is %d x %d."), evlog->lines, evlog->columns, terminal_lines, terminal_cols);
}
debug_return;

View File

@@ -297,7 +297,7 @@ dump_entry(struct timestamp_entry *entry, off_t pos)
} else if (entry->type == TS_PPID) {
printf("parent pid: %d\n", (int)entry->u.ppid);
}
printf("\n");
fputc('\n', stdout);
debug_return;
}