summaryrefslogtreecommitdiff
path: root/pages.c
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2020-01-02 13:31:33 +1030
committerDaniel Jones <admin@danieljon.es>2020-01-02 13:31:33 +1030
commitcceda0abba23c83811be34362c38c15427b1356a (patch)
tree9cee702bb0ca8dce55d0daf66bf1c44597e00589 /pages.c
parent237fdfd41af9c0e02652663e5e2fdc5608586ee8 (diff)
downloadwebsitegenerator-cceda0abba23c83811be34362c38c15427b1356a.tar.gz
websitegenerator-cceda0abba23c83811be34362c38c15427b1356a.zip
replaced strcat()'s with snprintf()
Diffstat (limited to 'pages.c')
-rw-r--r--pages.c29
1 files changed, 6 insertions, 23 deletions
diff --git a/pages.c b/pages.c
index 56ff50c..ae845e3 100644
--- a/pages.c
+++ b/pages.c
@@ -56,10 +56,7 @@ createfile(const char *file)
fprintf(stderr, "OK\n");
}
char filename[512] = {0};
- size_t length = 512;
- strncat(filename, output_dir, length-1);
- length = length - strlen(output_dir);
- strncat(filename, file, length-1);
+ snprintf(filename, 512, "%s%s", output_dir, file);
FILE *out = fopen(filename, "w");
if (!out)
@@ -105,10 +102,7 @@ findstring(const char *file, const char *str)
long offset = -1;
char filename[512] = {0};
- size_t length = 512;
- strncat(filename, output_dir, length-1);
- length = length - strlen(output_dir);
- strncat(filename, file, length-1);
+ snprintf(filename, 512, "%s%s", output_dir, file);
FILE *in = fopen(filename, "r");
if (!in)
@@ -163,10 +157,7 @@ deletebytes(const char *file, long offset, size_t bytes)
*/
char filename[512] = {0};
- size_t length = 512;
- strncat(filename, output_dir, length-1);
- length = length - strlen(output_dir);
- strncat(filename, file, length-1);
+ snprintf(filename, 512, "%s%s", output_dir, file);
FILE *in = fopen(filename, "r");
if (!in)
@@ -229,10 +220,7 @@ writeatbyte(const char *dest, struct fileorstring *source, long offset)
* return 1 on success. 0 on failure
*/
char filename[512] = {0};
- size_t length = 512;
- strncat(filename, output_dir, length-1);
- length = length - strlen(output_dir);
- strncat(filename, dest, length-1);
+ snprintf(filename, 512, "%s%s", output_dir, dest);
FILE *in = fopen(filename, "r");
if (!in)
@@ -480,16 +468,11 @@ createdirectpages(int *posts, size_t totalposts)
{
memset(source, 0, 1);
memset(file, 0, 1);
- memset(buff, 0, 1);
/* output file */
- strcat(file, direct_output_dir);
- sprintf(buff, "%d.html", posts[x]);
- strcat(file, buff);
+ snprintf(file, 512, "%s%d.html", direct_output_dir, posts[x]);
/* source file */
- strcat(source, posts_content);
- sprintf(buff, "%d.txt", posts[x]);
- strcat(source, buff);
+ snprintf(source, 512, "%s%d.txt", posts_content, posts[x]);
if (!createfile(file))
{