// Die unless we can allocate a copy of this many bytes of string.
void *xstrndup(char *s, size_t n)
{
- void *ret = xmalloc(++n);
- xstrcpy(ret, s, n);
+ char *ret = xmalloc(++n);
+ strncpy(ret, s, n);
+ ret[--n]=0;
return ret;
}
// Slow, but small.
-char *get_rawline(int fd, long *plen)
+char *get_rawline(int fd, long *plen, char end)
{
char c, *buf = NULL;
long len = 0;
for (;;) {
if (1>read(fd, &c, 1)) break;
if (!(len & 63)) buf=xrealloc(buf, len+64);
- if ((buf[len++]=c) == '\n') break;
+ if ((buf[len++]=c) == end) break;
}
if (buf) buf[len]=0;
if (plen) *plen = len;
char *get_line(int fd)
{
long len;
- char *buf = get_rawline(fd, &len);
+ char *buf = get_rawline(fd, &len, '\n');
if (buf && buf[--len]=='\n') buf[len]=0;
off_t fdlength(int fd);
char *xreadlink(char *name);
void loopfiles(char **argv, void (*function)(int fd, char *name));
-char *get_rawline(int fd, long *plen);
+char *get_rawline(int fd, long *plen, char end);
char *get_line(int fd);
void xsendfile(int in, int out);
int copy_tempfile(int fdin, char *name, char **tempname);