version 1.34, 2015/06/05 18:06:30 |
version 1.35, 2015/10/31 08:13:58 |
|
|
struct client *c = cmdq->client; |
struct client *c = cmdq->client; |
struct session *s; |
struct session *s; |
FILE *f; |
FILE *f; |
const char *path, *bufname; |
const char *path, *bufname, *cwd; |
char *pdata, *new_pdata, *cause; |
char *pdata, *new_pdata, *cause, *file, resolved[PATH_MAX]; |
size_t psize; |
size_t psize; |
int ch, error, cwd, fd; |
int ch, error; |
|
|
bufname = NULL; |
bufname = NULL; |
if (args_has(args, 'b')) |
if (args_has(args, 'b')) |
|
|
else if ((s = cmd_find_current(cmdq)) != NULL) |
else if ((s = cmd_find_current(cmdq)) != NULL) |
cwd = s->cwd; |
cwd = s->cwd; |
else |
else |
cwd = AT_FDCWD; |
cwd = "."; |
|
|
if ((fd = openat(cwd, path, O_RDONLY)) == -1 || |
xasprintf(&file, "%s/%s", cwd, path); |
(f = fdopen(fd, "rb")) == NULL) { |
if (realpath(file, resolved) == NULL) |
if (fd != -1) |
f = NULL; |
close(fd); |
else |
cmdq_error(cmdq, "%s: %s", path, strerror(errno)); |
f = fopen(resolved, "rb"); |
|
free(file); |
|
if (f == NULL) { |
|
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno)); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
|
|
pdata[psize++] = ch; |
pdata[psize++] = ch; |
} |
} |
if (ferror(f)) { |
if (ferror(f)) { |
cmdq_error(cmdq, "%s: read error", path); |
cmdq_error(cmdq, "%s: read error", resolved); |
goto error; |
goto error; |
} |
} |
if (pdata != NULL) |
if (pdata != NULL) |