commit f127c2f4a33c3cbdf1791b1f14cbc0314762271c
parent d0235849a0e7d158e3dda34323858ae2cc6a8803
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Thu, 29 Jul 2021 20:29:10 +0000
more of mdprint
Diffstat:
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/extra/mdprint.c b/extra/mdprint.c
@@ -7,12 +7,10 @@ newobj(void)
{
char *buf;
int fd;
- long n;
fd = open("/mnt/richterm/new", OREAD);
if (fd < 0) sysfatal("%r");
buf = mallocz(256, 1);
- n = read(fd, buf, 256);
- buf[n-1] = '\0';
+ read(fd, buf, 256);
close(fd);
return buf;
}
@@ -21,13 +19,13 @@ void
main(int argc, char **argv)
{
int fd;
+ long n;
Biobuf *bp;
char *lp;
if (argc > 1) {
if ((fd = open(argv[1], OREAD)) < 0)
sysfatal("can't open %s, %r", argv[1]);
} else fd = 0;
- print("---\n");
bp = Bfdopen(fd, OREAD);
while ((lp = Brdstr(bp, '\n', 0)) != nil) {
char *id;
@@ -35,11 +33,13 @@ main(int argc, char **argv)
int td;
id = newobj();
path = smprint("/mnt/richterm/%s/text", id);
- print("%s\n", path);
- //td = open(path, OWRITE);
- //if (td < 0) sysfatal("%r");
- //write(td, lp, strlen(lp));
- //close(td);
+ print("%s ", id);
+ td = open(path, OWRITE);
+ if (td < 0) sysfatal("%r");
+ n = write(td, lp, strlen(lp));
+ if (n != strlen(lp))
+ sysfatal("write failed, %ld/%ld", n, strlen(lp));
+ close(td);
free(lp);
free(id);
free(path);