Introduction
Introduction Statistics Contact Development Disclaimer Help
sfeed_gopher: remove PATH_MAX and restricting the path length - sfeed - RSS and…
git clone git://git.codemadness.org/sfeed
Log
Files
Refs
README
LICENSE
---
commit f83f6cd4dc21664721602ceb449631957e941215
parent e77a675e83ccbea65a50fe85dc9cb49fff5e0443
Author: Hiltjo Posthuma <[email protected]>
Date: Fri, 3 Feb 2023 16:12:30 +0100
sfeed_gopher: remove PATH_MAX and restricting the path length
This make it also cleanly compile without any other changes on GNU/Hurd.
Reference: https://www.gnu.org/software/hurd/hurd/porting/guidelines.html
Section: "PATH_MAX, MAX_PATH, MAXPATHLEN, _POSIX_PATH_MAX"
The fopen() functions will return NULL when the path is too long and set
errno = ENAMETOOLONG.
"The length of a pathname exceeds {PATH_MAX}, or pathname resolution of a
symbolic link produced an intermediate result with a length that exceeds
{PATH_MAX}."
Reference: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html
Diffstat:
M sfeed_gopher.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
---
diff --git a/sfeed_gopher.c b/sfeed_gopher.c
@@ -1,6 +1,5 @@
#include <sys/types.h>
-#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -123,8 +122,8 @@ int
main(int argc, char *argv[])
{
FILE *fpitems, *fpindex, *fp;
- char *name, *p, path[PATH_MAX + 1];
- int i, r;
+ char *name, *p;
+ int i;
if (argc == 1) {
if (pledge("stdio", NULL) == -1)
@@ -168,15 +167,11 @@ main(int argc, char *argv[])
if (!(fp = fopen(argv[i], "r")))
err(1, "fopen: %s", argv[i]);
-
- r = snprintf(path, sizeof(path), "%s", name);
- if (r < 0 || (size_t)r >= sizeof(path))
- errx(1, "path truncation: %s", path);
- if (!(fpitems = fopen(path, "wb")))
+ if (!(fpitems = fopen(name, "wb")))
err(1, "fopen");
printfeed(fpitems, fp, &f);
checkfileerror(fp, argv[i], 'r');
- checkfileerror(fpitems, path, 'w');
+ checkfileerror(fpitems, name, 'w');
fclose(fp);
fclose(fpitems);
@@ -185,7 +180,7 @@ main(int argc, char *argv[])
gophertext(fpindex, name);
fprintf(fpindex, " (%lu/%lu)\t", f.totalnew, f.total);
gophertext(fpindex, prefixpath);
- gophertext(fpindex, path);
+ gophertext(fpindex, name);
fprintf(fpindex, "\t%s\t%s\r\n", host, port);
}
fputs(".\r\n", fpindex);
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.