diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-03-27 22:36:22 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-03-27 22:36:22 -0400 |
commit | 21ad08b05f88f9282cd03278968b1bafef0bef39 (patch) | |
tree | 4cf6fc1f2b9510b58bda8bff8a703909e65fa151 /menudriver.c | |
parent | 9755a239808a1ae095d9a94773456a1581eb792d (diff) |
replace series of strcpy()/strcat() with snprintf()
Diffstat (limited to 'menudriver.c')
-rw-r--r-- | menudriver.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/menudriver.c b/menudriver.c index 989a06a..9b2b07b 100644 --- a/menudriver.c +++ b/menudriver.c @@ -51,7 +51,7 @@ void singleton(char *); int subdir(void); char next[40] = "", cmd[80], last[40] = "."; -int val, ok = 0; +int val; #include <string.h> #define index(s,c) strchr(s,c) @@ -133,9 +133,7 @@ void menudrive(char *dir) bad = 0; } - strcpy(cmd, menuviewer); - strcat(cmd, " "); - strcat(cmd, "contents"); + snprintf(cmd, sizeof(cmd), "%s contents", menuviewer); system(cmd); printf("::please type selection number (or return to exit):"); @@ -199,7 +197,8 @@ void menudrive(char *dir) strcpy(last, next), pushlast(), next[0] = '\0'; } - } else if (S_ISREG(st.st_mode)) { /* regular file */ + } else if (S_ISREG(st.st_mode)) { + /* regular file */ clrscr(); #ifndef UWIN @@ -208,23 +207,21 @@ void menudrive(char *dir) if (strcmp(next, "99") == 0) #endif { - strcpy(cmd, "./"); - strcat(cmd, next); + snprintf(cmd, sizeof(cmd), "./%s", next); system(cmd); if (fastback) { wait_for_return(); } } else { - strcpy(cmd, viewer); - strcat(cmd, " "); - strcat(cmd, next); + snprintf(cmd, sizeof(cmd), "%s %s", viewer, next); system(cmd); } if (fastback) { strcpy(last, next); next[0] = '\0'; + } else { printf("::next selection (or return to go back to menu, or q to quit):"); /* read remainder of line into next, less leading white space */ @@ -311,16 +308,13 @@ void singleton(char *fil) #ifndef UWIN if (st.st_mode & S_IXUSR) { /* executable (by owner) */ - strcpy(cmd, "./"); - strcat(cmd, fil); + snprintf(cmd, sizeof(cmd), "./%s", fil); system(cmd); fastback = 0; } else #endif { - strcpy(cmd, viewer); - strcat(cmd, " "); - strcat(cmd, fil); + snprintf(cmd, sizeof(cmd), "%s %s", viewer, fil); system(cmd); } @@ -414,7 +408,9 @@ void pushlast(void) } /* suppressed 'cos interferes with special case in lastval() */ - strcpy(lastp, last), lastp += n + 1, strcpy(last, "."); + strcpy(lastp, last); + lastp += n + 1; + strcpy(last, "."); } void poplast(void) |