Mercurial > hg > mlmmj
comparison src/mygetline.c @ 754:ecb991e41a4c
Add $controlN$ substitution
The interfaces to substitute() and substitute_one() have changed, as they
now need to know the listdir to be able to find control files
author | Ben Schmidt |
---|---|
date | Wed, 06 Oct 2010 23:30:26 +1100 |
parents | 136e5bc27f7a |
children | 5bab557020a6 |
comparison
equal
deleted
inserted
replaced
753:b58fd7980358 | 754:ecb991e41a4c |
---|---|
28 #include <errno.h> | 28 #include <errno.h> |
29 | 29 |
30 #include "mygetline.h" | 30 #include "mygetline.h" |
31 #include "memory.h" | 31 #include "memory.h" |
32 | 32 |
33 char *mygetline(int fd) | 33 static char *mygetuntil(int fd, char eof) |
34 { | 34 { |
35 size_t i = 0, res, buf_size = BUFSIZE; /* initial buffer size */ | 35 size_t i = 0, res, buf_size = BUFSIZE; /* initial buffer size */ |
36 char *buf, ch; | 36 char *buf, ch; |
37 | 37 |
38 buf = mymalloc(buf_size); | 38 buf = mymalloc(buf_size); |
60 if(i == buf_size - 1) { | 60 if(i == buf_size - 1) { |
61 buf_size *= 2; | 61 buf_size *= 2; |
62 buf = myrealloc(buf, buf_size); | 62 buf = myrealloc(buf, buf_size); |
63 } | 63 } |
64 buf[i++] = ch; | 64 buf[i++] = ch; |
65 if(ch == '\n') { | 65 if(ch == eof) { |
66 buf[i] = '\0'; | 66 buf[i] = '\0'; |
67 return buf; | 67 return buf; |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | |
72 char *mygetline(int fd) | |
73 { | |
74 return mygetuntil(fd, '\n'); | |
75 } | |
76 | |
77 char *mygetcontent(int fd) | |
78 { | |
79 return mygetuntil(fd, '\0'); | |
80 } |